如何在Windows中的命令行中运行此Java类? [英] How to run this java class in command line in windows?

查看:57
本文介绍了如何在Windows中的命令行中运行此Java类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package com.test01;

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

我认为Java应用程序启动器非常愚蠢.我已经指出了test01.class的位置:
java -cp.test01(.class)
但这是行不通的.很难使用.

I think the java application launcher is very stupid. I have point out the test01.class position:
java -cp . test01(.class)
but this doesn't works. It's very hard to use.

推荐答案

您将运行

java com.test01.test01

但是拥有一个与包同名的类是一个真正的好主意(以及不遵循Java命名约定).

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).

您需要在类路径中使用相关的类来运行它.例如,您可以只是这样编译(从源代码树的根"):

You'd need to run it with the relevant class on the classpath. 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

这篇关于如何在Windows中的命令行中运行此Java类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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