救命啊,classpath问题

ghw 2001-07-06 08:19:45
为了使用jar包(log_ctrl.jar)中的类CreateLog,我在classpath中加入了如下路径:C:\Public_class\log_ctrl.jar

在普通java文件中使用没有问题,比如我在test_log_ctrl.java中使用没有问题,代码如下:
import java.io.*;

public class test_log_ctrl
{
public static void main(String[] args)
{
System.out.println("begin");

log.CrontabLog.CreateLog c_log=new log.CrontabLog.CreateLog("C:\\usr\\src\\lxf\\log\\cfg\\");
c_log.writeLog(0);
c_log.flushLog();

try{Thread.sleep(3000);}catch(Exception ee){ }

c_log.writeLog(1);
c_log.flushLog();

} //end main()
}

而在一个打成jar包中的程序中使用却提示class找不到,错误提示如下:
D:\Log_Process>java -jar Log_Process.jar 1
Exception in thread "main" java.lang.NoClassDefFoundError: log/CrontabLog/CreateLog
at Log_Process.Log_Process.main(Log_Process.java:71)


在Linux下也是这样,这是什么原因造成的,怎么解决?
...全文
169 7 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
7 条回复
切换为时间正序
请发表友善的回复…
发表回复
knight_qmh 2001-07-09
  • 打赏
  • 举报
回复
最好把用到的包放在同一驱动器,不同驱动器我还不知道怎么处理,而且你manifest.mf中Classpath不是这样写,应该写为Class-Path,如
Class-Path: \Public_class\log_ctrl.jar
ghw 2001-07-09
  • 打赏
  • 举报
回复
to knight_qmh(辉):

我的manifest.mf文件如下(在JBuilder中):
Manifest-Version: 1.0
Classpath: C:\Public_class\log_ctrl.jar
Main-Class: Log_Process.Log_Process

不行啊,错误依旧。 (不好意思,周末没上来看,没想到有人回贴子了)
ghw 2001-07-09
  • 打赏
  • 举报
回复
问题解决,给分.

非常感谢knight_qmh!
knight_qmh 2001-07-09
  • 打赏
  • 举报
回复
不要加驱动器盘符,不应有冒号,如:
不要写成这样Class-Path: C:\Public_class\log_ctrl.jar
应该写成:Class-Path: \Public_class\log_ctrl.jar
ghw 2001-07-09
  • 打赏
  • 举报
回复
to knight_qmh:
把用到的包放在同一驱动器下也不行;另外在manifest.mf中把Classpath改为Class-Path后,运行时连主类都找不到啦
BlueHand 2001-07-09
  • 打赏
  • 举报
回复
可以这样运行:
java -classpath Log_Process.jar test_log_ctrl

knight_qmh 2001-07-06
  • 打赏
  • 举报
回复
manifest.mf中加了Main-Class没有?如:
jar cvfm Log_Process.jar manifest *.class

//manifest
Manifest-Version: 1.0
Main-Class: test_log_ctrl
Class-Path: log_ctrl.jar
Created-By: 1.3.0 (Sun Microsystems Inc.)

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧