1

有没有办法构建一个特定文件夹中的任何东西的 jar 文件?

在我的文件夹中,我有一个名为“GamesCombined.java”的主类和它的 .class 文件

这是我的目录在 GamesCombined 文件夹中的样子

-> 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

我已经通过以下链接制作了 GamesCombined.java 的 jar 文件: http ://www.skylit.com/javamethods/faqs/createjar.html

但是它有一个错误:

线程“主”java.lang.NoClassDefFoundError 中的异常:games/pacman/PacmanGame(错误名称:PacmanGame)

GamesCombined.java 已导入 games.pacman.*;

有没有办法可以构建一个包含其他类的 jar 文件?我应该怎么办?:o

我是 JAR 文件的新手。:/

4

2 回答 2

5

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

于 2013-08-11T06:51:22.367 回答
0

NoClassDefFoundError表示您没有在 PacManGame.java 中指定包(或者在将其添加到 jar 之前没有重新编译它)。

package games.pacman;
public class PacManGame {
    ...

要回答原始问题,您可以使用创建 jar 文件

jar cvfm gamescombined.jar MANIFEST.MF -C GamesCombined/ . 
于 2013-08-13T12:14:22.477 回答