Solved

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

Posted on 2013-11-15
2
610 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

10 Questions to Ask when Buying Backup Software

Choosing the right backup solution for your organization can be a daunting task. To make the selection process easier, ask solution providers these 10 key questions.

Question has a verified solution.

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

Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

623 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