Solved

log4j.xml is not loading in linux environment in executable jar

Posted on 2013-11-15
2
573 Views
Last Modified: 2013-11-22
hi,

log4j.xml is included in the executable jar .it has been prepared using pom.xml.
but log4j.xml is not loading when i run the jar.

its saying log4j.xml is not found(its looking at home/developer directory).its working fine in windows but not in linux environment.

see the structure of executable jar

sample.jar
|------META-INF/MANIFEST.MF
|-------com/company/utility/StdClient.class
|-------org/apache/log4j/allclassesrelatedtolog4j
|------org/apache/commons/
|-----org/apache/http
log4j.xml
             

MANIFEST.MF
**********

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By: XXXXX1
Build-Jdk: 1.7.0_40-ea
Main-Class: com.company.utility.StdClient
Class-Path: .
             

public class StdClient {
	
	private static final Logger LOG = Logger.getLogger(StdClient .class);
	
	
	
	public static void main(String[] args) {
DOMConfigurator.configure("log4j.xml");
LOG.info("started");
}

Open in new window


some part of the code in pom.xml which is preparing exectable jar

<build> 
   <finalName>/sample</finalName>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
              
                <executions>
                    <execution>
                        <id>package-jar-with-dependencies</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                        <configuration>
                            <appendAssemblyId>false</appendAssemblyId>
                            <descriptorRefs>
                                <descriptorRef>jar-with-dependencies</descriptorRef>
                            </descriptorRefs>
                            <archive>
                                <manifest>
                                    <mainClass>com.company.utility.StdClient</mainClass>
                                 </manifest>
                                 
                               <manifestEntries>
          						<Class-Path>.</Class-Path>
          					 </manifestEntries>
          					 
          					 
                            </archive>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>

</build>                    

Open in new window

0
Comment
Question by:chaitu chaitu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
2 Comments
 
LVL 86

Accepted Solution

by:
CEHJ earned 500 total points
ID: 39653199
DOMConfigurator.configure("log4j.xml");

Open in new window

That's a file name. You don't have a file. Try

DOMConfigurator.configure(StdClient.class.getResource("/log4j.xml"));

Open in new window

though that might be redundant

http://logging.apache.org/log4j/1.2/apidocs/org/apache/log4j/xml/DOMConfigurator.html#configure(java.net.URL)
0
 
LVL 86

Expert Comment

by:CEHJ
ID: 39668396
:)
Incidentally it's not much use having that file inside a jar - as it can't be edited, but i understand it's easier for deployment. You should consider having the app write that resource as a file to the user's home directory. Then you can use your file-loading code
0

Featured Post

Guide to Performance: Optimization & Monitoring

Nowadays, monitoring is a mixture of tools, systems, and codes—making it a very complex process. And with this complexity, comes variables for failure. Get DZone’s new Guide to Performance to learn how to proactively find these variables and solve them before a disruption occurs.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Setting up Secure Ubuntu server on VMware 1.      Insert the Ubuntu Server distribution CD or attach the ISO of the CD which is in the “Datastore”. Note that it is important to install the x64 edition on servers, not the X86 editions. 2.      Power on th…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

749 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question