1

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?

5
  • Are u talking about a .jar file or .java files ? because .java file is creating for every class you create
    – Sudantha
    Oct 28, 2010 at 5:41
  • it is .java. I have many classes defined in my single java file. Oct 28, 2010 at 5:42
  • 1
    2. Some make implementation work best if you intend with tab character. Use good text editor that shows tabs and spaces. There are many good programmer editors like Context, Notepad++, Edit+. Use them not notepad. Oct 28, 2010 at 6:16
  • 1
    1. In makefile backslash at end of line means continuation in next line. Remove it from line with singlefile.java Oct 28, 2010 at 6:23
  • I had got the same error , Resolved it by giving proper tab space for dependencies and the command Mar 13, 2018 at 11:58

7 Answers 7

4

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.

4

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.

4

Make insists that you use tabs instead of spaces. The error message even tells you that "(did you mean TAB instead of 8 spaces?)". So go to the lines where the code is indented, press backspace 8 times, then press tab. Do this on all lines and it will work.

2

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

1

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.

0
1

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.

0

download "managing projects with GNU make" from http://www.wanderinghorse.net/computing/make/ by Stephan Beal and original edition by Robert Mecklenburg, and look at page 121. It has everything you need to build Java using gnumake

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.