When I created the jar file I wrote the following java file:
package myjar;
public class MyClass {
public static void hello() {
System.out.println("hello");
}
public static void main(String[] args) {
MyClass.hello();
}
}
- I named the file MyClass.java.
- I created a class file by typing "javac src/main/java/myjar/MyClass.java"
- I generated a jar file by the command: "jar cvf myjar.jar src/main/java/myjar/MyClass.class"
Now, I took the jar file and added it to Project Structure. The name of the jar is 'myjar':
and in the IDE I wrote "import myjar.MyClass" and the word 'myjar' was marked in red.
When I use 'MyClass.hello()' in the project, I get an error:
no main manifest
Do you know what I can to to load it successfully ?
myjar
package? If not, create one, you can't import from the default package: stackoverflow.com/questions/2193226/…. – CrazyCodermyjar/MyClass.class
and no other directories above, it also should havemyjar
directory, not justMyClass.class
file in the root of the jar. – CrazyCoder