I'm deploying multiple WAR files in an apache tomcat server. each WAR file is containing their respective Log4j.properties file (Log4j located in WEB-INF/Log4j.properties).
If I'm deploying app1.WAR, having WEB-INF/classes/Log4j.properties to generate logs in CATALINA-HOME/logs/app1.log and another app2.WAR, having WEB-INF/classes/Log4j.properties to generate logs in CATALINA-HOME/logs/app2.log, but every logs from my both webapps are written into CATALINA-HOME/logs/app1.log.
how can I configure Log4j to create dedicated log file for each webapp loaded in apache ?
I finally found a solution.
we just need to copy Log4j and commons lib jar files in the WEB-INF/lib folder of each WAR file to get an independent instance of Log4j per webapp. Then, Log4J will get the Log4j.properties file of the webapp to create its own Logging instance.
Hope it will help.
The solution by #tiamat didn't worked for me. I have to configure a listener to initialize logger context along with providing configuration location explicitly to the context
URL configLocation = Class.forName("com.example.MyAppListener").getResource("/log4j2.xml");
LoggerContext context = (LoggerContext) LogManager.getContext(false);
context.setConfigLocation(configLocation.toURI());
if(!context.isInitialized()) {
context.initialize();
}else {
context.reconfigure();
}
Related
In my java project, I have config.xml in the
java/main/resources
folder. How do I load it so apache ignite can pick it up?
Ignition.start("config.xml");
You should put the file in java/main/resources/META-INF folder. In this case it will be picked up automatically.
I am trying to build a sample apache axis 2 project in tomcat server. In most of them, in the readme file, it is said to deploy StockQuoteService.aar.
"Type "ant generate.service" from Axis2_HOME/samples/quickstartxmlbeans
directory. Then deploy the
AXIS2_HOME/samples/quickstartxmlbeans/build/service/build/lib/StockQuoteService.aar "
How to do this deploying thing?
For a simple, ad hoc deployment, you can do this:
Download the axis2 WAR distribution. It comes as a ZIP file.
Extract the file "axis2.war" from the ZIP.
Copy axis2.war into Tomcat's webapps folder. Tomcat unpack axis2.war into a folder named axis2, which will contain a folder named services.
Copy your AAR files into the services folder. Axis2 will autodeploy them the same way Tomcat autodeploys WARs placed into its webapps folder.
Access your service as http://example.com:8080/axis2/services/servicename.
I have written a java Servlet web application, using NetBeans 7.2.1. The program have some jar file libraries that I have attached to the project. The application runs fine using NetBeans and Apache Tomcat 7.0.27.
My problem is that some of the jar file libraries that I am using in the project, need to access to some folders and files. I put these folder and files on the same directory as the whole NetBeans project is. but I got this exception:
Exception: java.lang.RuntimeException: java.io.FileNotFoundException
So I used these codes to find out where should I put them:
out.println("current directory: " + new File(".").getAbsolutePath());
out.println("current directory: " + System.getProperty("user.dir"));
out.println("current directory: " + getServletContext().getRealPath(("/")));
So I figured out that the current working directory is:
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27\bin
My question is that how can I set different directory address for each web application? I have many web applications and some of them use the same resource file names. I can't just put all of them in one directory.
Please note that I don't have access to the source code of jar files to change the. I just need a way to set the absolute path that the jar files use.
I have the same problem when I put the WAR file on the unix server. The extracted WAR file is in this location on the server:
/data02/tools/Apache/Tomcat/apache-tomcat-6.0.37/webapps/BANNEROnline
But I figure I should put the resource folders and files in this path (moosavi3 is my username!):
/home/moosavi3
How can I change the path?
The working directory is the directory from which java.[exe,bin] is started. I assume the bin directory is where the tomcat start-up script is? If the jars are all using this working directory I don't believe there is a way to make different web-apps have different working directory, they're all loaded on the same jvm (java.exe) from the same working directory.
A working directory is the directory from which a binary is started, it is not some arbitrary value that you can change.
I suspect these jar files where meant to be run as standalone applications and expected the filesystem resources they are trying to access to be in the same location as themselves.
Any filesystem resources would have to be moved to the location of your java.exe so that the correct file path resolution can result from your jars.
Standard Servlet project requires external libraries to be placed in the 'WEB-INF/lib' directory under project root. You can search google for 'servlet directory structure' and do your own research for more information. Shared libraries between web applications can be placed in the 'lib' directory under tomcat root, they should be picked up by tomcat jvm. My recommendation would be to keep the dependencies project specific, because you may need different versions in different projects in the future.
Update:
Read this page on the tomcat documentation, it will explain exactly how the project should be structured, and how to add a library that will be shared across all web applications:
http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html
Update 2:
The following Stackoverflow link explains several options how to add a static file to your web application, that will available at runtime.
https://stackoverflow.com/a/2161583/940754
Update 3:
Add a path to the classpath using the project's manifest:
http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html
I have an application which acesses a lot of property files. In jboss 5.1 we can load this from the conf directory. I would like to know if there is any such way of loading the property files in weblogic 10.3 .
I don't want to include it in an jar and place in the lib,since these property files are configurable files. The user needs to configure certain properties of the application.
Also placing the property files in the domain directory is not very good and I also would like to know if there is any other way of achieving the same .
Regards
Raj
You can place the properties files needed by your application(s) to the classpath of Weblogic and then remove the files from your WAR/JAR/EAR.
If you choose a specific folder that is not yet in your classpath, just log on the Weblogic console, and navigate through Environment -> Servers -> [Your server name] -> Configuration -> Server Start
Now it is just about adding the folder containing your properties file(s) to the classpath.
I create a war file using apache ant and
i wanted to
deploy that .war file in tomcat and make it run
can u people help me with the steps..
i m not clear abt it
stop tomcat
move your war into [tomcat install dir]/webapps
start tomcat
tomcat will deploy the war on startup
for database connectivity copy the connector in the lib folder of project which is in WEB_INF folder
like point\war\WEB-INF\lib
create war File ...in war folder of the project
like c:/user/workspace/point/war/ there (point is project name)
...by command jar cvf point.war *
now type http://localhost/portnumber/ like mine is http://localhost/9090
press on tomcat manager and give user and password
go on the option deploy war file to upload ...browse and choice the war file create in war folder of project
upload the file
click on the /point which created by manager and their your file is uploaded