创建一个用于从 Java/Clojure 执行的 jar 文件 [英] Creating one jar file that for execution from Java/Clojure
问题描述
我想创建一个使用 java 和 clojure 实现的 jar 文件来执行.这是我采取的步骤.
I'd like to create one jar file to execute that is implemented with java and clojure. This is the step that I took.
我可以生成一个包含 clojure 核心和我的 clojure 代码的 jar 文件 (ThingOne-1.0.0-SNAPSHOT-standalone.jar),我还可以获得一个使用 clojure 代码的类文件 (HelloJava.class)通过关注这个网站 - http://walkwithoutrhythm.net/blog/2012/03/26/how-to-call-clojure-1-dot-3-functions-from-java/
I could generate a jar file (ThingOne-1.0.0-SNAPSHOT-standalone.jar) that has clojure core and my clojure code, and I also could get a class file (HelloJava.class) that uses the clojure code in the jar file by following this site - http://walkwithoutrhythm.net/blog/2012/03/26/how-to-call-clojure-1-dot-3-functions-from-java/
java代码如下:clojure代码导入为ThingOne
The java code is as follows: clojure code is imported as ThingOne
import ThingOne.*;
public class HelloJava {
public static void main(String[] args) {
System.out.println("Hello from Java!");
core.foo (12345);
}
}
我可以运行这个命令来使用代码:
I can run this command to use the code:
java -cp 'ThingOne-1.0.0-SNAPSHOT-standalone.jar:.' HelloJava
制作一个jar文件
我制作了一个具有这种结构的 jar 目录.
Making one jar file
I made one jar directory that has this structure.
├── MANIFEST.MF
└── jar
└── ThingOne-1.0.0-SNAPSHOT-standalone.jar
MANIFEST.MF 的内容是
The content of MANIFEST.MF is
Manifest-Version: 0.1
Main-Class: HelloJava
Class-Path: jar/ThingOne-1.0.0-SNAPSHOT-standalone.jar
我可以用 jar cvfm hello.jar jar/MANIFEST.MF HelloJava.class
得到一个 jar 文件.
I could get one jar file with jar cvfm hello.jar jar/MANIFEST.MF HelloJava.class
.
但是,clojure jar 文件(ThingOne-1.0.0-SNAPSHOT-standalone.jar)并未包含在此 jar 文件中,而只是引用了.
However, the clojure jar file (ThingOne-1.0.0-SNAPSHOT-standalone.jar) is not included in this jar file, but just referenced.
如何制作一个包含java类文件和clojure jar文件的jar文件?
How can I make one jar file that contains the java class file and clojure jar file?
推荐答案
如果你想制作一个包罗万象的 jar,使用如下工具:
If you want to make an all-inclusive jar, use tools like:
如果你特别想要打包 jar 文件,你需要一个自定义的类加载器,比如:
If you specifically want to package jar files, you need a custom classloader, like:
也就是说,我会考虑道文的建议,除非您有它无法满足的特定需求.
That said, I'd consider Dao Wen's suggestion, unless you have a specific need it cannot meet.
这篇关于创建一个用于从 Java/Clojure 执行的 jar 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!