Thursday, July 26, 2012

Quality Center SQL for TestPlan path,Testname,ID,TestDescription Report?

   AND TS_TEST_ID in(10,12)          /* User AL_ITEM_ID for folder level*/

Quality Center SQL for TestLab report with latest status and root path?

SELECT FOLD1.CF_ITEM_NAME AS Folder_Name, Substr(FOLD10.CF_ITEM_NAME||'\'||FOLD9.CF_ITEM_NAME||'\'||FOLD8.CF_ITEM_NAME||'\'||FOLD7.CF_ITEM_NAME||'\'||FOLD6.CF_ITEM_NAME||'\'||FOLD5.CF_ITEM_NAME ||'\'||FOLD4.CF_ITEM_NAME ||'\'||FOLD3.CF_ITEM_NAME||'\'||FOLD2.CF_ITEM_NAME,12-length(fold1.cf_item_path)/3)||'\'||FOLD1.CF_ITEM_NAME AS FolderPath,CYCLE.CY_CYCLE TestSet_Name,
TEST.TS_NAME TestScript_Name,
 Where A.CF_ITEM_ID= 5 and Instr(B.CF_ITEM_PATH, A.CF_ITEM_PATH)=1))

Wednesday, July 25, 2012

How to integrate QC with Jira

We can Integrate QC with JIRA by using Go2Group JAM Plugin, You have to install Mercury SOAP Service on one of the server and add JAMPLUGIN.JAR file to your JIRA Plugin folder.

Under administration section in JIRA you get JAM Configuration window where you can Sync Requirements / TC and Defects from QC to JIRA and JIRA to QC .

Thursday, July 12, 2012

How to Use the Main-class JAR Attribute?

If you do package up an application in a JAR, there are two ways to run it. The first way is kind of clumsy--you have to add the JAR to your CLASSPATH and you have to know the name of the class to run. Suppose, for example, that I have an application called Shorts, packages in a JAR called Shorts.jar. To run it, I'd do something like this:
java -cp Shorts.jar Shorts
A much nicer solution is to use the Main-class attribute, which is a way of embedding the name of the class to run inside the JAR. Then you can just run the application (in Java 2, at least) like this:
java -jar Shorts.jar
How do you do it? Normally, you would create the JAR something like this: jar cvf Shorts.jar *.class
The trick to adding the Main-class attribute is defining an entirely separate file with the attribute definition. For instance, create the following one-line file and save it as
Main-class: Shorts
Now, to create the JAR, use this command line:
jar cvmf Shorts.jar *.class
The m option reads information from the file you just created and adds it to the manifest of the JAR you're creating. Now you can run the JAR using java -jar Shorts.jar.

How to use Fully Load Images Using ImageIcon?

You can load GIF, JPEG, and (in SDK 1.3) PNG images using Toolkit's getImage() method:
Image i = Toolkit.getDefaultToolkit().getImage("tarsier.png");
However, Images use lazy data loading, so the data for the image won't start to be loaded until you try to display the image. You can use a MediaTracker to force the data to load, but it's a pain in the butt. An easier solution is to use one of ImageIcon's constructors, which does the dirty work of waiting for image data to load. Then you can just pull out the image and use it, confident in the knowledge that its data is fully loaded:
Image i = new javax.swing.ImageIcon("tarsier.png").getImage();

Confusion forJava SDK and JRE ?

On Windows, you may actually have two Java environments in different places on your computer. The JDK (or SDK, whatever you want to call it) is usually installed in a directory like \jdk1.2.2. The JRE, including the Java Plug-in, is typically installed in a directory like \Program Files\JavaSoft\JRE\1.2.
This becomes a problem whenever you are installing standard extension libraries or editing files like the properties file. The problem I usually have goes something like this: I install a standard extension library, like the Communications API or the Java Cryptography Extension, in \jdk1.2.2\jre\lib\ext. I work on a program that uses the extension API, and it compiles fine. When I go to run it, it complains that the classes in the standard extension library are not found.
The problem is that I'm compiling using \jdk1.2.2\bin\javac.exe, but when I run the thing, it uses \winnt\java.exe, which is actually the JRE, which would expect to find the extension API in \Program Files\JavaSoft\JRE\1.2\jre\lib\ext.
To fix this, I usually remove or rename java.exe and javaw.exe in \winnt. Then when I run my program, it uses \jdk1.2.2\bin\java.exe which is the Java SDK where I installed the standard extension API.

what is Use of Antialiasing in java?

This is a sweet one. If you're doing any graphics at all in Java 2, you can make it look a lot nicer with a single line of code. Consider the following paint() method:
public void paint(Graphics g) {
  g.drawLine(20, 20, 40, 140);
  g.fillOval(50, 110, 120, 60);
  g.setFont(new Font("Serif", Font.ITALIC, 36));
  g.drawString("Cellini", 40, 80);

I haven't even used any 2D API features here--it's just plain old AWT graphics stuff. Adding antialiasing is easy. Just add this line to the very top of the paint() method:


What is Flush Streams in java?

This might seem obvious, but it repeatedly kicks my butt. The problem usually appears with two programs on either side of a network socket having some kind of conversation. If you don't flush the output stream every time you say something, the data may not actually get written out to the socket, and the two programs will sit patiently, waiting forever for something to happen.
Typically, you can just call flush() after you write something important:
// OutputStream out;
// byte[] data

If you're writing text data, you might use a PrintWriter for output. PrintWriter has a special constructor that lets you specify if the stream should be flushed after every newline:
PrintWriter out = new PrintWriter(rawOut, true);
A PrintWriter created in this way will automatically flush itself whenever you write a line of text.

Friday, July 6, 2012

Apache Interview Questions & Answers

Q: - Can you record all the cookies sent to your server by clients in Web Server logs?

Yes, add following lines in httpd.conf file.
CustomLog logs/cookies_in.log "%{UNIQUE_ID}e %{Cookie}i" CustomLog logs/cookies2_in.log "%{UNIQUE_ID}e %{Cookie2}i"

Q: - Can we do automatically roll over the Apache logs at specific times without having to shut down and restart the server?
Use CustomLog and the rotatelogs programs
Add following line in httpd.conf file. CustomLog "| /path/to/rotatelogs /path/to/logs/access_log.%Y-%m-%d 86400" combined

Q: - What we can do to find out how people are reaching your site?

Add the following effector to your activity log format. %{Referer}

Q: - How you will put a limit on uploads on your web server?

This can be achieved by LimitRequestBody directive.

<Directory "/var/www/html/data_uploads">
LimitRequestBody 100000
Here I have put limit of 100000 Bytes

Q: - I want to stop people using my site by Proxy server. Is it possible?

<Directory proxy:>
Order Allow,Deny
Deny from all
Satisfy All

Q: - What is mod_evasive module?

mod_evasive is a third-party module that performs one simple task, and performs it very well. It detects when your site is receiving a Denial of Service (DoS) attack, and it prevents that attack from doing as much damage. mod_evasive detects when a single client is making multiple requests in a short period of time, and denies further requests from that client. The period for which the ban is in place can be very short, because it just gets renewed the next time a request is detected from that same host.

Q: - How t to enable PHP scripts on your server?
If you have mod_php installed, use AddHandler to map .php and .phtml files to the PHP handler. AddHandler application/x-httpd-php .phtml .php

Q: - Which tool you have used for Apache benchmarking?

ab (Apache bench)
ab -n 1000 -c 10

Q: - Can we cache files which are viewed frequently?

Yes we can do it by using mod_file_cache module.
CacheFile /www/htdocs/index.html

Q: - What is location of log files for Apache server ?


Q: - What are the types of virtual hosts ? ?

name-based and IP-based.
Name-based virtual host means that multiple names are running on each IP address.
IP-based virtual host means that a different IP address exists for each website served. Most configurations are named-based because it only requires one IP address.

Q: - How to restart Apache web server ?
service httpd restart

Q: - How to check the version of Apache server ?

rpm -qa |grep httpd

Q: - What is meaning of "Listen" in httpd.conf file ?

Port number on which to listen for nonsecure (http) transfers.

Q: - What is DocumentRoot ?

it is a location of files which are accessible by clients. By default, the Apache HTTP server in RedHat Enterprise Linux is configured to serve files from the /var/www/html/ directory.

Q: - On which port Apache server works ?

http - port 80
https - port 443

Q: - Tell me name of main configuration file of Apache server ?


Q: - On which version of apache you have worked ?


Q: - What do you mean by a valid ServerName directive?
The DNS system is used to associate IP addresses with domain names. The value of ServerName is returned when the server generates a URL. If you are using a certain domain name, you must make sure that it is included in your DNS system and will be available to clients visiting your site.

Q: - What is the main difference between <Location> and <Directory> sections?

Directory sections refer to file system objects; Location sections refer to elements in the address bar of the Web page

Q: - What is the difference between a restart and a graceful restart of a web server?

During a normal restart, the server is stopped and then started, causing some requests to be lost. A graceful restart allows Apache children to continue to serve their current requests until they can be replaced with children running the new configuration.

Q: - What is the use of mod_perl module?
mod_perl scripting module to allow better Perl script performance and easy integration with the Web server.

Q: - If you have added “loglevel Debug” in httpd.conf file, than what will happen?

It will give you more information in the error log in order to debug a problem.

Q: - Can you record the MAC (hardware) address of clients that access your server.


Weblogic Interview Questions & Answers

Q: - How do I increase WebLogic Server memory?

Increase the allocation of Java heap memory for WebLogic Server. (Set the minimum and the maximum to the same size.) Start WebLogic Server with the -ms32m option to increase the allocation, as in this example:

$ java ... -ms32m -mx32m ...

This allocates 32 megabytes of Java heap memory to WebLogic Server, which improves performance and allows WebLogic Server to handle more simultaneous connections. You can increase this value if necessary.

Q: - Can I configure the messaging bridge to automatically downgrade the quality of service if the Exactly-once service isn't available on either the source or target bridge destination?

Yes, just make sure to select the QOS Degradation Allowed check box on the Messaging Bridge > Configuration > General administration console page.

Q: - How do I restrict access to servlets and JSPs?

The Java Servlet API Specification v2.2 allows you to declaratively restrict access to specific Servlets and JSPs using the Web Application Deployment descriptor. Section 13.3.2 of the specification has an example deployment descriptor that uses declarative security. For more information, see Programming WebLogic HTTP Servlets.

Q: - Can I start a Managed Server if the Administration Server is unavailable?

By default, if a Managed Server is unable to connect to the specified Administration Server during startup, it can retrieve its configuration by reading a configuration file and other files directly. You cannot change the server's configuration until the Administration Server is available. A Managed Server that starts in this way is running in Maindexindex1naged Server Independence mode.

Q: - How do I increase WebLogic Server memory?

Increase the allocation of Java heap memory for WebLogic Server. (Set the minimum and the maximum to the same size.) Start WebLogic Server with the -ms32m option to increase the allocation, as in this example:

$ java ... -ms32m -mx32m ...

This allocates 32 megabytes of Java heap memory to WebLogic Server, which improves performance and allows WebLogic Server to handle more simultaneous connections. You can increase this value if necessary.

Q: - Can I start a Managed Server if the Administration Server is unavailable?

By default, if a Managed Server is unable to connect to the specified Administration Server during startup, it can retrieve its configuration by reading a configuration file and other files directly. You cannot change the server's configuration until the Administration Server is available. A Managed Server that starts in this way is running in Maindexindex1naged Server Independence mode.

Q: - How are notifications made when a server is added to a cluster?

The WebLogic Server cluster broadcasts the availability of a new server instance each time a new instance joins the cluster. Cluster-aware stubs also periodically update their list of available server instances.

Q: - What happens when a failure occurs and the stub cannot connect to a WebLogic Server instance?

When the failure occurs, the stub removes the failed server instance from its list. If there are no servers left in its list, the stub uses DNS again to find a running server and obtain a current list of running instances. Also, the stub periodically refreshes its list of available server instances in the cluster; this allows the stub to take advantage of new servers as they are added to the cluster.

Q: - Can I enable requests to a JDBC connection pool for a database connection to wait until a connection is available?

No, there's no way to allow a request to wait for a pool connection, and from the system point of view there should not be. Each requests that waits for a connection ties up one of the fixed number of execute threads in the server, which could otherwise be running another server task. Too many waiting requests could tie up all of the execute threads and freeze the server.

Q: - How do I use multibyte character sets with WebLogic jDriver for Informix?

Currently, multibyte character sets are not supported for the WebLogic jDriver for Informix driver.

Tomcat Interview Questions & Answers

Q: - What is Tomcat?

Tomcat is a Java Servlet container and web server from Jakartha project of Apache software foundation. A web server sends web pages as response to the requests sent by the browser client. In addition to the static web pages, dynamic web pages are also sent to the web browsers by the web server. Tomcat is sophisticated in this respect, as it provides both Servlet and JSP technologies. Tomcat provides a good choice as a web server for many web applications and also a free Servlet and JSP engine. Tomcat can be used standalone as well as behind other web servers such as Apache httpd.

Q: - How do I configure Tomcat to work with IIS and NTLM?

Follow the standard instructions for when the isapi_redirector.dll

Configure IIS to use "integrated windows security"

In server.xml, make sure you disable tomcat authentication:

<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" tomcatAuthentication="false" />
Q: -I stored a cookie on the browser; why can't I see it?

First, check to make sure you spelled the cookie name correctly. Next, make sure the browser has cookies enabled. Also, if you specified a root path for the cookie, make sure that the JSP or servlet reading the cookie is in that path. Remember, too, that if you don't give the cookie a specific expiration time, the cookie will vanish when the user shuts the browser down.

Q: - Why is a new object created whenever I call jsp:useBean?

You probably forgot to specify a scope for the bean. Remember, the default scope for a bean is page, and all beans with page scope disappear when the page finishes executing.

Q: - When do I use . and when do I use []?

Although you can use these operators interchangeably, it is a good idea to use an operator that indicates the kind of data being accessed. For example, if you are accessing a bean property, use the . operator. If you are accessing a map value or an array index, use the [] operator. There are plenty of times when you break this rule, especially in cases where you want a map to look like it is a bean, you want things to make sense to the next person who reads your code. You may know the types of all the variables, but the next person may not.

Q: - What is Jasper?
Jasper is a program to read the .class files in binary format. This program can generate ASCII files , which can be used along with Jasmin Assembler. Jasper is intended for generating input into a class file browser which can produce the hierarchy of inheritance and composition maps from the .class files.
Q: - Can I set Java system properties differently for each webapp?

No. If you can edit Tomcat's startup scripts, you can add "-D" options to Java. But there is no way to add such properties in web.xml or the webapp's context.

Q: - Why do I get a ClassNotFoundException when I try to use the ShoppingCart class?

The JSP engine probably can't see the class in its classpath. Tomcat uses the system classpath, so if ShoppingCart.class is visible somewhere in the system classpath, they should see it.

Q: - Explain the concepts of Tomcat Servlet Container.

- Tomcat Servlet Container is a servlet container. The servlets runs in servlet container.
- The implementation of Java Servlet and the Java Server Pages is performed by this container.
- Provides HTTP web server environment in order to run Java code.
- Reduces garbage collection
- Native Windows and Unix wrappers for platform integration

Ques 1. How do you create multiple virtual hosts?

Ans. If you want tomcat to accept requests for different hosts e.g., then you must

1. create ${catalina.home}/www/appBase , ${catalina.home}/www/deploy, and

2. add a host entry in the server.xml file
<Host appBase=\"www/appBase\" name=\"\"/>

3. Create the the following file under conf/Catalina/
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<Context path=\"/\" docBase=\"www/deploy/mywebapp.war\" reloadable=\"true\" antiJARLocking=\"true\"> </Context>
Add any parameters specific to this hosts webapp to this context file

4. put your war file in ${catalina.home}/www/deploy

When tomcat starts, it finds the host entry, then looks for any context files and will start any apps with a context

To add more sites just repeat and rinse, all webapps can share the same war file location and appbase

Ques 2. How will you load properties file?

Ans. * Use a ResourceBundle. See the Java docs for the specifics of how the ResourceBundle class works. Using this method, the properties file must go into the WEB-INF/classes directory or in a jar file contained in the WEB-INF/lib directory.

* Another way is to use the method getResourceAsStream() from the ServletContext class. This allows you update the file without having to reload the webapp as required by the first method. Here is an example code snippet, without any error trapping:

// Assuming you are in a Servlet extending HttpServlet
// This will look for a file called "/more/" relative
// to your servlet Root Context
InputStream is = getServletContext().getResourceAsStream("/more/");
Properties p = new Properties();

Ques 3. Can I set Java system properties differently for each webapp?

Ans. No. If you can edit Tomcat's startup scripts, you can add "-D" options to Java. But there is no way to add such properties in web.xml or the webapp's context.

Ques 4. How do I configure Tomcat to work with IIS and NTLM?

Ans. Follow the standard instructions for when the isapi_redirector.dll

Configure IIS to use "integrated windows security"

In server.xml, make sure you disable tomcat authentication:

<Connector port="8009" enableLookups="false" redirectPort="8443" protocol="AJP/1.3" tomcatAuthentication="false" />

Ques 5. How can I access members of a custom Realm or Principal?

Ans. When you create a custom subclass of RealmBase or GenericPrincipal and attempt to use those classes in your webapp code, you\'ll probably have problems with ClassCastException. This is because the instance returned by request.getUserPrincipal() is of a class loaded by the server\'s classloader, and you are trying to access it through you webapp\'s classloader. While the classes maybe otherwise exactly the same, different (sibling) classloaders makes them different classes.

This assumes you created a My``Principal class, and put in Tomcat\'s server/classes (or lib) directory, as well as in your webapp\'s webinf/classes (or lib) directory. Normally, you would put custom realm and principal classes in the server directory because they depend on other classes there.

Here\'s what you would like to do, but it throws ClassCastException:

MyPrincipal p = request.getUserPrincipal(); String emailAddress = p.getEmailAddress(); Here are 4 ways you might get around the classloader boundary:

1) Reflection

Principal p = request.getUserPrincipal();
String emailAddress = p.getClass().getMethod(\"getEmailAddress\", null).invoke(p, null);
2) Move classes to a common classloader

You could put your custom classes in a classloader that is common to both the server and your webapp - e.g., either the \"common\" or bootstrap classloaders. To do this, however, you would also need to move the classes that your custom classes depend on up to the common classloader, and that seems like a bad idea, because there a many of them and they a core server classes.

3) Common Interfaces

Rather than move the implementing custom classes up, you could define interfaces for your customs classes, and put the interfaces in the common directory. You\'re code would look like this:

public interface MyPrincipalInterface extends {
public String getEmailAddress();

public class MyPrincipal implements MyPrincipalInterface {
public String getEmailAddress() {
return emailAddress;

public class MyServlet implements Servlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException {
MyPrincipalInterface p = (MyPrincipalInterface)request.getUserPrincipal();
String emailAddress = p.getEmailAddress();
Notice that this method gives you pretty much the webapp code you wanted in the first place

4) Serializing / Deserializing

You might want to try serializing the response of \'request.getUserPrincipal()\' and deserialize it to an instance of [webapp]MyPrincipal.

Ques 6. How do I override the default home page loaded by Tomcat?

Ans. After successfully installing Tomcat, you usually test it by loading http://localhost:8080 . The contents of that page are compiled into the index_jsp servlet. The page even warns against modifying the index.jsp files for this reason. Luckily, it is quite easy to override that page. Inside $TOMCAT_HOME/conf/web.xml there is a section called <welcome-file-list> and it looks like this:

The default servlet attempts to load the index.* files in the order listed. You may easily override the index.jsp file by creating an index.html file at $TOMCAT_HOME/webapps/ROOT. It's somewhat common for that file to contain a new static home page or a redirect to a servlet's main page. A redirect would look like:


<meta http-equiv="refresh" content="0;URL=">


This change takes effect immediately and does not require a restart of Tomcat.

Ques 7. How do I enable Server Side Includes (SSI)?

Ans. Two things have to be done for tomcat to aknowledge SSI scripts:

1. Rename $CATALINA_BASE/server/lib/servlets-ssi.renametojar to $CATALINA_BASE/server/lib/servlets-ssi.jar.

2. Uncomment the section of web.xml found in $CATALINA_BASE/conf/web.xml that deals with SSI. it looks like this when it is uncommented:


Ques 8. How do I use DataSources with Tomcat?

Ans. When developing J2EE web applications, the task of database connection management can be daunting. Best practice involves using a J2EE DataSource to provide connection pooling, but configuring DataSources in web application servers and connecting your application to them is often a cumbersome process and poorly documented.

The usual procedure requires the application developer to set up a DataSource in the web application server, specifying the driver class, JDBC URL (connect string), username, password, and various pooling options. Then, the developer must reference the DataSource in his application's web.xml configuration file, and then access it properly in his servlet or JSP. Particularly during development, setting all of this up is tedious and error-prone.

With Tomcat 5.5, the process is vastly simplified. Tomcat allows you to configure DataSources for your J2EE web application in a context.xml file that is stored in your web application project. You don't have to mess with configuring the DataSource separately in the Tomcat server.xml, or referencing it in your application's web.xml file. Here's how:

Install the JDBC Driver Install the .jar file(s) containing the JDBC driver in Tomcat's common/lib folder. You do not need to put them in your application's WEB-INF/lib folder. When working with J2EE DataSources, the web application server manages connections for your application.

Create META-INF/context.xml In the root of your web app directory structure, create a folder named META-INF (all caps). Inside that folder, create a file named context.xml that contains a Resource like this:

<?xml version="1.0" encoding="UTF-8"?>


<Resource name="jdbc/WallyDB" auth="Container"
type="javax.sql.DataSource" username="wally" password="wally"


This example shows how to configure a DataSource for a SQL Server database named mytest located on the development machine. Simply edit the Resource name, driverClassName, username, password, and url to provide values appropriate for your JDBC driver.

Access the DataSource in Your Application From a Servlet
Here's how you might access the data in a servlet:

InitialContext ic = new InitialContext();
DataSource ds = (DataSource) ic.lookup("java:comp/env/jdbc/WallyDB");
Connection c = ds.getConnection();
Notice that, when doing the DataSource lookup, you must prefix the JNDI name of the resource with java:comp/env/

Ques 9. What is Tomcat?

Ans. 1) Tomcat is a Java Servlet container and web server from the Jakarta project of the Apache software foundation.
2) A web server responds with web pages to requests from client browsers.
3) Web servers can provide dynamic content based on the requests sent by the user.
4) Tomcat is very good at this because it provides both Java servlet and JavaServerPages (JSP) technologies.
5) Tomcat can also be used as a web server for many applications even if free servlet and JSP engine is wanted.
6) It can be used standalone or used behind traditional web servers such as Apache httpd, with the traditional server serving static pages and Tomcat serving dynamic servlet and JSP requests.

Ques 10. What is Jasper?

Ans. 1) Jasper is Tomcat's JSP Engine. Tomcat 5.x uses Jasper 2, which is an implementation of the Sun Microsystems's JavaServer Pages 2.0 specification.
2) Jasper parses JSP files to compile them into Java code as servlets (that can be handled by Catalina).
3) At runtime, Jasper is able to automatically detect JSP file changes and recompile them.

Ques 11. Explain the concepts of Tomcat Servlet Container.

Ans. 1) A servlet container is a specialized web server that supports servlet execution.
2) It combines the basic functionality of a web server with certain Java/servlet specific optimizations and extensions (such as an integrated Java runtime environment, and the ability to automatically translate specific URLs into servlet requests).
3) Individual servlets are registered with a servlet container, providing the container with information such as the functionality, the URL used for identification.
4) The servlet container then initializes the servlet as necessary and delivers requests to the servlet as they arrive.
5) Many containers can dynamically add and remove servlets from the system, allowing new servlets to quickly be deployed or removed without affecting other servlets running from the same container.
6) Servlet containers are also referred to as web containers or web engines.

Ques 12. What is WebServers? Why it is used?

Ans. Transaction with HTTP request and HTTP response is called webserver.
Using the internet listening the HTTP request and providing the HTTP response is also called webserver.It gives only html output.It will not process business logic .They can provide Http server.They are static.

Ques 13. What is different between webserver and application server?

Ans. The basic difference between a web server and an
application server is Webserver can execute only web applications i,e servlets and JSPs and has only a single container known as Web container which is used to interpret/execute web
Application server can execute Enterprise application, i,e (servlets, jsps, and EJBs) it is having two containers
1. Web Container(for interpreting/executing servlets and jsps)
2. EJB container(for executing EJBs). it can perform operations like load balancing , transaction demarcation etc.

Ques 14. Question : How to communicate between two webservers in two diff systems?

Ans. By using plug module .

Ques 15. How web server handles multiple requests for same action class(Struts) concurrently?

Ans. Struts or any webserver makes new thread for each new request. so multiple request is served with new request object.

Ques 16. Suppose when we are starting startup.bat file of Tomcat server it is not started. DOS window appears for a Second only. What we need do?

Ans. Your set up might have been not done well.
Make sure you have added tomcat root directory path in the CATALINA_HOME environment variable and added the bin path in the path variable.

Jboss Interview Questions & Answers

Q: - What is Jboss ?

JBoss is a popular open source application server based on JEE technology.
Being JEE based, the JBoss supports cross-platform java applications.
It was embedded with Apache Tomcat web server. It runs under any JVM of 1.3 or later versions. JBoss supports JNDI, Servlet/JSP (Tomcat or Jetty), EJB, JTS/JTA, JCA, JMS, Clustering (JavaGroups), Web Services (Axis), and IIOP integration (JacORB).

Q: - What is JBoss cache ?

JBoss cache is a product. Frequently accessed Java objects are cached by utilzing JBoss cache to improve the performance of e-business applications. JBoss decreases the network traffic and increases the scalability of applications by eliminating unnecessary database acces.Fully transactional features and highly configurable set of options which are to deal with concurrent data access, are provided by JBoss cache in an efficient manner possible for the applications.

Q: - What is JBoss JBPM?

JBoss JBPM is a workflow and BPM engine. Enabling the creation of business processes that coordinates between people, applications and services is the functionality of BPM engine. The combination of workflow applications development with process design is a feature of JBoss jBPM. The business process is graphically represented to facilitate a strong link between the business analyst and technical developer. This feature is provided by the JBoss jBPM process designer.

Q: - How do you monitor JBoss and detect the bottleneck of an application?

Different components of the application are to be measured. This step is to find where the degradation is, whether it is external or internal and where is the appliciation spending all the time. Using Joss JMX agents and monitoring the deployed components to the application server involves in the first step. After finding the most of the time spent by specific components or libraries or most of the resources, one can use Jprobe a specialized tool for examining the single object or the objects loaded in the memory.

Q: - Describe the use of "instanceof" keyword.

"instanceof" keyword is used to check what is the type of object.

Q: - What is an Applet?

An applet is a small server side application that can be loaded and controlled on the browser by the client application. An applet has limited access to resources in order to ensure security.

Q: - What's the difference between servlets and applets?

Servlets executes on Servers while Applets executes on browser, Unlike applets, servlets have no graphical user interface.

Q: - If you have defined a web service that needs to transfer quite a lot of information, how would you do ?

You might consider using an attachment to transfer the information.Jboss JAX-WS Web services provides Attachment support with MTOM (Message Transmission Optimization Mechanism) SOAP.

Q: - Does Seam run on other application servers besides JBoss ?

Seam runs beautifully on other application servers - just like everything else the Hibernate team does, this is not a JBoss-only thing.

Wednesday, July 4, 2012

How to configur JBoss mail service ?

how to use the Java Mail service from JBoss AS, either connecting to a local SMTP server or using Google SMTP server. The JBoss Mail subsystem configures a JavaMail session binding into JNDI.  Let's start at first with JBoss AS 7 configuration. Open your AS 7 configuration file (standalone.xml/domain.xml) and find the following line:

<subsystem xmlns="urn:jboss:domain:mail:1.0">
    <mail-session jndi-name="java:jboss/mail/Default">
          <smtp-server outbound-socket-binding-ref="mail-smtp"/>
The Session is bound to the following host and port:
<outbound-socket-binding name="mail-smtp">
   <remote-destination host="localhost" port="25"/>

Adding support for User Authentication:

As most of mail servers requires user authentication we will at first add login information by adding the <login> element:

<subsystem xmlns="urn:jboss:domain:mail:1.0">
    <mail-session jndi-name="java:jboss/mail/Default">
         <smtp-server outbound-socket-binding-ref="mail-smtp">
              <login name="fmarchioni" password="fmarchioni"/>
Now let's configure a mail server which will deliver our mails. You can try Apache James
 which is an opensource mail server, pretty light and simple to get 
started with it. Download it. Next unzip it and launch the run script 
which will start the mail server.

At startup James server just contains an administrative root account, so we will use this to add an user account. Unfortunately James does not provide (as far as I know!) a GUI interface to add users, to do that, telnet to localhost on port 4555 with the command:
telnet localhost 4555

You can log in with the root user name and password. After the login, we'll add an user. The adduser command expects a username and password combination. After adding users, you can use the listusers command to verify the entries and then exit the remote manager by typing quit. The whole session should look like this:
jboss mail service jboss mail service
Now let's create a simple Servlet which uses the Java Mail session to send a mail:

package com.sample;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.WebServlet;

import javax.mail.Session;
import javax.mail.Message;
import javax.mail.Transport;
import javax.mail.Address;
import javax.mail.internet.InternetAddress;
import javax.mail.internet.MimeMessage;
import javax.annotation.Resource;

public class SendMail extends HttpServlet
    private Session mailSession;

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

            PrintWriter out=response.getWriter();
            try    {
                MimeMessage m = new MimeMessage(mailSession);
                Address from = new InternetAddress("");
                Address[] to = new InternetAddress[] {new InternetAddress("") };

                m.setRecipients(Message.RecipientType.TO, to);
                m.setSubject("JBoss AS 7 Mail");
                m.setSentDate(new java.util.Date());
                m.setContent("Mail sent from JBoss AS 7","text/plain");
                out.println("Mail sent!");
            catch (javax.mail.MessagingException e)
                out.println("Error in Sending Mail: "+e);
As you can see this Servlet injects the Java Mail Session using the Java EE @Resource annotation:
private Session mailSession;

Fairly simple. Now test your servlet before moving to the next section.

Sending mail to a Remote GMail server

You can slighty change your configuration to use your GMail server account. The only tricky part of it is that it requires enabling the TLS/SSL transport, otherwise the GMail server will refuse to accept your connection.
In earlier JBoss AS version, you needed to set the mail.smtp.starttls.enable to true, in order to enable secure connection.
When using JBoss AS 7, you need to set the ssl property of the smtp server element. Here's a sample configuration:

<mail-session jndi-name="java:jboss/mail/Default">
    <smtp-server ssl="true" outbound-socket-binding-ref="mail-smtp">
                 <login name="" password="password"/>
. . . .
<outbound-socket-binding name="mail-smtp">
    <remote-destination host="" port="465"/>

JBoss AS 5/6 Mail configuration

In earlier releases of JBoss application server, you can configure the Java Mail service by dropping a mail-service.xml into the deploy folder.
Here's a sample configuration which uses an unauthenticated session:

  <mbean code="org.jboss.mail.MailService"
    <attribute name="JNDIName">java:/Mail</attribute>
    <attribute name="Configuration">
        <property name="" value="localhost"/>
        <property name="mail.smtp.port" value="25"/>

Adding support for user authentication:

You can follow the procedure we have exposed for AS 7 to create an user on your James server: the configuration would change to:

  <mbean code="org.jboss.mail.MailService"
       <attribute name="User">fmarchioni</attribute>
        <attribute name="Password">fmarchioni</attribute>   
        <attribute name="JNDIName">java:/Mail</attribute>
        <attribute name="Configuration">
        <property name="" value="localhost"/>
         <property name="mail.smtp.port" value="25"/>
        <property name="mail.smtp.auth" value="true"/>
        <property name="mail.smtp.user" value="fmarchioni"/>

Adding support for SSL/TSL:

Finally, if you want to enable SSL/TSL transport (as for GMail accounts) just add the following MBean configuration:

   <mbean code="org.jboss.mail.MailService"
     <attribute name="User">fmarchioni</attribute>
     <attribute name="Password">fmarchioni</attribute>
    <attribute name="JNDIName">java:/Mail</attribute>
     <attribute name="Configuration">
        <property name="" value=""/>
        <property name="mail.smtp.auth" value="true"/>
        <property name="mail.smtp.port" value="465"/>
        <property name="mail.smtp.starttls.enable" value="true"/>
        <property name="mail.smtp.socketFactory.class" value=""/>







How do I configure a Queue/Topic to work in a cluster in JBoss?

JBoss AS 5
Just set the Clustered attribute to "true" in your Queue/Topic definition. Here's a Queue example: 

<mbean code="org.jboss.jms.server.destination.QueueService"
     <depends optional-attribute-name="ServerPeer">jboss.messaging:service=ServerPeer</depends>
     <attribute name="Clustered">true</attribute>


How to secur JBoss server?

Security is a fundamental part of any enterprise application .The JBoss component framework that handles security is the JBossSX extension framework. The JBossSX security extension provides support for both the role-based declarative J2EE security model as well as integration of custom security via a security proxy layer.

The default implementation of the declarative security model is based on Java Authentication and Authorization Service (JAAS) login modules and subjects.

JAAS delivers a framework for providing authentication and authorization for all the Java applications.

Authentication is a mechanism to verify the client

Authorization is a mechanism to ensure that the client has the permissions required to access a secured resource.

The four steps to enable JAAS:

1. Identify which resources needs to be secured: a Web Application ? an EJB ?

2. Identify a suitable Security Provider. In the case of JBOSS, the security is provided by the JBOSS security manager.

3. Use a Security Implementation to secure the identified resources.

4. Make the clients of the secured resources aware of the security implementation and usage mechanisms

The LoginModule

The JBOSS application server provides pluggable security managers. The Web and the EJB Containers use the security managers to perform authentication and authorization. The JAAS-based security manager is the default security manager provided with JBOSS

The LoginModule is the module is in charge to provide the security implementation that authenticates and authorizes the clients. A typical implementation involves validating the username/password combination

JBOSS provides some Login Modules out of the box :
  • UserRolesLoginModule: This is the default login module : it reads the username, password and role information from files that are packaged with the applications.
  • DatabaseServerLoginModule: This module reads the username, password and role information from the tables in a database. The database is accessed using JDBC and the JDBC driver needs to be available in the application classpath.
  • LDAPLoginModule: This module requires the username and password. This is used to connect to LDAP as a means of verification. If successful, the roles are based on the group memberships of the user. This module is not very configurable as it doesn’t expose enough configuration options to work with all LDAPs.
  • BaseCertLoginModule: This module uses client certificates to perform authentication. It cannot provide role information. This is typically used in conjunction with one of the other LoginModules to obtain the role memberships

Securing a Web Application with UserRolesLoginModule

In this first tutorial we'll explore how to secure a Web application and an EJB application using the UserRolesLoginModule
Step 1: Add the Security Policy to your conf/login-config.xml

<application-policy name = "jboss-secure">

   <login-module code=""
 flag = "required">
     <module-option name="usersProperties"></module-option>
     <module-option name="rolesProperties"></module-option>

This tells JBoss to associate the UserRolesLoginModules for the policy named "jboss-secure".
Note: Security domains are created on demand. Putting an entry in login config.xml doesn't have any effect until an application tries to use it.

Step 2: Add security constraints to web.xml 


     <web-resource-name>Restricted to Secure role</web-resource-name>
     <description>Declarative security</description>



   <realm-name>JBoss Secured Realm</realm-name>


In this sample all resources of the web application are restricted to the "Administrator" role. Now you need only

Step 3: Add security domain to your jboss-web.xml




Last configuration file is JBoss web's deployment descriptors. This file is by default under the WEB-INF folder. To link to a specific security domain, you need to set the security-domain element to the JNDI name of the security domain to link to. Security domains are bound under java:/jaas in JNDI, so the todo domain would be java:/jaas/jboss-secure.

Step 4: Add and

Usernames and password are stored in file (you can place it anywhere JBoss classloader can reach it for example under WEB-INF/classes)

The minimalist file can be:


The associate the usernames to Security Roles.

The minimalist file can be:


Securing an EJB Application 

Securing the EJB tier is not much different: the server configuration stays the same, we need to group the EJB methods based on the roles that can access these methods.

Step 1: add <method-permission> tag in the ejb-jar.xml file. 

In the above example, the method “securedMethod” in the EJB “SampleEJB” is available only to the
client belonging to the “Secure” role. However, the method “unsecuredMethod” in the same bean is available to all the clients.

Step 2: Add security domain to your jboss.xml

During the application packaging, the administrator must choose the security domain used to protect
the application. This is exaclty the same as for the web tier except that the EJB tier uses another d.descriptor file called jboss.xml.


JBoss start up configuration - Setting Server properties using the Properties Service

Setting Server properties using the Properties Service

One cool way to add a list of System properties to JBoss is the Properties MBean Service.
In the deployment folder look for "properties-service.xml". (if you don't have it in your release you can create it at any time) :

Now add your properties either in the URLList Attribute or in the Properties Attribute:

    <mbean code=""

    <attribute name="URLList">

    <attribute name="Properties">
       property1=This is the value of my property
       property2=This is the value of my other property


As you can see the The "URLList" is a comma-separated list of URL strings from which to load properties file-formatted content while the "Properties" is a specification of multiple property name=value pairs

Now you can access your properties with standard:


Logging the startup process

JBoss uses the Log4jService (in JBoss AS 5.x and earlier) or the LoggingService (in JBoss AS 6.x and later) to configure logging.

However this service is not configured until after the bootstrap phase.

During the bootstrap the microkernel logs into log/boot.log using the configuration defined in (in 5.x and earlier) or (in 6.x and later) contained in $JBOSS_HOME/bin/run.jar.

If you want to customize the boot loggin you have basically two options:
  • Change the configuration inside run.jar 
  • Use a system property to reference an outside configuration file.

The simplest strategy is to un-jar $JBOSS_HOME/bin/run.jar, change the appropriate properties file and re-jar. (We suggest you using the Open Source archiving software 7-zip which does a good job at editing files inside of archives).

Alternatively, you can also specify the boot log configuration at the command line, instead of editing run.bat/, for example:

run.bat -Dlog4j.configuration=file:./

or for the release 6.x :

run.bat -Dlogging.configuration=file:./

How to set up JBoss start up configuration ?

you need to know about the startup process of JBoss AS, how to inject system properties in the application server and how to trace the logs of the start up activities.

How to start the JBoss AS

Starting the application server is just a matter of launching the start.cmd (Windows) or (Unix) script.

You can however customize the server startup using several parameters:

The option -b can be used to bind all server services to an IP Address.

For example: -b        # Bind the server on the IP Address -b                   # Bind the server on all network interfaces

The option -c can be used to choose which server configuration will be started. If not used the "default" will be chosen.

For example: -c all                 # Starts the "all" server configuration

The options -B can be used to add an extra library to the front bootclasspath
This is equivalento to dropping a jar library into $JBOSS_HOME/lib.

The options -L can be used to add an extra library to the loaders classpath

This is equivalento to dropping a jar library into $JBOSS_HOME/common/lib.

You can set a system property through the
-D<name>=<value> option. You can also use the -P option to load the properties from a file.

Create a file named


launch JBoss AS with:

run.cmd -P

Applications using JGroups library might benefit from the -m and -u option.

-m sets the UDP multicast port; only used by JGroups. -u sets the UDP multicast address

More about JBoss ?

What is JBoss ? JBoss Application Server (or JBoss AS) is a free software/open-source Java EE-based application server. An important distinction for this class of software is that it not only implements a server that runs on Java, but it actually implements the Java EE part of Java. Because it is Java-based, the JBoss application server operates cross-platform: usable on any operating system that supports Java. JBoss AS was developed by JBoss, now a division of Red Hat.

Important notice: This tutorial covers the releases 4-5-6 of the application server. If you want to check the latest AS 7 version, we suggest you looking at the following tutorial
JBoss application server can be freely downloaded from the Community site
The installation of JBoss is simply a matter of extracting the compressed archive into a folder.

In order to start up JBoss correctly, you have to define the environment variable JAVA_HOME to the location where you have installed Java.

After you have installed JBoss, perform a simple startup test to validate that there are no problems with your Java VM/operating system combination. To test your installation, move to the bin directory of your JBOSS_HOME/bin directory and issue the following command:

run.bat    # Windows users
$   # Linux/Unix users

JBoss AS 5-6 configuration:

Let's have a look at the application server folders for the releases 5 and 6:
what is jboss
Here's a description about the single folders:
bin This directory contains the scripts necessary to start-up and shutdown the server. This folder also contains some scripts (like twiddle) there are a few utilities for web services and server management
client This directory contains the client libraries needed to run client applications
common This directory contains the lib folder which is the new repository for the common libraries used by all application server configurations.
docs This folder contains the xml schemas used by the various xml configuration files and useful JMS, JTA and Datasource configuration examples which can be used as templates
lib This is the repository for all JBoss bootstrap libraries. Here is the new Micro-container along with earlier JMX  kernel
server This directory is the home of all server configurations. Here you can find the built-in server configurations (minimal, default, standard, web and all). Each server configuration contains the following directories in the next table
Place in the folder common/lib the libraries which are shared between all your server configuration

JBoss 5 and 6 available server configurations:

JBoss 5 and 6 ship with a set of pre-built server configurations. Most of the time you'll need to use the "default" configuration for single node applications and "all" for clustered applications. Here's anyway a description of each configuration:

The "default" configuration:

This is the basic JBoss configuration containing a default set of services. It has the most frequently used services required to deploy a JEE application. It does not include the JAXR service, the IIOP service, or any of the clustering services.

The "all" confuguration:

This configuration is a full JEE server profile with enterprise extensions such as Clustering and RMI/IIOP.
Inside each server configuration there's one more level containing the single server configuration and deployed artifacts. Here' s the next level:

The "standard" configuration:

The standard folder hosts the configuration that has been tested for Java EE 5.0 compliance. The major differences with the other server existing configurations is that call-by-value and deployment isolation are enabled by default, along with support for RMI-IIOP and jJUDDI. .

The "web" configuration

The "web" configuration is a new experimental lightweight configuration created around JBoss Web that will follow the developments of the Java EE 6 web profile. Besides being a servlet/jsp container (and this is the most relevant difference with a pure Ttomcat  Web Server), it provides support for JPA and JTA/JCA.

The "minimal" configuration

This is the has a minimal configuration—the bare minimum services required to start JBoss. It starts the logging service, a JNDI server and a URL deployment scanner to find new deployments. This is what you would use if you want to use JBoss to start your own services without any other JEE technologies. This is just the bare server. There is no web container, no EJB or JMS support. This is not a JEE compatible configuration.

Inside each server configuration there's one more level which contains the configuration folders, the deployment folder and others. Here's a table which resumes the server structure:

conf This is the configuration directory of the single server configurations.
data The data directory is a location available for use by services that want to store content in the file system
deploy The default location for deployment of JBoss services
deployers Contains all the JBoss AS services that are used to recognize and deploy different application and archive types
lib This folder used to contain the common libraries of all applications. You can use this directory for storing configuration-specific libraries
log The default directory into which the bootstrap logging service places its logs
tmp The location to which deployments are copied for local use
work Used by JBoss Web Server (the web container that comes prepackaged with JBoss AS) to store compiled JSP files and other temporary data.

JBoss AS 4 configuration

Let's have a look at the application server folders for the release 4:
what is jboss
Here's a description about the single folders:
bin This directory contains the scripts necessary to start-up and shutdown the server. This folder also contains some scripts (like twiddle) there are a few utilities for web services and server management
client The JARs that are required for clients that run outside of JBoss are located in this directory.
docs This folder contains the xml schemas used by the various xml configuration files and useful JMS, JTA and Datasource configuration examples which can be used as templates
lib This is the repository for all JBoss bootstrap libraries.
server The JBoss server configuration sets are located under the server directory. The default server configuration set is the server/default set. JBoss ships with minimal, default and all configuration sets.
Inside each server configuration there's one more level which contains the configuration folders, the deployment folder and others. Here's a table which resumes the server structure:
conf The conf directory contains the jboss-service.xml bootstrap descriptor file for a given server configuration. This defines the core services that are fixed for the lifetime of the server.
data The data directory is a location available for use by services that want to store content in the file system
deploy The default location for deployment of JBoss services
lib This is the default location for static Java libraries that should not be hot deployed. All JARs in this directory are loaded into the shared classpath at startup.
log The log directory is the directory log files are written to. This may be overridden through the conf/log4j.xml configuration file.
tmp The location to which deployments are copied for local use

How to configuration log4j to JBoss?

JBoss AS uses log4j as logging framework. This tutorial will show how to configure log4j service in your jBoss application server and also how to create a custom configuration which can be deployed along with your application.

Log4j is a flexible open source project from Apache. Using Log4j, we can replace the debugging print line statements with configurable logging statements.

The advantage in using Log4j is, if you do not want to print the debugging print lines in production application, you can easily switch them off using Log4j configuration file.

At first let's see where Log4j configuration file is located:
In the releases 4.x and 5.x it's located here:JBoss_HOME\server\default\conf\jboss-log4j.xml
Since the release 6.0.0 M1 it's located in the deploy folder: JBOSS_HOME\server\default\deploy\jboss-logging.xml

Let's have a look at a minimal configuration:
 <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">

<log4j:configuration xmlns:log4j="" debug="false">

    <appender name="FILE" class="org.jboss.logging.appender.DailyRollingFileAppender">
        <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
        <param name="File" value="${jboss.server.log.dir}/server.log"/>
        <param name="Append" value="false"/>

        <param name="DatePattern" value="'.'yyyy-MM-dd"/>

        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>

    <appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">
        <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
        <param name="Target" value="System.out"/>
        <param name="Threshold" value="INFO"/>

        <layout class="org.apache.log4j.PatternLayout">
            <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/>

    <category name="com.sample">
        <priority value="INFO"/>

        <appender-ref ref="CONSOLE"/>
        <appender-ref ref="FILE"/>


As you can see, the configuration file can be basically split in two areas:
Appender: this is the class file which directs the actual logging to a destination. It could be a simple Console appender which dumps the log messages to stdout (screen) or a file appender, which sends the log messages to a log file

Category: (formerly known as Logger) connects the classes from a package to one or more appenders.

In our example, we have defined 2 appenders: one which logs statements to the Server console (equivalent to the System.out) and another which uses a DailyRollingFileAppender to append logs to the file server.log.

We have also added a category definition (for the package com.sample) which specifies the minimum priority of messages that will be generated. The purpose of the categories is to limit the log messages produced by components to a level that makes sense. (Note In our example the message doesn't show up on the console since the threshold on the console is INFO)

The last part of the configuration is the Root logger. All loggers which are not defined through a category, inherit from the Root logger which collects messages from both the CONSOLE appender and the FILE appender.

JBoss's log4j specific configuration

Log4j configuration is handled by the MBean org.jboss.logging.Log4jService. You can configure it in the JBOSS_HOME/server/default/conf/jboss-service.xml file.
<mbean code="org.jboss.logging.Log4jService"
<attribute name="ConfigurationURL">resource:jboss-log4j.xml</attribute>

<attribute name="Log4jQuietMode">true</attribute>
<attribute name="RefreshPeriod">60</attribute>
Here, you can configure the log4j resource name (jboss-log4j.xml) and the RefreshPeriod, which states how frequently in seconds the ConfigurationURL is checked for changes.

Using log4j in your application

Once you have configured the main log4j configuration file you don't need adding any library since log4j JBoss AS already ships with all the necessary libraries.

Just define a static org.apache.log4j.Logger instance and link it to your class. For example in an HelloWorld class you would log this way:
 import org.apache.log4j.Logger

public class HelloWorld {

 static Logger logger = Logger.getLogger(HelloWorld.class);
 // ...

  public void doSomething() {
   logger.debug("This is a debug statement");

Creating a custom appender

The sample configuration can be furtherly expanded by defining new appenders or categories. For example, if you want to append your application specific logs to another file, you you can define a new File appender so that application logs don't mix the server-related File appender.
 <appender name="CUSTOM"
  <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
  <param name="File"        value="${jboss.server.home.dir}/log/custom.log"/>
  <param name="Append"      value="false"/>
  <param name="DatePattern" value="'.'yyyy-MM-dd"/>
  <layout class="org.apache.log4j.PatternLayout">
  <param name="ConversionPattern" value="%d %-5p [%c] %m%n"/>
This appender will be picked up by the Root category or by a custom defined category as in this sample:
<category name="com.sample">
  <priority value="DEBUG" />
  <appender-ref ref="CUSTOM"/>
Here, all logs emitted by the package com.sample with a priority DEBUG or higher will use the CUSTOM appender.

Using a custom log4j configuration file

The above configuration requires that you adapt the JBoss log4j file to your needs. This is not usually the best option because you should rather provide a custom configuration along with your application.

If you have already tried to pack log4j configuration along with your application, you might be disappointed that it doesn't emit any logging statement. Why ? since the log4j framework is already packed in the server lib and configuration you need to deploy your application in isolate classloader mode so that it doesn't conflict with the server logging system.

(If you want to read more about isolating classloader you might check this article: )

Isolating your application requires a simple three step process:

1) Add a jboss-web.xml (Web application) or jboss-app.xml (Enterprise App) declaring claassloader isolation
2) Add the log4j.jar along with your application ( because it will not be loaded anymore from the server lib )
3) Add the log4j.xml (or to your application

Let's see how you need to pack your Web application in order to use a custom log4j configuration (ScreenShots from Eclipse)

jboss log4j tutorial logging configuration
As you can see we have packed the configuration file (jboss-log4j.xml) in the src folder, so that it will be moved to the WEB-INF/classes folder once we distribute the application.

The file log4j.jar is added in the Web application library.

Finally we need to add in the WEB-INF folder the jboss-web.xml declaring the classloader isolation. Here's an example:
  <class-loading java2ClassLoadingCompliance="false">
The same steps can be performed on an Enterprise Archive- the main difference will be that we need rather a jboss-app.xml file to declare classloader isolation. You also need to pack log4j.jar in the "lib" folder of your .ear and your configuration file in the root of your .ear.

Here's eclipse screenshot:

jboss log4j eclipse configuration
Here's a sample jboss-app.xml file:
JBoss 5 Classloader issue

The AS5 deployers ignore the previous classloader configuration just defined. Instead, for a  scoped deployment, users will be required to create a META-INF/jboss-classloading.xml:
<classloading xmlns="urn:jboss:classloading:1.0" domain="simple-scoped"

parent-first="false" />