Solved

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

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
The purpose of this article is to demonstrate how we can use conditional statements using Python.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
Viewers will learn about basic arrays, how to declare them, and how to use them. Introduction and definition: Declare an array and cover the syntax of declaring them: Initialize every index in the created array: Example/Features of a basic arr…

760 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now