JARing a java project with main class in bin

Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

gdi1942

Thread Starter
Joined
Nov 1, 2006
Messages
215
I'm attempting to JAR my project and have it be executable. Theres a problem with the way it needs to do it. Ecclipse automatically make s abin file to hold your class files in. After compiliation it throws them in there, fine. I never put "package bin;" at the top of any of my classes and it runs without a flaw in ecclipse. However to run the main class in command line you need to be in the bin folder to launch. And to jar the entire project I figured you had to be in the root of the project in command line and specifing this command

>jar cmf Manifest.txt MyProject.jar *

with Manifest in the folder and contains
Main-Class: bin.AppDriver <Carrage Return>

but then i go to execute the jar using this command: java -jar MyProject.jar

I get the following error.
Exception in thread "main" java.lang.NoClassDefFoundError: bin/AppDriver (wrong
name: AppDriver)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
at java.net.URLClassLoader.access$100(URLClassLoader.java:56)
at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:268)
at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
 
Joined
Jul 29, 2004
Messages
6,650
Hi gdi1942,

I don't use Eclipse, so I can't tell about the way it builds JAR files.
In the Manifest file, I would remove the reference to a bin package from the Main-Class parameter as it seems that Eclipse executes your application without any package reference in your coding.
 

gdi1942

Thread Starter
Joined
Nov 1, 2006
Messages
215
the manifest now reads
Main-Class: AppDriver <Carrage Return>

Java spits out.
Exception in thread "main" java.lang.NoClassDefFoundError: AppDriver

which would make sense as the AppDriver is in the bin folder inside the jar
 
Joined
Jul 29, 2004
Messages
6,650
Assuming your application contains many classes, you'll need to make a package statement at the top of each of the sources.
Then you compile all the classes of your application and you store all the resulting .class files in the same directory which name is the name of the package.
Adapt the Main-Class parameter of the Manifest file and jar your application with the C option to point the directory where the classes are stored.
 
Status
This thread has been Locked and is not open to further replies. Please start a New Thread if you're having a similar issue. View our Welcome Guide to learn how to use this site.

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

As Seen On
As Seen On...

Welcome to Tech Support Guy!

Are you looking for the solution to your computer problem? Join our site today to ask your question. This site is completely free -- paid for by advertisers and donations.

If you're not already familiar with forums, watch our Welcome Guide to get started.

Join over 807,865 other people just like you!

Latest posts

Staff online

Top