简体   繁体   English

使用javac编译多个jar和java文件

[英]Compiling multiple jar and java files using javac

I downloaded a sample code written in java that has multiple jar files and java files.我下载了一个用 java 编写的示例代码,其中包含多个 jar 文件和 java 文件。 I am not a Java programmer so I am having a hard time compiling the code.我不是 Java 程序员,所以我很难编译代码。 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.所有 jar 文件都位于 lib 文件夹中,而 java 文件位于 src 文件夹中。

You need to stop the shell from globbing the wild-card in lib/*.jar by escaping it.你需要从停止外壳globbing在野生卡lib/*.jar通过转义它。

Also, you need to remove the .jar suffix ... because that's how classpath wildcards work;此外,您需要删除.jar后缀……因为这就是类路径通配符的工作方式; see Oracle's "Setting the classpath" document.请参阅 Oracle 的“设置类路径”文档。

So ...所以 ...

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

Using an IDE is another option.使用 IDE 是另一种选择。 However, if all you want to do is compile and run, then downloading and installing and learning to use an IDE is overkill (IMO).但是,如果您只想编译和运行,那么下载、安装和学习使用 IDE 就有点过头了 (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 ...另一方面,对于使用 IDE 的 Java 程序员来说,了解如何在 shell 提示符下编译和运行也很有好处……

old post, but thought below details help, you can specify jar files by separating by ;旧帖子,但认为下面的详细信息有帮助,您可以通过分隔指定 jar 文件; in windows and : in unix在 Windows 中和:在 unix 中

Eg: (windows)例如:(窗户)

javac -cp first.jar;second.jar;third.jar YourClass.java

(unix) (Unix)

javac -cp first.jar:second.jar:third.jar YourClass.java

Source: https://gullele.com/pass-all-the-jars-in-classpath-when-compiling-java/来源: https : //gullele.com/pass-all-the-jars-in-classpath-when-compiling-java/

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

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