Specifying classpath for a jar

↘锁芯ラ 提交于 2019-12-01 06:49:22

If you use -jar, -cp is ignored:

-jar
Execute a program encapsulated in a JAR file. The first argument is the name of a JAR file instead of a startup class name. In order for this option to work, the manifest of the JAR file must contain a line of the form Main-Class: classname. Here, classname identifies the class having the public static void main(String[] args) method that serves as your application's starting point. See the Jar tool reference page and the Jar trail of the Java Tutorial for information about working with Jar files and Jar-file manifests. When you use this option, the JAR file is the source of all user classes, and other user class path settings are ignored.

Source: java - the Java application launcher

I would instead read a property in my Java application (that property could indicate from where resources should be loaded).

Example of how to execute the application would then be: java -Dkey=value -jar application.jar

You can't use classpath wildcards in the manifest.

Take a look at Setting the classpath for more information on how classpath works:

class path wildcards are not honored in the Class-Path jar-manifest header.

Yes, and for the shell, ~ means $HOME, but for java, it doesn't mean anything.

The problem was that I also had an index file. If you have an index file, the Class-Path will be ignored.

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