Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java jars unable to resolve class

Tags:

java

groovy

I'm relatively new to Java development...I thought I understood how class path works, but I must be missing something.

Using Groovy, I have 2 external classes referenced by imports. When I execute the script, I get "unable to resolve class" errors. I have the jars for these in the same directory as the script. If I un-jar them, the script works, but jar'd up the script does not.

What am I missing here?

EXAMPLE

import org.apache.log4j.Logger

Logger log = Logger.getLogger("ldap_delete")
log.info("This is an informative log entry")

Putting log4j-1.2.17.jar in the same directory as the .groovy script does not work. Setting cp to . does not work. I have to do:

groovy -cp log4j-1.2.17.jar myscript.groovy

to get the class to load.

like image 976
Bean Avatar asked Dec 06 '25 08:12

Bean


1 Answers

Would need to see the script for your specific problem but in general you need to set the classpath when running a java program if it is dependent upon other jars. Here is an example:

java -cp /path/to/something.jar;/another/path/else.jar my.package.Program

like image 109
wxkevin Avatar answered Dec 08 '25 20:12

wxkevin