?
Solved

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

Posted on 2013-11-15
2
Medium Priority
?
643 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 1500 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

Quick Start: DOCKER

Sometimes you just need a Quick Start on a topic in order to begin using it.. this is just what you need to know to get up and running with Docker!

Question has a verified solution.

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

Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

719 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