Using wildcards in java classpath

I run a shell script that should execute the main method:

 java -classpath /path/to/app/conf/lib/nameJar* com.example.ClassTest 

At this point, I get this exception:

 Exception in thread "main" java.lang.NoClassDefFoundError: org/springframework/context/ApplicationContext Caused by: java.lang.ClassNotFoundException: org.springframework.context.ApplicationContext at java.net.URLClassLoader$1.run(URLClassLoader.java:200) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:188) at java.lang.ClassLoader.loadClass(ClassLoader.java:303) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301) at java.lang.ClassLoader.loadClass(ClassLoader.java:248) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:316) 

This is because spring banks are in a different folder. So, I changed the script:

 java -classpath /path/to/app/conf/lib/nameJar*:/path/to/app/lib/spring* com.example.ClassTest 

But with this script, com.example.ClassTest could not be found. Any ideas on this issue?

Thanks in advance

+6
source share
2 answers

The extension of the java classpath classpath template is unusual.

From docs :

Class Path Template Overview

Class path entries can contain a database wildcard character *, which is considered equivalent by specifying a list of all files in a directory with the extension .jar or .JAR. For example, writing the path to the file foo / * indicates all the JARs in a directory named foo. The pathpath element, consisting of simply * extends the list of all jar files in the current directory.

So you need to specify:

 java -classpath /path/to/app/conf/lib/*:/path/to/app/lib/* 

If you need only specific banks, you will need to add them separately. The classpath string does not support common wildcards such as nameJar* , *.jar , spring* , etc.

Read Configuring multiple jars on the java class path for more information.

+10
source

It seems the JVM cannot find the WA60 associated with JARS. Put all the necessary JARS in one place (say c: \ libs) and use "java.ext.dirs" when running the command "java"

like:

 java -Djava.ext.dirs=c:/libs com.example.ClassTest 
0
source

Source: https://habr.com/ru/post/917166/


All Articles