简体   繁体   English

如何在命令提示符下运行依赖于YahooFinance jar文件的多个.java文件

[英]How to run multiple .java files with dependency to YahooFinance jar file in Command Prompt

So I am trying to run my multiple .java files with a dependency to an external jar file. 因此,我试图运行与外部jar文件相关的多个.java文件。 The structure of my program looks like this.. 我的程序的结构如下所示。

Folder

  • AccountReport.javaDriver.java AccountReport.javaDriver.java
  • EquityAccount.java EquityAccount.java
  • SavingsAccount.java SavingsAccount.java
  • YahooFinanceAPI-3.6.0.jar YahooFinanceAPI-3.6.0.jar

The way I must do it is... 我必须做到的方式是...

"When I grade your homework I will be using the command prompt to compile and run the programs. Ideally, I'd like to be able to compile/run these two commands from the command prompt: “当我为作业评分时,我将使用命令提示符来编译和运行程序。理想情况下,我希望能够从命令提示符处编译/运行这两个命令:

javac *.java javac * .java

java Driver Java驱动程序

If you are using a jar file, however, it may not be that simple. 但是,如果您使用的是jar文件,则可能不是那么简单。

Before you hand in your code please copy all of the .java files that you wrote into a new directory. 在提交代码之前,请将所有编写的.java文件复制到新目录中。 If you are using a jar file put it in the same directory. 如果使用的是jar文件,请将其放在同一目录中。 Then try and build and run the program from the command prompt. 然后尝试从命令提示符下构建并运行该程序。

If you have to alter the two commands about please put a comment in your driver that tells me how to build it (to include a classpath, for example). 如果必须更改这两个命令,请在驱动程序中添加一条注释,告诉我如何构建它(例如,包括类路径)。

You may have to rename the class that holds main to "Driver". 您可能必须将保存main的类重命名为“ Driver”。

If you are using Eclipse, you may also have to remove any package statements that were added for you by Eclipse (you can comment them out if you'd like). 如果您使用的是Eclipse,则可能还必须删除Eclipse为您添加的所有程序包语句(您可以根据需要将其注释掉)。

It is up to you to ensure that I can build and run the code!" 您有责任确保我可以构建和运行代码!”

I have tried to run the following line "javac -classpath YahooFinance.jar Driver.java" in the command line but I get error messages. 我试图在命令行中运行以下行“ javac -classpath YahooFinance.jar Driver.java”,但收到错误消息。

命令提示符错误消息

All of the classpath files compile but once I type "java Driver" the error message pop up 所有的类路径文件都会编译,但是一旦我输入“ java Driver”,就会弹出错误信息

输入“ javac -cp YahooFinance.jar * .java后,弹出的.class文件

You need to also specify the classpath when you run you code. 运行代码时,还需要指定类路径。

java -classpath .;YahooFinanceAPI-3.6.0.jar Driver

The . . includes the current directory on the classpath, which is the default, but you're overriding it with the jar, so you now need to explicitly include it. 在类路径中包含当前目录,这是默认目录,但是您用jar覆盖了它,因此现在需要显式包含它。

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

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