Java使用“-cp”和“-jar”一起 [英] Java using "-cp" and "-jar" together

查看:218
本文介绍了Java使用“-cp”和“-jar”一起的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

伙计,

早些时候,我只有一个jar文件并设置了清单,以便我可以简单地运行我的程序:

Earlier, I had just one jar file and the manifest was set up such that I can simply run my program as:

 java -jar MyApp.jar

现在,我已将我的功能分成两个jar文件 - MyCore.jar和MyApp.jar。

Now, I have separated my functionality into two jar files - MyCore.jar and MyApp.jar.

以下命令有效:

java -cp "*" com.mycompany.mypackage.App

但我无法让以下工作

java -cp "*" -jar MyApp.jar

我得到一个ClassNotFoundException。

I get a ClassNotFoundException.

我更喜欢使用-jar开关。有没有办法让它发挥作用?

I prefer using "-jar" switch. Is there a way to make it work?

提前感谢您的帮助。

问候,

Peter

Regards,
Peter

推荐答案

我有一个像这样的Manifest.mf文件。

I have a Manifest.mf file like this.

Manifest-Version: 1.0
Main-Class: com.mycompany.mypackage.App
Class-Path: MyApp.jar MyCore.jar log4j.jar 

您可以将所需的任何jar文件添加到Class-Path行。然后,只要罐子在类路径中,就可以运行不带-cp的java -jar命令。

You can just add any jar files you need to the Class-Path line. Then as long as the jars are in the class path you can run the java -jar command without -cp.

这篇关于Java使用“-cp”和“-jar”一起的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆