简体   繁体   English

通过命令行运行Java程序

[英]Running a java program through command line

I am running a Java program with the following command: 我正在使用以下命令运行Java程序:

java -cp .:./* com.bot.fix.botclient

All the jar files are in the same directory. 所有的jar文件都在同一目录中。 It works FINE! 很好! But what if I want to run it from a different folder? 但是,如果我想从其他文件夹运行该怎么办?

The full location of the java program is: FIX/fixprog/src/com/fix/botclient Java程序的完整位置为:FIX / fixprog / src / com / fix / botclient

But if I try to run: 但是,如果我尝试运行:

java -cp FIX/fixprog/src/* FIX/fixprog/src/com.bot.fix.botclient

I get: 我得到:

Error: Could not find or load main class FIX.fixprog.src.com.bot.fix.botclient

What am I doing wrong? 我究竟做错了什么? How can I run the same Java program but not in the same directory? 如何运行相同的Java程序但不在同一目录中?

Try if below works. 请尝试以下方法。 You don't need to specify path when giving the fully qualified name of your java class that you are trying to execute. 在给出尝试执行的Java类的完全限定名称时,无需指定路径。 The "cp" part takes care of it. “ cp”部分会处理它。

java -cp FIX/fixprog/src com.bot.fix.botclient

If you have only jar files try: 如果只有jar文件,请尝试:

java -cp FIX/fixprog/src/* com.bot.fix.botclient

If you have also classes you should try: 如果您还有其他课程,则应尝试:

java -cp FIX/fixprog/src/*:FIX/fixprog/src/ com.bot.fix.botclient

If both did not work perhaps you shoud use absolut path with disk unit if you are using windows. 如果两种方法都不起作用,那么如果您使用的是Windows,则应该在磁盘机上使用绝对路径。

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

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