if i run the command jar --create --release 9 -C com.java.mrjar.nine\build\classes .
I have the error
entry: META-INF/versions/9/com/java/mrjar/nine/Main.class, contains a new public class not found in base entries
entry: META-INF/versions/9/com/java/mrjar/nine/TimeUt.class, contains a new public class not found in base entries
invalid multi-release jar file mrjars\com.java.mrjar.jar deleted
These are the Main and TimeUt classes:
package com.java.mrjar.nine;
import java.time.Instant;
public class Main {
public static void main(String[] args) {
System.out.println("Inside jdk9 Main.main()...");
TimeUt t = new TimeUt();
System.out.println("Local Date: "+t.getLocalDate(Instant.now()));
}
}
package com.java.mrjar.nine;
import java.time.Instant;
import java.time.LocalDate;
import java.time.ZoneId;
public class TimeUt {
public TimeUt() {
System.out.println("creating jdk9 version of TimeUt");
}
public LocalDate getLocalDate(Instant now){
return LocalDate.ofInstant(now, ZoneId.systemDefault());
}
}
I can create the jar normally without addidng the --release 9 but it's a normal jar, it doesn't have versions>9 data.
The jar
command in the question is attempting to create a MR JAR without any classes in the base section, instead it is attempting to put all the classes (including the public/API classes) in a versioned section. If you are just trying to create a JAR file then drop the --release
option. If you are really trying to create a MR JAR then you should put the public/API classes in the base section, then put the 9 specific classes in the versioned section. JEP 238 has all the details on this help, the jar --help
output has some examples too.