java程序运行时出现问题:Could not find the main class: test_jena. Program will exit.
2013-02-02 19:48
1051 查看
一般出现这个问题都是因为运行程序时粗心把编译生成的文件名写错了,但这次不是。
java程序能编译通过,但运行时出现问题:
java程序没有任何问题,jre和jdk安装没有问题!
回想自己直接使用export了一个新的CLASSPATH:export CLASSPATH=/home/liaomeng/apache-jena-2.7.4/lib。
试着删除这个CLASSPATH变量,发现程序又能正常编译运行了!!!
所以猜想出现这个问题的原因就在于:
这个CLASSPATH覆盖了原来系统默认的CLASSPATH变量值(当初装java时用的是yum安装,java使用的应该是默认的CLASSPATH路径)
再仔细检查后发现,一般添加CLASSPATH都以“.:”开头,是不是应该加上呢,试一下,果然如此!!!
so,把命令改为export CLASSPATH=.:/home/liaomeng/apache-jena-2.7.4/lib即可解决问题。
总结:
用export添加CLASSPATH时一定要在前面加“.:”,多个jar包之间用“;”分隔。
经过试验发现,也可以通过export命令添加PATH变量,但是必须是在已有的PATH变量后面增加,so必须:
export PATH=$PATH:/home/lm/apache-jena-2.7.4/bin,
此时新添加的PATH变量不会把系统之前的PATH变量替换掉。
如果不是用export添加环境变量,修改/etc/profile或者.bashrc文件,此时也需要认真填写每个变量和路径,小心驶得万年船。。。
java程序能编译通过,但运行时出现问题:
Exception in thread "main" java.lang.NoClassDefFoundError: test_jena Caused by: java.lang.ClassNotFoundException: test_jena at java.net.URLClassLoader$1.run(URLClassLoader.java:217) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(URLClassLoader.java:205) at java.lang.ClassLoader.loadClass(ClassLoader.java:321) at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:294) at java.lang.ClassLoader.loadClass(ClassLoader.java:266) at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:334) Could not find the main class: test_jena. Program will exit.
java程序没有任何问题,jre和jdk安装没有问题!
回想自己直接使用export了一个新的CLASSPATH:export CLASSPATH=/home/liaomeng/apache-jena-2.7.4/lib。
试着删除这个CLASSPATH变量,发现程序又能正常编译运行了!!!
所以猜想出现这个问题的原因就在于:
这个CLASSPATH覆盖了原来系统默认的CLASSPATH变量值(当初装java时用的是yum安装,java使用的应该是默认的CLASSPATH路径)
再仔细检查后发现,一般添加CLASSPATH都以“.:”开头,是不是应该加上呢,试一下,果然如此!!!
so,把命令改为export CLASSPATH=.:/home/liaomeng/apache-jena-2.7.4/lib即可解决问题。
总结:
用export添加CLASSPATH时一定要在前面加“.:”,多个jar包之间用“;”分隔。
经过试验发现,也可以通过export命令添加PATH变量,但是必须是在已有的PATH变量后面增加,so必须:
export PATH=$PATH:/home/lm/apache-jena-2.7.4/bin,
此时新添加的PATH变量不会把系统之前的PATH变量替换掉。
如果不是用export添加环境变量,修改/etc/profile或者.bashrc文件,此时也需要认真填写每个变量和路径,小心驶得万年船。。。
相关文章推荐
- 解决运行java application时提示Could not find the main class.Program will exit.问题
- 安装java的时候出现Could not find the main class.program will exit
- <综合>java virtual machine launcher 提示 could not find the main class,program will exit 问题
- java could not find the main class:Welcome. Program will exit 问题
- Myeclips运行的的时候出现Could not find the main class:Main. Program will exit.
- java virtual machine launcher Could not find the main class. Program will exit
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- Eclipse 运行项目抛UnsupportedClassVersionError弹出yunCould not find the main class.program will exit
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- JAVAEclipse:could not find the main class,program will exit!
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- Java执行main方法,异常为:could not find the main class.program will exit
- Eclipse运行异常:Could not find the main class. Program will exit.
- java调用本地方法的时候报错 could not find the main class:xx.program will exit
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法
- Java中Could not find the main class.program will exit和java.lang.UnsupportedClassVersionError 的解决方法 .
- Java执行main方法,异常为:could not find the main class.program will exit
- Eclipse下编译出现错误:can not find the main class,Program will exit 问题解决
- jdk版本不同造成问题解决could not find the main class, Program will exit(2)