使用GCJ编译时如何将jar包与*.java文件链接在一起?
我有以下文件:
A.jar(包含 *.class 文件)
B.jar(包含*.class文件)
Program.java(包含具有主要功能的Program类,依赖于A.jar和B.jar)
如何使用GCJ构建可执行文件Program?
I have the following files:
A.jar (containing *.class files)
B.jar (containing *.class files)
Program.java (containing Program class with main function, which depends on A.jar and B.jar)
How can I build an executable file Program using GCJ?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我已经有一段时间没有接触 Java 了,所以下面的内容大部分都是我的想法。
在linux中,通常java程序是由包装脚本启动的。对于您的情况,此包装器脚本可以是
Program
,内容:如果您希望只有一个 jar 文件,那么您可以“unjar”A.jar 和 B.jar 并创建一个新的 jar,假设 Program.jar 包含 A.jar、B.jar 和您的 Program.class 中的所有类,然后您创建一个小清单文件,告诉您执行 jar 文件时要运行哪个类(在本例中是您的程序.类)。
清单文件的内容(我们称之为manifest.txt):
请注意“Main-Class: Program”行后面的空行 - 这是必需的。
因此,创建单个
Program.jar
:现在创建 shell 脚本包装器
Program
:使其可执行:
并运行它:
如果有效就鼓掌,否则扔烂番茄!
It's been a while since I played around with Java so the following are mostly off the top of my head.
In linux usually a java program is launched by a wrapper script. For your case this wrapper script can be the
Program
, the content:If you prefer to have only a single jar file then you can "unjar" A.jar and B.jar and create a new jar, say Program.jar that contain all the classes from A.jar, B.jar and your Program.class, and you create a little manifest file that tells which class is to be run when you execute the jar file (in this case it's your Program.class).
The content of the manifest file (let's call it manifest.txt):
Note the blank line after the "Main-Class: Program" line - it's needed.
So the create the single
Program.jar
:Now create the shell script wrapper
Program
:Make it executable:
and run it:
Applause if it works, throw rotten tomatoes otherwise!
这对我有用:
gcj -c A.jar -o Ao
gcj -c B.jar -o Bo
gcj --main=Program --classpath=A.jar:B.jar -o Program 敖博 Program.java
This works for me:
gcj -c A.jar -o A.o
gcj -c B.jar -o B.o
gcj --main=Program --classpath=A.jar:B.jar -o Program A.o B.o Program.java