Run java without specifying classpath on the command line

半腔热情 提交于 2019-12-02 12:59:39

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/7637820/run-java-without-specifying-classpath-on-the-command-line

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!