Skip to content

Compiler Errors and Problems

Volker Berlin edited this page May 27, 2022 · 5 revisions

Error: Abstract or native method can not be used: java/lang/Foo.bar()V

JWebAssembly can only compile pure Java code into WebAssembly code. The JDK contains a lot of native code. If you want to use this native Java code, you need a library that provides a replacement for the native methods. For the browser, you can use the jwebassembly-api library. For a WAPI target, you need a different library.

  1. if you have not added a library, the first step is to add one.
  2. if this does not help, then you can write a replacement for the method using the @Replace annotation.
  3. alternatively, you can analyze why this native method is needed. If you set the debug flag, the compiler will output in what order the methods were scanned. If there is a method in the scan order that you never need at runtime, then override it to stop the scan and compilation at that point.

If you find a good replacement for a native method that can also help others, make a pull request [jwebassembly-api] (https://github.com/i-net-software/JWebAssembly-API).

Problem: Very small output file

If the WebAssembly output file (*.wasm) is very small (about 100 bytes), then the compiler did not find an @Export annotation. The compiler compiles only the methods marked with the @Export annotation and all the referenced Java code. The cause may be:

  1. adding the Java sources failed. Are there compiled Java classes?
  2. you have not added the @Export annotation to one of your methods.
Clone this wiki locally