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

查看:431
本文介绍了使用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.

推荐答案

您需要通过转义从lib/*.jar中的通配符globbing停止shell.

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天全站免登陆