# JARing a java project with main class in bin



## gdi1942 (Nov 2, 2006)

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)


----------



## Chicon (Jul 29, 2004)

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 (Nov 2, 2006)

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


----------



## Chicon (Jul 29, 2004)

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.


----------

