我已经设法编译java程序,但我不能执行它 [英] I have managed to compile java-program but I cannot execute it
问题描述
我刚刚在Windows Vista上安装了JDK。之后,我为4个环境变量设置了合适的值:classpath,include,lib,path。之后,我能够编译我的HelloWorld程序(我有一个* .class文件)。但是当我尝试执行编译的程序(我键入java HelloWorldApp)它不工作。 Java写了很多东西,最后它写的是找不到主类:HelloWorldApp。任何人,请求,帮助我这个问题吗?
I have just installed JDK on Windows Vista. After that I set proper values for the 4 environment variables: classpath, include, lib, path. After that I was able to compile my HelloWorld-program (I got a *.class file). But when I try to execute the compiled program (I type java HelloWorldApp) it does not work. The Java write a lot of stuff and in the end it is written that it "could not find the main class: HelloWorldApp". Can anybody, pleas, help me with this problem?
推荐答案
- 创建一个名为
的文件HelloWorld.java
; - 将
HelloWorld.java
: - 通过执行命令:
javac HelloWorld.java
在与HelloWorld.java相同的文件夹中; - 执行代码:
java -cp。 HelloWorld
在与HelloWorld.java相同的文件夹中。
- create a file called
HelloWorld.java
; - paste the code posted below inside
HelloWorld.java
: - compile it by executing the command:
javac HelloWorld.java
in the same folder as HelloWorld.java is in; - execute the code by doing:
java -cp . HelloWorld
in the same folder as HelloWorld.java is in.
public class HelloWorld {
public static void main(String[] args) {
System.out.println("HelloWorld works!");
}
}
classpath的工作原理, a href =http://en.wikipedia.org/wiki/Classpath_%28Java%29 =nofollow noreferrer> http://en.wikipedia.org/wiki/Classpath_%28Java%29
How the classpath works, can be read here: http://en.wikipedia.org/wiki/Classpath_%28Java%29
这篇关于我已经设法编译java程序,但我不能执行它的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!