简体   繁体   English

如何在 windows 的命令行中运行此 java class?

[英]How to run this java class in command line in windows?

package com.test01;

public class test01 {
    public static void main(String[] args)
    {
        System.out.println("hi");
    }
}

I think the java application launcher is very stupid.我认为 java 应用程序启动器非常愚蠢。 I have point out the test01.class position:我已经指出了 test01.class position:
java -cp. java -cp。 test01(.class) test01(.class)
but this doesn't works.但这不起作用。 It's very hard to use.它很难使用。

You would run你会跑

java com.test01.test01

but having a class with the same name as a package is a really bad idea (as well as not following the Java naming conventions).但是拥有一个与 package 同名的 class 是一个非常糟糕的主意(以及不遵循 Java 命名约定)。

You'd need to run it with the relevant class on the classpath.您需要在类路径上使用相关的 class 运行它。 For example, you could just compile it like this (from the "root" of your source tree):例如,您可以像这样编译它(从源代码树的“根”):

javac -d . [path to source file]
java com.test01.test01

or if you've got your source organized appropriately already:或者,如果您已经适当地组织了您的资源:

javac com\test01\test01.java
java com.test01.test01

You should be changing over to the base directory from where the classes start您应该切换到类开始的基目录

java -cp $CLASSPATH:.: com.test01.test01 java -cp $CLASSPATH:.: com.test01.test01

But naming a class "test01" is not a good naming convention.但是将 class 命名为“test01”并不是一个好的命名约定。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM