views:

83

answers:

5

I am running Eclipse in windows for doing my homeworks. I have to submit a makefile so that my code (singlefile.java) can be compiled. How can I do this.

I found this. Can it be tested on windows.

EDIT: As per the suggestions, I installed gnu make for windows:

My make file is as follows:

JFLAGS = -g
JC = javac
#
.SUFFIXES: .java .class
.java.class:
        $(JC) $(JFLAGS) $*.java
CLASSES = \
        singlefile.java \
default: classes
classes: $(CLASSES:.java=.class)
clean:
        $(RM) *.class

However, when I run make, I am getting the error:

*** missing separator (did you mean TAB instead of 8 spaces?).  Stop.

I am new to make. What am I missing?

A: 

do you have to use make? or can you use any build tool. Make is rarely if ever used for java, usually ant.apache.org or maven.apache.org, the first being simpler.

MeBigFatGuy
yes, it is a requirement to use make.
iJeeves
+1  A: 

If you don't have any dependencies, you can write a makefile just as you would with C programs with something like:

JAVAC = javac

%.class: %.java
    $(JAVAC) $<

(note: you'd probably want a clean task as well)

If you're planning on continuing with java for more advanced projects, however, consider using maven or ant for building your project. Both can be integrated into eclipse so you don't have to do much work. Then you can wrap your 'mvn compile' command into a Makefile and forget about it.

Ben Taitelbaum
A: 

Because you're using Eclipse and Java you should look at creating an Ant buildfile.

Catchwa
+1  A: 

The Makefile you linked is a suitable starting point.

Can it be tested on windows?

Only if you have installed Cygwin or something like that. Even then, there is a small risk that you will create a makefile that contains Windows platform dependencies ...

I'd recommend testing the makefile on the platform that they provide for you to do your software development on, which is most likely some flavour of UNIX ... given that they expect you to supply a makefile.

But as others have said, if you have the option, use Ant instead of Make for building simple Java projects. Ant has the advantage of being more platform independent, and requiring little apart from an Ant installation and a Java installation.

Stephen C
+1  A: 

All you have to do with this makefile is to change Purchaser.java into your .java source and remove other .java sources from it. If you use Windows, then you probably do not have make installed in your system. You can install and use GNU make, Microsoft nmake or other. I think the simplest way to compile your program is to make .bat file with content like:

javac MyClacc.java

Of course you can add there javac flags like -deprecation etc.

Simplest form of makefile in your case can look like:

default:
    javac singlefile.java

clean:
    del singlefile.class

Be sure to make indentation (before commands like javac and del) with tab character.

Michał Niklas