简体   繁体   中英

JAVA, Batch file errors

I have an existing Java project that compiles and runs properly through Eclipse. I have created the following .bat file to run the program sans Eclipse:

java -classpath jflashplayer.jar;bin TestProgram

The file is saved within the project folder, but not within the bin folder (located in same directory as bin ). When I try to run the batch, I am met with a large number of runtime errors, the first being

Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/apache/commons/io/FileUtils

I'm not sure why I get this error when it compiles and runs properly via Eclipse. I have the commons-io jar files linked to the project within Eclipse as libraries, and the jar files are themselves located in the project file (same directory as the batch file and the bin folder).

Also, I'm not entirely sure what the -classpath jflashplayer.jar bit of the batch file is doing. I am using the jflashlayer.jar library (also linked to the project within Eclipse and in the same location as the other jar files), but I am not sure why it would appear in the batch file. I edited an existing batch file from a similar project that uses the jflashplayer.jar files, and it has worked previously to leave that part in.

When I write code in Java, I rarely require it to compile/run outside of the IDE, so I usually have troubles when it comes to this part. Perhaps there is a more robust and foolproof method to run the program outside of the IDE other than the batch file method.

The batch file method is fine, but you have to specify all the libraries you're using on the classpath, just like the jflashplayer.jar .

In this case, the error you're getting is because the Apache commons-io library is not specified on the classpath. Your command would have to look something like:

java -classpath jflashplayer.jar;commons-io.jar;<other jars ...>;bin TestProgram

Alternatively, you can create a runnable jar from Eclipse as described here . When you select a library handling strategy , choose the option Extract required libraries into generated JAR . This will make it so that all the library classes you're using are packaged into your application's jar file, and you can just execute it by invoking java -jar my_application.jar .

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