请高手帮忙看一下,我的JAVA编译环境配置有什么问题

软件和网站开发以及相关技术探讨
回复
tuliangde
帖子: 10
注册时间: 2006-09-28 15:25

请高手帮忙看一下,我的JAVA编译环境配置有什么问题

#1

帖子 tuliangde » 2006-09-28 15:31

照着快速设置指南上面安装了JDK和JRE,便了一个最简单的JAVA程序放在桌面上,编译能通过,并且生成了CLASS文件,但是用命令执行CLASS文件大时候报如下错误:
tuliang@TL-desktop:~$ javac /home/tuliang/Desktop/Hello.java
tuliang@TL-desktop:~$ java /home/tuliang/Desktop/Hello.class
Exception in thread "main" java.lang.NoClassDefFoundError: /home/tuliang/Desktop/Hello/class

怎么会NoClassDefFound呢?我编的程序没有错啊!这么简单大程序也不可能出错啊!代码如下:

public class Hello
{
public static void main(String arg[])
{
System.out.println("hello");
}
}

我的环境变量配置如下:
tuliang@TL-desktop:~$ sudo update-alternatives --config java

There are 3 alternatives which provide `java'.

Selection Alternative
-----------------------------------------------
1 /usr/bin/gij-wrapper-4.1
+ 2 /usr/lib/jvm/java-gcj/jre/bin/java
* 3 /usr/lib/jvm/java-1.5.0-sun/jre/bin/java
Press enter to keep the default[*], or type selection number: 3

为什么就是不行呢~请高手帮忙指点一下。
上次由 tuliangde 在 2006-09-29 9:24,总共编辑 1 次。
qingsmy
帖子: 5
注册时间: 2005-12-15 23:30

#2

帖子 qingsmy » 2006-09-28 23:16

tuliang@TL-desktop:~$ javac /home/tuliang/Desktop/Hello.java
tuliang@TL-desktop:~$ java /home/tuliang/Desktop/Hello.class
Exception in thread "main" java.lang.NoClassDefFoundError: /home/tuliang/Desktop/Hello/class

把Hello.class修改为Hello
tuliangde
帖子: 10
注册时间: 2006-09-28 15:25

#3

帖子 tuliangde » 2006-09-29 9:22

这个应该没什么关系吧~~我试了啊~~还是不行啊~~
tuliang@TL-desktop:~$ java /home/tuliang/Desktop/Hello
Exception in thread "main" java.lang.NoClassDefFoundError: /home/tuliang/Desktop/Hello
The God said: " let there be light." I denied. So there be darkness.
头像
oneleaf
论坛管理员
帖子: 10441
注册时间: 2005-03-27 0:06
系统: Ubuntu 12.04

#4

帖子 oneleaf » 2006-09-29 12:10

java -cp /home/tuliang/Desktop/ Hello
tuliangde
帖子: 10
注册时间: 2006-09-28 15:25

#5

帖子 tuliangde » 2006-09-29 14:15

多谢楼上的仁兄,解决了~~太感谢了~~
头像
GOVO
帖子: 427
注册时间: 2005-05-15 3:09

#6

帖子 GOVO » 2006-10-05 1:10

oneleaf 写了:java -cp /home/tuliang/Desktop/ Hello
呃。。。。-cp是什么意思?
琴声如我
77519697
帖子: 26
注册时间: 2006-07-20 15:44

解释一下

#7

帖子 77519697 » 2006-10-07 20:13

root@zrt-desktop:/home/zrt/Desktop/TestDB/dist# java -jar TestDB.jar
java.io.FileNotFoundException: database.properties (No such file or directory)
at java.io.FileInputStream.open(Native Method)
at java.io.FileInputStream.<init>(FileInputStream.java:106)
at java.io.FileInputStream.<init>(FileInputStream.java:66)
at testdb.TestDB.getConnection(Main.java:48)
at testdb.TestDB.runTest(Main.java:31)
at testdb.TestDB.main(Main.java:17)
root@zrt-desktop:/home/zrt/Desktop/TestDB/dist# java -cp TestDB.jar
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)

where options include:
-d32 use a 32-bit data model if available

-d64 use a 64-bit data model if available
-client to select the "client" VM
-server to select the "server" VM
-hotspot is a synonym for the "client" VM [deprecated]
The default VM is client.

-cp <class search path of directories and zip/jar files>
-classpath <class search path of directories and zip/jar files>
A : separated list of directories, JAR archives,
and ZIP archives to search for class files.
-D<name>=<value>
set a system property
-verbose[:class|gc|jni]
enable verbose output
-version print product version and exit
-version:<value>
require the specified version to run
-showversion print product version and continue
-jre-restrict-search | -jre-no-restrict-search
include/exclude user private JREs in the version search
-? -help print this help message
-X print help on non-standard options
-ea[:<packagename>...|:<classname>]
-enableassertions[:<packagename>...|:<classname>]
enable assertions
-da[:<packagename>...|:<classname>]
-disableassertions[:<packagename>...|:<classname>]
disable assertions
-esa | -enablesystemassertions
enable system assertions
-dsa | -disablesystemassertions
disable system assertions
-agentlib:<libname>[=<options>]
load native agent library <libname>, e.g. -agentlib:hprof
see also, -agentlib:jdwp=help and -agentlib:hprof=help
-agentpath:<pathname>[=<options>]
load native agent library by full pathname
-javaagent:<jarpath>[=<options>]
load Java programming language agent, see java.lang.instrument
头像
patrickhe
帖子: 681
注册时间: 2005-07-21 19:13
来自: Peking, China
联系:

#8

帖子 patrickhe » 2006-10-07 23:23

GOVO 写了:
oneleaf 写了:java -cp /home/tuliang/Desktop/ Hello
呃。。。。-cp是什么意思?
cp 是 classpath 的缩写

java --help 可以看到主要参数的说明
头像
kobe082002
帖子: 53
注册时间: 2005-12-01 1:21

#9

帖子 kobe082002 » 2006-10-14 16:12

也可以把当前路径加到classpath里面,这样就不用每次都指明classpath了
回复