简体   繁体   English

无法为JAVA创建Makefile

[英]Having trouble creating makefile for JAVA

I'd like to try and create a makefile for my project. 我想尝试为我的项目创建一个Makefile。 I am running this in linux not in windows, specifically ubuntu. 我在Linux中而不是Windows中(特别是ubuntu)中运行它。

This is what my project directory looks like: 这是我的项目目录:

project_root
    /src
        A.java
        B.java
        C.java
        D.java
    /bin
       #this is where I'd like the .class files
    /include 
        A.jar
        B.jar
        C.jar
    makefile
    run.sh

And this is what my makefile looks like: 这是我的makefile的样子:

JC = javac
CLASSPATH = .:include/*
SRCPATH = ./src/
OUTDIR = ./bin/

.SUFFIXES: .java .class

.java.class:
        $(JC) -cp $(CLASSPATH) $(OUTPATH) $*.java

CLASSES = \
        $(SRCPATH)A.java \
        $(SRCPATH)B.java \
        $(SRCPATH)C.java \
        $(SRCPATH)D.java 

default: classes

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

clean:
    $(RM) $(SRCPATH)*.class

When I run make in the project directory I get this output: 当我在项目目录中运行make时,得到以下输出:

make: *** No rule to make target `.java', needed by `javac'.  Stop.

Can anyone help? 有人可以帮忙吗?

I think you don't have a TAB character as the first character in the line when you define your .java.class suffix rule. 我认为您在定义.java.class后缀规则时没有TAB字符作为该行的第一个字符。

In make, every recipe line must include an actual TAB character (not just spaces) as the first character in the line. 在制作过程中,每个配方行必须包含实际的TAB字符(不仅仅是空格)作为该行中的第一个字符。 If the first character is not a real TAB, then it's not a recipe line. 如果第一个字符不是真正的TAB,则它不是配方行。

The reason you don't get a syntax error is because your line looks like a rule, due to the colon in the CLASSPATH ; 之所以没有语法错误,是因为CLASSPATH的冒号使您的行看起来像一条规则; it looks like this: 它看起来像这样:

javac -cp .:include/* ./bin/ .java

( $* expands to nothing here) which is parsed by make to be defining three targets, javac , -cp , and . $*在此处扩展为零)由make解析,以定义三个目标javac-cp. , each of which depends on include/* , ./bin/ , and .java . ,每个依赖于include/* ,. include/* ./bin/ include/*.java

Hence your error message. 因此,您的错误消息。

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

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