Reputation: 485
Is there a way to build a jar file that is anything inside a specific folder?
Inside my folder I have my main class named "GamesCombined.java" with it's .class files
Here's what my directory looks like inside GamesCombined folder
-> GamesCombined.java
-> GamesCombined.class //classes*
-> games (folder)
|
|----> pacman (folder)
| |
| |----> PacmanGame.java
| |----> PacmanGame.class //classes*
|
|----> racinggame(folder)
|
|----> RacingGame.java
|----> RacingGame.class //classes*
-> images (folder)
|
|----> pacman (folder)
| |
| |----> //jpg's and png's
|
|----> racinggame (folder)
|
|----> //jpg's and png's
I already made a jar file of the GamesCombined.java by following this link: http://www.skylit.com/javamethods/faqs/createjar.html
But then it has an error:
Exception in thread "main" java.lang.NoClassDefFoundError: games/pacman/PacmanGame (wrong name: PacmanGame)
GamesCombined.java has import games.pacman.*;
Is there a way where I could just build a jar file including the other classes? What should I do? :o
I'm new when it comes on JAR files. :/
Upvotes: 1
Views: 4160
Reputation: 11
The NoClassDefFoundError
indicates that you have not specified the package inside PacManGame.java (or you didn't recompile it before adding it to the jar).
package games.pacman;
public class PacManGame {
...
To answer the original question, you can create the jar file using
jar cvfm gamescombined.jar MANIFEST.MF -C GamesCombined/ .
Upvotes: 0
Reputation: 1487
The easiest way is to use the included Jar Builder of your IDE. Java brings a tool which also can create JarFiles, take a look : Creating a JAR File
(your jdk/bin)jar cf jar-file input-file(s)
In both ways you have to check your classpath, written in your Manifest
EDIT:
JCreator Pro is quite easy:
click: Configure>Options>Tools>New>Create JAR File
this creates an user tool to create a JAR file, this does not yet include the manifest, you will have to manually add the manifest.
OR you can configure the command line switches to incorporate the manifest, try this for example: cvmf $[PrjDir]\MANIFEST.MF $[PrjName].jar .
this should include the manifest 'MANIFEST.MF' in your project directory as a manifest. You will have to create that yourself though.
NOTE: this has NOT been tested
Upvotes: 5