在命令行上运行java而不指定classpath [英] Run java without specifying classpath on the command line

查看:471
本文介绍了在命令行上运行java而不指定classpath的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在.jar文件清单中指定了java程序的主类和类路径,但偶尔我想要运行与 Main-Class 属性。我是否可以让java启动这个类,同时仍然从清单中提取类路径,这样我就不必在命令行中用 -cp 指定整个东西了?

I've specified the main class and classpath for a java program in the .jar file manifest, but occasionally I want to run a different class from the one specified by the Main-Class attribute. Can I get java to launch this class while still pulling the classpath from the manifest, so that I don't have to specify the whole thing on the command line with -cp?

推荐答案

只需将命令行中的jar文件放入-cp;然后,Java将观察清单中的classpath属性,即使您没有使用-jar:

Just put the jar file on the command line with -cp; Java will then observe the classpath attribute within the manifest, even though you're not using -jar:

java -cp app.jar MyOtherClass

这篇关于在命令行上运行java而不指定classpath的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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