简体   繁体   English

在使用GCJ进行编译期间,如何将jar包与* .java文件链接在一起?

[英]How do I link jar packages together with *.java files during compilation using GCJ?

I have the following files: 我有以下文件:

A.jar (containing *.class files) A.jar(包含* .class文件)
B.jar (containing *.class files) B.jar(包含* .class文件)
Program.java (containing Program class with main function, which depends on A.jar and B.jar) Program.java(包含具有主要功能的Program类,它取决于A.jar和B.jar)

How can I build an executable file Program using GCJ? 如何使用GCJ构建可执行文件程序

It's been a while since I played around with Java so the following are mostly off the top of my head. 自从我玩Java以来​​已经有一段时间了,因此以下内容几乎不在我的脑海中。

In linux usually a java program is launched by a wrapper script. 在Linux中,通常由包装脚本启动Java程序。 For your case this wrapper script can be the Program , the content: 对于您的情况,此包装脚本可以是Program ,其内容为:

#!/bin/sh
java -cp A.jar:B.jar:/path/to/dir/where/Program.class/is/in Program

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). 如果您只希望有一个jar文件,则可以“解压缩” A.jar和B.jar并创建一个新的jar,例如说Program.jar,其中包含A.jar,B.jar和您的Program中的所有类。类,然后创建一个小清单文件,该文件指示执行jar文件时要运行哪个类(在本例中为Program.class)。

The content of the manifest file (let's call it manifest.txt): 清单文件的内容(我们将其称为manifest.txt):

-----8<------
Main-Class: Program

----->8------

Note the blank line after the "Main-Class: Program" line - it's needed. 请注意“ Main-Class:Program”行之后的空白行-这是必需的。

So the create the single Program.jar : 因此,创建单个Program.jar

gcj --classpath A.jar:B.jar Program.java
mkdir tmp
cd tmp
jar xf ../A.jar
jar xf ../B.jar
cp ../Program.class .
jar cmf ../manifest.txt ../Program.jar .
cd ..

Now create the shell script wrapper Program : 现在创建外壳脚本包装Program

#!/bin/sh
java -jar /path/to/Program.jar

Make it executable: 使它可执行:

chmod +x Program

and run it: 并运行它:

./Program

Applause if it works, throw rotten tomatoes otherwise! 如果鼓掌鼓掌,否则扔烂番茄!

This works for me: 这对我有用:

gcj -c A.jar -o Ao gcj -c A.jar -o Ao
gcj -c B.jar -o Bo gcj -c B.jar -o Bo
gcj --main=Program --classpath=A.jar:B.jar -o Program Ao Bo Program.java gcj --main = Program --classpath = A.jar:B.jar -o程序Ao Bo Program.java

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM