aspose file tools*
The moose likes IDEs, Version Control and other tools and the fly likes How to convert java to jar. jar to batch file in eclipse IDE Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Engineering » IDEs, Version Control and other tools
Bookmark "How to convert java to jar. jar to batch file in eclipse IDE" Watch "How to convert java to jar. jar to batch file in eclipse IDE" New topic
Author

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

sulthan mathina
Greenhorn

Joined: Jan 31, 2011
Posts: 6
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

Joined: May 14, 2008
Posts: 5823
    
    7

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


JBoss In Action
sulthan mathina
Greenhorn

Joined: Jan 31, 2011
Posts: 6
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

Joined: Jul 26, 2007
Posts: 10266
    
    8

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


[How to ask questions] [Donate a pint, save a life!] [Onff-turn it on!]
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16019
    
  20

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.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to convert java to jar. jar to batch file in eclipse IDE