【问题标题】:'java' not working in windows command prompt [duplicate]'java'在Windows命令提示符下不起作用[重复]
【发布时间】:2017-02-06 13:51:13
【问题描述】:

我正在尝试在 windows 命令提示符下使用“java”工具,但它不起作用。

我有一个 Test.java 文件。我用cmd中的javac工具编译它。它生成了一个文件Test.class。当我使用“java”工具运行这个 Test.class 文件时,它会给出错误“无法找到或加载主类测试”。

我尝试在 cmd 中运行“java”命令。它给出以下输出。

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
    -server       to select the "server" VM
    -hotspot      is a synonym for the "server" VM  [deprecated]
                  The default VM is server.

    -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 | -no-jre-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 with specified granularity
    -da[:<packagename>...|:<classname>]
    -disableassertions[:<packagename>...|:<classname>]
                  disable assertions with specified granularity
    -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
See http://www.oracle.com/technetwork/java/javase/documentation/index.html for m
ore details.

提供一些解决方案。

【问题讨论】:

    标签: java cmd jvm


    【解决方案1】:

    您的 Test 类中需要一个 main 方法。 main 方法是您的 Java 应用程序的入口点:https://docs.oracle.com/javase/tutorial/getStarted/application/

    【讨论】:

      猜你喜欢
      • 2019-01-26
      • 1970-01-01
      • 2010-12-13
      • 2013-07-13
      • 2010-11-20
      • 1970-01-01
      • 2011-01-23
      • 2012-11-15
      • 2018-06-20
      相关资源
      最近更新 更多