安裝了最新的
Java SE Development Kit (JDK)
JDK 6 Update 16
http://java.sun.com/javase/downloads/index.jsp
安裝過程中全部預設值
HelloWorld.java
public class HelloWorld {
public static void main(String[] args)
System.out.println("Hello! World!");
}
}把它存在F:\
然後
cd C:\Program Files\Java\jdk1.6.0_16\bin>
javac F:\HelloWorld.java
成功,產生 F:\HelloWorld.classC:\Program Files\Java\jdk1.6.0_16\bin>java F:\HelloWorld錯誤
Exception in thread "main" java.lang.NoClassDefFoundError: F:\HelloWorld
Caused by: java.lang.ClassNotFoundException: F:\HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: F:\HelloWorld. Program will exit.把F:\HelloWorld.class 放到 C:\Program Files\Java\jdk1.6.0_16\bin>
C:\Program Files\Java\jdk1.6.0_16\bin>java HelloWorld
這樣子就可功經過爬文後找到CLASSPATH 是CLASS 的路徑...但是HelloWorld 並沒有用到什麼其他的CLASS 呀..最多只是內置的的一些CLASS....
試了這個也不行
C:\Program Files\Java\jdk1.6.0_16\bin>java -cp . F:\HelloWorld 也不行..
謝謝
Java SE Development Kit (JDK)
JDK 6 Update 16
http://java.sun.com/javase/downloads/index.jsp
安裝過程中全部預設值
HelloWorld.java
public class HelloWorld {
public static void main(String[] args)
System.out.println("Hello! World!");
}
}把它存在F:\
然後
cd C:\Program Files\Java\jdk1.6.0_16\bin>
javac F:\HelloWorld.java
成功,產生 F:\HelloWorld.classC:\Program Files\Java\jdk1.6.0_16\bin>java F:\HelloWorld錯誤
Exception in thread "main" java.lang.NoClassDefFoundError: F:\HelloWorld
Caused by: java.lang.ClassNotFoundException: F:\HelloWorld
at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
Could not find the main class: F:\HelloWorld. Program will exit.把F:\HelloWorld.class 放到 C:\Program Files\Java\jdk1.6.0_16\bin>
C:\Program Files\Java\jdk1.6.0_16\bin>java HelloWorld
這樣子就可功經過爬文後找到CLASSPATH 是CLASS 的路徑...但是HelloWorld 並沒有用到什麼其他的CLASS 呀..最多只是內置的的一些CLASS....
試了這個也不行
C:\Program Files\Java\jdk1.6.0_16\bin>java -cp . F:\HelloWorld 也不行..
謝謝
不行呀...語法不對...-cp 要跟參數
以下顯示錯誤C:\Program Files\Java\jdk1.6.0_16\bin>java -cp F:\HelloWorld
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)where options include:
-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 -splash:<imagepath>
show splash screen with specified imageC:\Program Files\Java\jdk1.6.0_16\bin>java -cp F:\HelloWorld
Usage: java [-options] class [args...]
(to execute a class)
or java [-options] -jar jarfile [args...]
(to execute a jar file)where options include:
-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 -splash:<imagepath>
show splash screen with specified image
public static void main(String[] args){
System.out.println("Hello! World!");
}
}main方法少了个大括号
classpath设置问题
在配置环境变量时:少了一个“.”
安裝了最新的
Java SE Development Kit (JDK) 现在都有1.7了
java空格-cp空格F:\空格HelloWorld