Compiling multiple jar and java files using javac

青春壹個敷衍的年華 提交于 2020-02-22 07:18:37

问题


I downloaded a sample code written in java that has multiple jar files and java files. I am not a Java programmer so I am having a hard time compiling the code. Here's my attempt:

javac -classpath lib/*.jar src/*.java

However this is what I get:

javac: invalid flag: lib/dom4j-1.6.1.jar
Usage: javac <options> <source files>
use -help for a list of possible options

What's wrong with my approach and how can I compile the code? ALl the jar files are located in the lib folder, and the java files in the src folder.


回答1:


You need to stop the shell from globbing the wild-card in lib/*.jar by escaping it.

Also, you need to remove the .jar suffix ... because that's how classpath wildcards work; see Oracle's "Setting the classpath" document.

So ...

javac -classpath lib/\* src/*.java

Using an IDE is another option. However, if all you want to do is compile and run, then downloading and installing and learning to use an IDE is overkill (IMO). And the flipside is that it is good for an IDE-using Java programmer to also understand how to compile and run from the shell prompt ...



来源:https://stackoverflow.com/questions/30313812/compiling-multiple-jar-and-java-files-using-javac

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