5

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?

Yassin Hajaj
  • 21,337
  • 9
  • 51
  • 89
Oliver
  • 3,815
  • 8
  • 35
  • 63
  • 1
    Are you sure you should be delimiting the commands using \? Couldn't find any documentation on that. – Vince May 08 '18 at 22:22
  • "\" can be used in shell scripts or on the command line to ignore line breaks. You can try on you shell. – Oliver May 09 '18 at 11:32

1 Answers1

1

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.

Naman
  • 27,789
  • 26
  • 218
  • 353
  • Disclaimer - This just went too long to be a comment, hence moved in here. Let me know if this doesn't help, would delete it. – Naman May 09 '18 at 04:28
  • I tried all possible variants but the problem remains. – Oliver May 09 '18 at 11:32
  • 1
    I figured out how to invoke jaotc correctly: cd helloworld/target/classes; jaotc --output xyz.so --search-path . --class-name net.sweblog.jm18.aot.hw.HelloWorld So the correct usage of --search-path is not clear. – Oliver May 09 '18 at 11:54