質問

Here's what I've got.

I've got my 'MyJava' folder which everything is contained in.

MyJava/src/a/HelloWorld.java
MyJava/src/b/Inner.java
MyJava/bin/
MyJava/manifest.txt

HelloWorld.java:

public class HelloWorld {

    public static void main(String[] args) {

        System.out.println("Hello, World");

        Inner myInner = new Inner(); 
        myInner.myInner(); 
    }
}

Inner.java:

public class Inner {

    public void myInner() {
        System.out.println("Inner Method");
    }
}

Manifest.txt:

Main-Class: HelloWorld

First I compile the .javas to .class:

javac -d bin src/a/HelloWorld.java src/b/Inner.java

Now I put these into a .jar file jar cvfm myTwo.jar manifest.txt bin/*.class

now I try run the jar: java -jar myTwo.jar

And I get:

Exception in thread "main" java.lang.NoClassDefFoundError: HelloWorld
...
Could not find the main class: HelloWorld. Program will exit.

I know this is a pretty simple problem, what am I missing?

役に立ちましたか?

解決

If you examine the files inside your .JAR you will notice that your compiled classes are inside the bin directory (and therefore cannot be found, since your manifest references a class in the top level).
Change your jar... command like this:

jar cvfm myTwo.jar manifest.txt -C bin .

See also the "Creating a JAR File" section of the Java Tutorial.

他のヒント

One of the solutions is to add the following line to the manifest.txt

Class-Path: bin/

Then you can use 'your' command for the jar creation:

jar cvfm myTwo.jar manifest.txt bin/*.class
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top