Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compile single class with jaotc of Java 10

I would like compile a Java 10 class file with jaotc. While I am able to build a shared lib of an Java 10 module I am not able figure out how to compile a single class. The FQCN of my class is net.sweblog.jm18.aot.hw.HelloWorld and its full path is target/classes/net/sweblog/jm18/aot/hw/HelloWorld.class.

So tried to invoke jaotc as follows:

$ jaotc --output output/helloworld.so \
    --search-path helloworld/target/classes/ \
    --class-name net.sweblog.jm18.aot.hw.HelloWorld

Error: Failed to find class file: net.sweblog.jm18.aot.hw.HelloWorld
java.lang.NullPointerException
    at jdk.aot/jdk.tools.jaotc.Main.run(Main.java:135)
    at jdk.aot/jdk.tools.jaotc.Main.run(Main.java:101)
    at jdk.aot/jdk.tools.jaotc.Main.main(Main.java:80)

Does anyone know how to invoke jaotc correctly to compile my class file?

like image 307
Oliver Avatar asked Nov 07 '22 07:11

Oliver


1 Answers

The NullPointerException could be thrown when there are no classes found by the tool to compile in the specified searchPath or the files(if specified in the --jar arg).

If you look at the code at Line#135 does a

printer.printInfo(classesToCompile.size() + " classes found");

where NPE could be thrown if classesToCompile is null which is the case only when the lookup for classes fails in the specified path

try {
    foundClasses = lookup.search(this.main.options.files, this.main.options.searchPath);
} catch (InternalError var7) {
    this.main.printer.reportError(var7);
    return null;
}

Hence, I would recommend verifying the search path that you've specified. I also doubt specifying the class name net.sweblog.jm18.aot.hw.HelloWorld to a compiler, if I am not wrong to draw an analogy with javac here, it would have required a complete path for either the compiled or source class.

like image 128
Naman Avatar answered Nov 14 '22 23:11

Naman