如何从控制台运行已编译的java项目,而不是从IntelliJ运行 [英] How to run compiled java project from console, not from IntelliJ
问题描述
在编译演示项目之后,out> production> testPrj> apidemo中有许多.class文件。基本上,每个文件都有一个.class文件
After the the demo project is compiled, there are many .class file in the out>production>testPrj>apidemo. Basically, each file will have one .class file
我希望进入控制台:
java apidemo.class
java apidemo.class
但它不起作用。
我试过java apidemo.class。错误消息是错误:无法找到或加载主类apidemo。
I tried "java apidemo.class". The error msg is "Error: Could not find or load main class apidemo".
我还读到了这个帖子。这对我的情况不起作用。我的编译成功,它可以从Intellj运行,但我不知道如何从控制台运行它。如何从控制台运行已编译的java项目?
I also read this post. It is not working for my situation. My compile is success, and it can be run from Intellj, but I don't know how to run it from console. How do I run a compiled java project from console?
推荐答案
您需要提供具有包名称的类的完全限定名称,而不是包含.class。因此,您需要将自己放在父目录中,其中 ApiDemo.class
是 - 即out> production> testPrj。
You need to provide the fully qualified name of the class with package name and not include ".class". So you need to place yourself in the parent directory to where ApiDemo.class
is - i.e. out>production>testPrj.
然后执行:
$ java apidemo.ApiDemo
另一种方法是提供out / production / testPrj作为类路径:
Another way is to provide "out/production/testPrj" as the classpath:
$ java -cp /path/to/out/production/testPrj apidemo.ApiDemo
这篇关于如何从控制台运行已编译的java项目,而不是从IntelliJ运行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!