使用javac编译多个jar和java文件 [英] Compiling multiple jar and java files using javac

查看:74
本文介绍了使用javac编译多个jar和java文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我下载了一个用 java 编写的示例代码,其中包含多个 jar 文件和 java 文件.我不是 Java 程序员,所以我很难编译代码.这是我的尝试:

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

然而这是我得到的:

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

我的方法有什么问题,我该如何编译代码?所有的jar 文件都在lib 文件夹中,java 文件在src 文件夹中.

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.

推荐答案

You need to stop the shell from globbinglib/*.jar 中的通配符逃避它.

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

此外,您需要删除 .jar 后缀...因为类路径通配符就是这样工作的;请参阅 Oracle 的"设置类路径" 文档.

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

所以……

javac -classpath lib/* src/*.java

<小时>

使用 IDE 是另一种选择.但是,如果您只想编译和运行,那么下载、安装和学习使用 IDE 就有点过头了 (IMO).另一方面,对于使用 IDE 的 Java 程序员来说,了解如何在 shell 提示符下编译和运行也很有好处......


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

这篇关于使用javac编译多个jar和java文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆