简体   繁体   中英

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. The structure of my program looks like this..

Folder

  • AccountReport.javaDriver.java
  • EquityAccount.java
  • SavingsAccount.java
  • 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

java Driver

If you are using a jar file, however, it may not be that simple.

Before you hand in your code please copy all of the .java files that you wrote into a new directory. If you are using a jar file put it in the same directory. 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".

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

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.

命令提示符错误消息

All of the classpath files compile but once I type "java Driver" the error message pop up

输入“ 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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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