如何运行由“lein jar”制作的jar?命令?
这是 这个问题。
运行“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 相同。
这是第二个罐子的问题。正如我在之前的
当我运行时
java -cp PATH_TO_THE_CLOJURE_AND_CONTRIB.jar:$CLASSPATH -jar myproject-1.0.0-SNAPSHOT.jar'
,出现以下错误。
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)
可能出了什么问题,我想如果我使用 -cp 选项指向 jar 文件,我可以以与“myproject-1.0.0-SNAPSHOT-standalone.jar”相同的方式使用“myproject-1.0.0-SNAPSHOT.jar”。
还有什么我必须做的吗?
添加
java -cp ALLTHE_JAR_PATH myproject.core
解决了问题。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
如果您使用的是 Leiningen 1.2,您可能会遇到一个错误,即依赖项会在创建 uberjar 之前被删除(显然违背了 uberjar 的目的)。请降级到 1.1 并等待新版本(应该很快就会发布)或使用 lein 的 HEAD 进行检查(如 lein 的 README 中有关破解 Leiningen 的部分所述)。
完成此操作后,您应该能够使用 lein uberjar 生成一个独立的 jar 并说 java -jar name-of-your-standalone.jar 来启动您的应用程序。
作为替代方案,您可以使用
lein jar
创建一个常规 jar,并输入类似java -cp '$PROJECT_ROOT/lib/*:your-app.jar' your-app.main< /code> (其中
your-app.main
是应用程序的主类;另外,将$PROJECT_ROOT
替换为适当的路径,并提供your-app 的路径.jar
,当然)。lib/*
东西仅适用于 JDK 1.6;使用 1.5 时,您必须单独包含每个罐子。 请注意,使用-jar
时,-cp
和$CLASSPATH
将被忽略;仅考虑 jar 清单中指定的类路径(如果有)。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 sayjava -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 likejava -cp '$PROJECT_ROOT/lib/*:your-app.jar' your-app.main
(whereyour-app.main
is your application's main class; also, replace$PROJECT_ROOT
with the appropriate path and supply a path toyour-app.jar
, of course). Thelib/*
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.