Java jars unable to resolve class

巧了我就是萌 提交于 2020-01-23 12:01:20

问题


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

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