分页: 1 / 1

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

发表于 : 2006-09-28 15:31
tuliangde
照着快速设置指南上面安装了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

为什么就是不行呢~请高手帮忙指点一下。

发表于 : 2006-09-28 23:16
qingsmy
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

发表于 : 2006-09-29 9:22
tuliangde
这个应该没什么关系吧~~我试了啊~~还是不行啊~~
tuliang@TL-desktop:~$ java /home/tuliang/Desktop/Hello
Exception in thread "main" java.lang.NoClassDefFoundError: /home/tuliang/Desktop/Hello

发表于 : 2006-09-29 12:10
oneleaf
java -cp /home/tuliang/Desktop/ Hello

发表于 : 2006-09-29 14:15
tuliangde
多谢楼上的仁兄,解决了~~太感谢了~~

发表于 : 2006-10-05 1:10
GOVO
oneleaf 写了:java -cp /home/tuliang/Desktop/ Hello
呃。。。。-cp是什么意思?

解释一下

发表于 : 2006-10-07 20:13
77519697
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

发表于 : 2006-10-07 23:23
patrickhe
GOVO 写了:
oneleaf 写了:java -cp /home/tuliang/Desktop/ Hello
呃。。。。-cp是什么意思?
cp 是 classpath 的缩写

java --help 可以看到主要参数的说明

发表于 : 2006-10-14 16:12
kobe082002
也可以把当前路径加到classpath里面,这样就不用每次都指明classpath了