Java jar无法解析类 [英] Java jars unable to resolve class

查看:103
本文介绍了Java jar无法解析类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Java开发还比较陌生...我以为我了解类路径的工作原理,但是我一定会缺少一些东西.

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

使用Groovy,我有2个由导入引用的外部类.执行脚本时,出现无法解析类"错误.我将这些罐子放在与脚本相同的目录中.如果我将其解压缩,脚本将起作用,但将脚本解压缩将不会.

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.

我在这里想念什么?

示例

import org.apache.log4j.Logger

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

将log4j-1.2.17.jar与.groovy脚本放在同一目录中不起作用.将cp设置为.不起作用.我必须做:

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

以加载该类.

推荐答案

需要查看针对您特定问题的脚本,但是通常,如果运行Java程序依赖于其他jar,则需要设置类路径.这是一个示例:

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

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

这篇关于Java jar无法解析类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆