Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

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

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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
This article will show you step-by-step instructions to build your own NTP CentOS server.  The network diagram shows the best practice to setup the NTP server farm for redundancy.  This article also serves as your NTP server documentation.
This video teaches viewers about errors in exception handling.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Suggested Courses

877 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