-
Bug
-
Resolution: Not an Issue
-
P4
-
None
-
19
-
generic
-
generic
ADDITIONAL SYSTEM INFORMATION :
Windows 10
java version "19" 2022-09-20
A DESCRIPTION OF THE PROBLEM :
Setting an entry point when creating a jar from within the directory that contains
the main class does not work.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create a directory jartest and cd into it
2. compile the Main.java program: javac Main.java
3. create the jar: jar cfe main.jar jartest.Main Main.class
4. run the jar: java -jar main.jar
ACTUAL -
Error: Could not find or load main class jartest.Main
Caused by: java.lang.ClassNotFoundException: jartest.Main
---------- BEGIN SOURCE ----------
package jartest;
public class Main {
public static void main(String[] args){
System.out.printf("Hi\n");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
You need to create the jar in the parent directory:
cd ..
jar cfe jartest\main.jar jartest.Main jartest\Main.class
cd jartest
N.B. jartest.Main is present in the jar archive, so it is rather strange to have to
cd into the parent directory to create the jar archive
FREQUENCY : always
Windows 10
java version "19" 2022-09-20
A DESCRIPTION OF THE PROBLEM :
Setting an entry point when creating a jar from within the directory that contains
the main class does not work.
STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
1. create a directory jartest and cd into it
2. compile the Main.java program: javac Main.java
3. create the jar: jar cfe main.jar jartest.Main Main.class
4. run the jar: java -jar main.jar
ACTUAL -
Error: Could not find or load main class jartest.Main
Caused by: java.lang.ClassNotFoundException: jartest.Main
---------- BEGIN SOURCE ----------
package jartest;
public class Main {
public static void main(String[] args){
System.out.printf("Hi\n");
}
}
---------- END SOURCE ----------
CUSTOMER SUBMITTED WORKAROUND :
You need to create the jar in the parent directory:
cd ..
jar cfe jartest\main.jar jartest.Main jartest\Main.class
cd jartest
N.B. jartest.Main is present in the jar archive, so it is rather strange to have to
cd into the parent directory to create the jar archive
FREQUENCY : always