如何运行从'lein jar'命令制作的jar? [英] How to run the jar made from 'lein jar' command?
问题描述
这是这个问题。
运行'lein jar'后,我得到'myproject-1.0.0-SNAPSHOT.jar',它不包含clojure-1.2.0-beta1。 jar和clojure-contrib-1.2.0-beta1.jar。
运行'lein uberjar'给我两个jar文件。第一个(以-standalone.jar结尾)是jar包含所有内容,第二个是与'lein jar'生成的jar相同。
这是jar的问题与第二个。使用第一个jar运行没有问题,正如我在前面的post-from-lein-uberjar> post 。
当我运行
java -cp PATH_TO_THE_CLOJURE_AND_CONTRIB.jar:$ CLASSPATH - jar myproject-1.0.0-SNAPSHOT.jar'
,我得到以下错误。
原因:java.lang.ClassNotFoundException:clojure.lang.IFn
at java.net.URLClassLoader $ 1.run(URLClassLoader.java:202)
在java.security.AccessController.doPrivileged(本地方法)
在java.net.URLClassLoader.findClass(URLClassLoader.java:190)
在java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher $ AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
这可能是错误的,我想我可以使用'myproject-1.0.0-SNAPSHOT.jar与'myproject-1.0.0-SNAPSHOT-standalone.jar'如果我使用-cp选项指向jar文件。
还有什么需要做的吗?
< h2> ADDED
java -cp ALLTHE_JAR_PATH myproject.core
$ b
如果您使用的是Leiningen 1.2,那么您可能会遇到一个错误依赖性将在创建uberjar之前被删除(显然会破坏uberjar的点)。请降级到1.1并等待新版本(应该很快到达)或使用lein的HEAD(如lein的README中关于Leasingen的一节中所述)。
一旦你这样做,你应该能够生成一个独立的jar与 lein uberjar
并说 java -jar name-of-your
另一种方法是使用 lein jar创建一个普通的jar
并说出像 java -cp'$ PROJECT_ROOT / lib / *:your-app.jar'your-app.main
c $ c> your-app.main 是你的应用程序的主类;同样,用适当的路径替换 $ PROJECT_ROOT
code> your-app.jar ,当然)。 lib / *
的东西只适用于JDK 1.6;与1.5,你必须包括每个瓶子分开。 请注意,使用 -jar
, -cp
和 $ CLASSPATH
被忽略;只会考虑在jar清单中指定的类路径(如果有)。
This is a follow-up for this question.
After running 'lein jar', I get 'myproject-1.0.0-SNAPSHOT.jar', which doesn't contain the clojure-1.2.0-beta1.jar and clojure-contrib-1.2.0-beta1.jar.
And running 'lein uberjar' gives me two jar files. The first one (that ends with -standalone.jar) is the jar contains everything, and the second one is the same as the jar generated with 'lein jar'.
This is the question of the jar with the second one. There's no problem running with the first jar, as I explained in the previous post.
When I run
java -cp PATH_TO_THE_CLOJURE_AND_CONTRIB.jar:$CLASSPATH -jar myproject-1.0.0-SNAPSHOT.jar'
, I get the following error.
Caused by: java.lang.ClassNotFoundException: clojure.lang.IFn at java.net.URLClassLoader$1.run(URLClassLoader.java:202) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:190) at java.lang.ClassLoader.loadClass(ClassLoader.java:307) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
What might be wrong, I thought I can use the 'myproject-1.0.0-SNAPSHOT.jar the same way with 'myproject-1.0.0-SNAPSHOT-standalone.jar' if I point to the jar files using -cp option.
Is there anything more that I had to do?
ADDED
java -cp ALLTHE_JAR_PATH myproject.core
solves the problem.
If you're using Leiningen 1.2, you are probably being hit by a bug whereby dependencies would get deleted prior to the creation of an uberjar (obviously defeating the point of uberjar). Please either downgrade to 1.1 and wait for the new release (which should be arriving shortly) or use a checkout of lein's HEAD (as described in the section on hacking Leiningen in lein's README).
Once you do that, you should be able to produce a standalone jar with lein uberjar
and say java -jar name-of-your-standalone.jar
to launch your app.
As an alternative, you can create a regular jar with lein jar
and say something like java -cp '$PROJECT_ROOT/lib/*:your-app.jar' your-app.main
(where your-app.main
is your application's main class; also, replace $PROJECT_ROOT
with the appropriate path and supply a path to your-app.jar
, of course). The lib/*
thing will only work on JDK 1.6; with 1.5 you'd have to include every jar separately. Note that when using -jar
, -cp
and $CLASSPATH
are ignored; only the classpath specified in the jar's manifest (if any) is taken into account.
这篇关于如何运行从'lein jar'命令制作的jar?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!