简体   繁体   English

运行Java而不在命令行上指定类路径

[英]Run java without specifying classpath on the command line

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. 我已经在.jar文件清单中指定了Java程序的主类和类路径,但有时我想运行与Main-Class属性指定的类不同的类。 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 ? 我可以在仍然从清单中提取类路径的同时让Java启动该类,这样就不必在命令行上使用-cp指定整个东西了吗?

Just put the jar file on the command line with -cp; 只需使用-cp将jar文件放在命令行中即可; Java will then observe the classpath attribute within the manifest, even though you're not using -jar: 然后,即使您未使用-jar,Java也会观察清单中的classpath属性:

java -cp app.jar MyOtherClass

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM