问题描述
我想将一个小的Java应用程序编译为Windows可执行文件.
I want to compile a small Java application to a Windows executable.
该应用程序非常小,只有一个主类,但是它使用Apache POI.
The application is very small, only a single main class, but it uses Apache POI.
编译时,只要将POI Jar放入类路径参数中,一切都可以正常工作.
When I compile it, everything works fine, as long as I put the POI Jar into the class path argument.
但是,在进行链接时,GCJ无法解析POI包中的类的引用.消息都是这样的:
But when it comes to linking, GCJ cannot resolve the references the classes in the POI package. The messages are all like this:
undefined reference tp 'org::apache::poi:hssf:usermodel:HSSFWorkbook::class$'
要链接我的应用程序我必须做什么?
What do I have to do in order to link my application?
推荐答案
您必须将导入的Jar分别编译到.so
库中.确保在编译库时和在编译代码时都在--classpath
中提供Jars.
You have to compile the imported Jars into .so
libraries separately. Make sure to provide the Jars in the --classpath
, both while compiling the libraries as while compiling your code.
一个示例,其中我正在编译GNU加密库:
An example, where I'm compiling the GNU crypto library:
gcj --classpath=source/:libs/gnu-crypto.jar -fjni -c libs/gnu-crypto.jar -o libs/gnu-crypto.o
gcj -shared -fPIC -o libs/libgnu-crypto.o libs/gnu-crypto.o -o libs/libgnu-crypto.so
最后,通过参考库路径的shell脚本执行可执行文件.例如:
Finally, execute your executable through a shell script referencing the library path. For example:
#!/bin/sh
export LD_LIBRARY_PATH=./libs/:$LD_LIBRARY_PATH
exec ./MyJavaApp $*
这篇关于为什么GCJ不能从导入的包中找到类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!