我已经设法编译java程序,但我不能执行它 [英] I have managed to compile java-program but I cannot execute it

查看:107
本文介绍了我已经设法编译java程序,但我不能执行它的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在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?

推荐答案


  1. 创建一个名为的文件HelloWorld.java ;

  2. HelloWorld.java

  3. 通过执行命令: javac HelloWorld.java 在与HelloWorld.java相同的文件夹中;

  4. 执行代码: java -cp。 HelloWorld 在与HelloWorld.java相同的文件夹中。

  1. create a file called HelloWorld.java;
  2. paste the code posted below inside HelloWorld.java:
  3. compile it by executing the command: javac HelloWorld.java in the same folder as HelloWorld.java is in;
  4. 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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆