2

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.

Naman
  • 27,789
  • 26
  • 218
  • 353
MrSir
  • 576
  • 2
  • 11
  • 29
  • Could you share your project structure as well please. – Naman Sep 12 '17 at 10:48
  • There's only a `com.java.mrjar.nine` project with a `module-info.java` and a `com.java.mrjar.nine` package, both classes are under that package. The content of module info is `module com.java.mrjar.nine { exports com.java.mrjar.nine; }` – MrSir Sep 12 '17 at 10:55

1 Answers1

4

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.

Alan Bateman
  • 5,283
  • 1
  • 20
  • 25
  • What i originally wanted to create is a multi release jar of this class and another similar _com.java.mrjar.eight_ that just uses jdk8 and has a different `TimeUnit.getLocalDate()` method. I asked for help only on the jdk9 one because it gives me that same error and for simplicity. The original command i'm trying to do is `jar --create --file mrjars\com.jdojo.mrjar.jar -C com.java.mrjar.eight\build\classes . --release 9 -C com.java.mrjar.nine\build\classes .` If i run this i have the same error – MrSir Sep 12 '17 at 11:11
  • 3
    "contains a new public class not found in base ..." means you are augmenting the API in the versioned string with a public class that is not found in the base section. I suspect you've used a different package for the classes that are you putting in the versioned section. – Alan Bateman Sep 12 '17 at 11:14
  • They are both under the same package, I've added package and imports in the code. – MrSir Sep 12 '17 at 11:27
  • 2
    Are you sure? Your posts hint that the packages are com.java.mr.jar.eight and com.java.mrjar.nine. – Alan Bateman Sep 12 '17 at 11:42
  • Yes you're right, i thought you meant the classes inside a single project, once i gave both projects the same package name it works. – MrSir Sep 12 '17 at 11:48