wasmer-java icon indicating copy to clipboard operation
wasmer-java copied to clipboard

Instance not found; using Maven

Open Tsangares opened this issue 4 years ago • 2 comments

Describe the bug

I use maven and not gradle so I built the jar as described in the readme, then I installed the jar using maven cli:

mvn install:install-file -Dfile=wasmer-jni-amd64-linux-0.2.0.jar -DgroupId=org.wasmer -DartifactId=wasmer -Dversion=0.2.0 -Dpackaging=jar

This puts it in my local maven repo. Then I added it as a dependency:

  <dependency>
      <groupId>org.wasmer</groupId>
      <artifactId>wasmer</artifactId>
      <version>0.2.0</version>
    </dependency>

But when I run my code using the example SimpleExample.java almost exactly I recieve the error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/wasmer/Instance
    at com.clopen.Clopen.main(Clopen.java:15)
Caused by: java.lang.ClassNotFoundException: org.wasmer.Instance
    at java.net.URLClassLoader.findClass(URLClassLoader.java:382)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:352)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)

Pretty much it compiles, using the wasmer-jni-amd64-linux-0.2.0.jar as a dependency but cannot find the org.wasmer.Instance object.

Maybe a solution to this is to add the program to the maven repository. I cannot use gradle because this test example of using rust to compile to wasm to run in java will be incorporated into a much larger maven project.

Tsangares avatar Jul 29 '20 07:07 Tsangares

Thanks for the bug report.

Did you inspect the content of the JAR? What do you have inside? I get this:

$ jar tf wasmer-jni-amd64-darwin-0.2.0.jar
META-INF/
META-INF/MANIFEST.MF
org/
org/wasmer/
org/wasmer/Native.class
org/wasmer/exports/
org/wasmer/exports/Export.class
org/wasmer/exports/Function.class
org/wasmer/Instance.class
org/wasmer/Exports.class
org/wasmer/Memory.class
org/wasmer/Module.class
org/wasmer/native/
org/wasmer/native/darwin-amd64/
org/wasmer/native/darwin-amd64/libwasmer_jni.dylib

Hywan avatar Aug 17 '20 11:08 Hywan

I think I found the source of the problem os.arch isn't consistent and different jvm's report different values. My mac is reporting "x86_64" I think just checking for both values would fix it

zacharywhitley avatar Mar 10 '21 23:03 zacharywhitley