I need to execute a Java Driver class (with the main method) from the command prompt as. This is a part of the Alfresco project.
D:\java\bin>java -classpath D:\mylib\mycode.jar org.mycode.MyDriver
MyDriver.java in turn uses log4J.
In order to do so, I need to first set log4J in the open command prompt shell, so that I can run the java MyDriver later).
In order to first set log4j, I do as:
D:\java\bin>java -Dlog4j.configurationFile=file:"D:\log4j.properties" -jar D:\mylib\log4j-1.2.17.jar
However, I get an error as:
no main manifest attribute, in D:\mylib\log4j-1.2.17.jar
How should I set up the Log4J properties in the command prompt?
If I hear you right, I did the following:
As a part of troubleshooting, I thought of placing the log4j-1.2.17.jar and log4j.properties in D:\java\bin (and D:\java\bin is also the JAVA_PATH), and then run the code as:
D:\java\bin> java -classpath D:\mylib\mycode.jar org.mycode.MyDriver
I get error as:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logg
er
at org.mycode.MyDriver.<clinit>(MyDriver.java:30)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 1 more
When I unzip the log4j-1.2.17.jar, the org/apache/log4j/Logg
Er indeed exists in the log4j-1.2.17.jar
The line 30 shown above in the error log is the line where the Logger class from Log4J is used in MyDriver.java