• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How to convert java to jar. jar to batch file in eclipse IDE

 
sulthan mathina
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,
I have created java application with properties file and sql server database. It running successfully in eclipse.Then i convert it into jar by new-->export-->...........etc. Created. Now i want to create batch file for this jar. I created run.bat but i did not get my output.
I run jar in cmd by java -jar sss.jar
It throwing exception
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/log4j/Logg
er
at smapp.Main.<clinit>(Main.java:15)
Caused by: java.lang.ClassNotFoundException: org.apache.log4j.Logger
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
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
Could not find the main class: smapp.Main. Program will exit.

 
Peter Johnson
author
Bartender
Posts: 5856
7
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like you are using Log4J in you app - did you include that JAR file in your classpath? (It would help if you posted the contents of you bat file).

Which class did you identify as the "main" class? The JVM thinks that it is smapp.Main - do you have such a class? (It would help if you posted the manifest from your JAR file.)

Also, post the contents of your JAR by running:

jar -tf sss.jar
 
sulthan mathina
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi ,

C:\>jar -tf ss.jar
META-INF/MANIFEST.MF
smapp/Main.class
smapp/data.class
log4j.properties

bat file

set $PATH=$PATH;"C:\Program Files\Java\jdk1.6.0_20\bin"

java -jar ss.jar

echo Completed Successfully....
 
Maneesh Godbole
Saloon Keeper
Posts: 11196
15
Android Eclipse IDE Google Web Toolkit Java Mac Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like Peter mentioned, you need to specify your main class in the manifest and ensure the log4j jar is on the classpath
Recommended reading
http://download.oracle.com/javase/tutorial/deployment/jar/appman.html
http://download.oracle.com/javase/tutorial/deployment/jar/downman.html
 
Tim Holloway
Saloon Keeper
Posts: 18304
56
Android Eclipse IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stuff like this is hard to do using just Eclipse, because Eclipse is a development environment, not a runtime environment and Java's classpath rules require that you do some things that are complicated enough that a "one-size-fits-all" Eclipse build doesn't handle.

You can do one of 2 things:

1. You can create a batch file with an explicit classpath reference for the additional jar(s) such as log4j. Needless to say, the deployment of something like this gets complicated, since now you have a Java app jar, a log4j library jar and an MS-DOS batch file to install on the user's system instead of just a simple file copy.

2. You can build an executable JAR. This solution provides a single file, which can be executed using the "java -jar ...." command line. However, in order to resolve the log4j classes, you'll have to do something more. Either a) explode the log4j car and merge its classes into your application jar, or b) add a custom classloader to your app so that you can include the unexploded log4j.jar embedded in your executable jar.

The reason for the extra complexity is that jar-in-jar organization isn't supported by the default behaviour of the JVM, so you have to include your own classloader to locate and load classes from the embedded jar(s). However, this is more work than most of us want to go through. Fortunately, if you use Maven, you can invoke the "build executable jar" goal and it will do all that for you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic