简体   繁体   English

Java:如何向makefile添加多个外部库?

[英]Java: How to add multiple external libraries to makefile?

My java project makes use of some apache commons libraries. 我的Java项目使用了一些Apache Commons库。 I want to be able to run my program in unix though so i made a makefile to compile it for me. 我希望能够在Unix中运行程序,所以我制作了一个makefile来为我编译它。 My project has 4 Java classes and 4 external libraries (.jars). 我的项目有4个Java类和4个外部库(.jars)。 In my directory i have my four .Java files and a folder named "lib" which contain my .Jar files. 在我的目录中,我有四个.Java文件和一个名为“ lib”的文件夹,其中包含我的.Jar文件。 Here's my make file: 这是我的make文件:

 JFLAGS = -g
JC = javac -sourcepath / -classpath lib/commons-httpclient-3.1.jar:lib/commons-io-2.4.jar:lib/commons-codec-1.9.jar:lib/commons-logging-1.1.3.jar
.SUFFIXES: .java .class
.java.class:
$(JC) $(JFLAGS) $*.java

CLASSES = \
SubmissionDriver.java \
FileAndArgs.java \
hashConverter.java \
InvalidAgeException.java

default: classes

classes: $(CLASSES:.java=.class)

clean:
    $(RM) *.class

And here's my error messages: I get like 14 error message that pertain to the actual class files though. 这是我的错误消息:虽然我收到14条错误消息,但它们与实际的类文件有关。 Here's some examples: 这里有一些例子:

SubmissionDriver.java:74: error: cannot find symbol
    public static void httpSend() throws HttpException, IOException{
                                         ^
  symbol:   class HttpException
  location: class SubmissionDriver
SubmissionDriver.java:75: error: cannot find symbol
            HostConfiguration hf=new HostConfiguration();
            ^
 symbol:   class HostConfiguration
 location: class SubmissionDriver
SubmissionDriver.java:75: error: cannot find symbol
            HostConfiguration hf=new HostConfiguration();
                                     ^
 symbol:   class HostConfiguration
 location: class SubmissionDriver
SubmissionDriver.java:77: error: cannot find symbol
            PostMethod post = new PostMethod("myurl");
            ^

Also it states this at the bottom of thsoe 14 error messages: 它还在thsoe 14错误消息的底部指出了这一点:

14 errors
make: *** [SubmissionDriver.class] Error 1
  1. Make is not a good build tool for java. Make不是Java的良好构建工具。 Try ant perhaps (or Maven, or Gradle) 尝试蚂蚁(或Maven或Gradle)
  2. The way your makefile is structured you invoke a "javac" command for each java class. 生成文件的结构方式为每个Java类调用一个“ javac”命令。 This will not work if your java classes have dependencies on each other 如果您的Java类相互依赖,则此方法将无效
  3. Make sure you have a tab before this line 确保在此行之前有一个选项卡

    $(JC) $(JFLAGS) $*.java $(JC)$(JFLAGS)$ *。java

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

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