GJC - an external jar
-
12-10-2019 - |
Question
Please don't go into a rant why I shouldn't be using GJC, I understand the con's of it.
The question is, can I link a compiled library just as if using a regular jar?
// this works and links to the jarfiles.jar
java -cp lib/jarfiles.jar:classes Main
But is I turn the jar to native code like this:
gcj -shared -fPIC -Wl,-Bsymbolic jarfiles.jar -o jarfiles.so
And try to run it calling the .so file:
java -cp lib/jarfiles.so:classes Main
It blows not being able to find the expected classes.
Exception in thread "main" java.lang.NoClassDefFoundError: com/netxpect/FirstFromJar
at Main.<clinit>(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.netxpect.FirstFromJar
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
Shouldn't this work? What am I doing wrong? Thank you.
Solution
I think it should be:
1- gcj -shared -fjni jarfiles.jar -o libjarfiles-shared.so
2- put jarfiles.so in /usr/lib or similar (btw: directory must be listed in LD_LIBRARY_PATH)
3- gcj -fjni Somefile.java --main=Somefile -ljarfiles-shared
4- LD_LIBRARY_PATH=/usr/lib/jni ./a.out
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow