开发者

Makefile compilation issue with javac

I have a problem with a makefile. I have three classes. They do pretty simple stuff. One does an addition on a subtraction, and the last one will instantiate the two and simply print the resulted addition and subtraction.

Now when I create my makefile, I compile my Plus.java and my Minus.java but don't know how to compile the main class because it depends on the previous two. I want to compile and run it from the makefile if it's possible.

I get the above results when I try to run make:

javac -g Plus.class Minus.class
javac: invalid flag: Plus.class
Usage: javac <options> <source files>
use -help for a list of possible options
make: *** [Operation.class] Error 2

I don't know how to proceed; please forgive me if my question is to simple but I am new working with these stuff. I've searched many sites but with no answer.

Here is my Makefile:

JCC = javac

JCR = java

JFLAGS = -g

default: Operation.class

Plus.class: Plus.java
    $(JCC) $(JFLAGS) Plus.java

Minus.class: Minus.java
    $(JCC) $(开发者_如何学编程JFLAGS) Minus.java

Operation.class: Operation.class
    $(JCC) $(JFLAGS) Operation.class  

run: Operation.class
    $(JCR) Operation.class

clean:
    $(RM) *.class


You need to pass the names of source files to javac:

javac -g Plus.java

A better option is possibly:

javac -g *.java

Very few people in the Java world invoke javac directly or use makefiles. Most people use an IDE when developing:

Eclipse: http://www.eclipse.org
Netbeans: http://www.netbeans.org

And then a more comprehensive build tool for final / automated builds:

Ant: http://ant.apache.org/
Maven: http://maven.apache.org/

Both of those could be invoked from make, or indeed invoke make themselves, in order to integrate with your existing build system.

EDIT: It seems you have a makefile issue. See if this works:

JCC = javac
JCR = java
JFLAGS = -g

all:
[TAB]$(JCC) $(JFLAGS) *.java

run:
[TAB]$(JCR) Operation

clean:
[TAB]$(RM) *.class

Replace [TAB] with an actual tab character - as you probably know this is incredibly important in make!


you need to run javac -g Plus.java Minus.java (not .class)


Try this. Alas, managing Java class dependencies is a pain using make (been there done that in relatively large projects), so you should still seriously consider using Ant or some other appropriate tool.

JCC = javac

JCR = java

JFLAGS = -g

default: Operation.class

Plus.class: Plus.java
            $(JCC) $(JFLAGS) Plus.java

Minus.class: Minus.java
             $(JCC) $(JFLAGS) Minus.java

Operation.class: Operation.java Plus.class Minus.class
                $(JCC) $(JFLAGS) Operation.java 

run: Operation.class
    $(JCR) Operation.class

clean: $(RM) *.class


I solved it. It was a problem with the packages. I edited my files in netbeans and remained:

package operations

to every one of them

so I got Operation to compile but now it didn't run

Silly problem....

JCC = javac

JCR = java

JFLAGS = -g

default: Operation.class Plus.class Minus.class

Plus.class: Plus.java
    $(JCC) $(JFLAGS) Plus.java

Minus.class: Minus.java
    $(JCC) $(JFLAGS) Minus.java

Operation.class: Operation.java Plus.java Minus.java
    $(JCC) $(JFLAGS) Operation.java  Plus.java Minus.java

run:
    $(JCR) Operation

clean:
    $(RM) *.class
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜