问题
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.
回答1:
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
来源:https://stackoverflow.com/questions/19814355/java-jars-unable-to-resolve-class