Issue running java program from batch file, runs fine in IDE

北城以北 提交于 2019-12-05 18:25:58

Solved

Batch file now reads

javac TestShipment.java Shipment.java ShipmentHW1.java
cd ..
java shipment.TestShipment
pause

and it works like a charm. Anyone have any ideas why I had to call the package.class instead of just compiling it regularly?

Try doing

javac TestShipment.java
java TestShipment
pause

Without seeing the contents of TestShipment.java, I'll assume you have some dependency on the Shipment and ShipmentHW1 classes. As such, when you execute a program that uses the TestShipment class, you need to have the .class files for each of the three (and any other dependencies).

So you will have to compile Shipment.java and ShipmentHW1.java as well before running your java command. If they are in the same package, you're good, if not, you will have to specify an appropriate value for the -cp option.

When running java with a class name, you need to specify the fully qualified class name.

If your .java files are declared to be in the 'shipping' package, then you probably need to be running java from the parent directory of 'shipping', e.g.

cd <path>/shipping
javac TestShipment.java
cd ..
java shipping/TestShipment
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!