GJC-外部罐子
请不要抱怨为什么我不应该使用 GJC,我理解它的缺点。
问题是,我可以像使用常规 jar 一样链接已编译的库吗?
// this works and links to the jarfiles.jar
java -cp lib/jarfiles.jar:classes Main
但是我是否将 jar 转换为本机代码,如下所示:
gcj -shared -fPIC -Wl,-Bsymbolic jarfiles.jar -o jarfiles.so
并尝试调用 .so 文件运行它:
java -cp lib/jarfiles.so:classes Main
无法找到预期的类,这真是太糟糕了。
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)
这不应该起作用吗?我做错了什么?谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为应该是:
1-
gcj -shared -fjni jarfiles.jar -o libjarfiles-shared.so
2- 将 jarfiles.so 放在 /usr/lib 或类似的目录中(顺便说一句:必须列出目录在 LD_LIBRARY_PATH 中)
3-
gcj -fjni Somefile.java --main=Somefile -ljarfiles-shared
4-
LD_LIBRARY_PATH=/usr/lib/jni ./a.out
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