I have been trying all day to get this thing to work. Basically I need to create a makefile to build my project from its sources. I know a little about Linux but not much and I am a complete makefile newbie.
I have tried loads of examples from all over the net and all complain that they are missing dependencies. Others have suggested using Ant or Mavern but this is not possible the precise handin notice is:
Quoted from Specification
Your submission should consist of a single file comp2010.tar suitable for use on a Linux system. This must contain a file Makefile, and all sources. You should not hand in any .class files. Your Makefile must build the tool from the Java sources. The main class must be called Blaise. In short, the (automatic) testing process will consist of:
tar xf comp2010.tar
make
java Blaise < test.file > testout 2> testerr
These commands will be executed in an empty directory in a standard departmental teaching Linux environment with Java 1.6. The CLASSPATH will include the ANTLR jar, version 3.2.
NOTE: Please ensure that your submission can be compiled and executed on standard departmental machines. Please make sure that you use the right version of Java, and that you do not use absolute paths. If you use any external libraries, you need to submit these as well.
So you see I cannot set up any environment variables as the machine to run it is not mine and I am not allowed administrative access. I cannot hand in any class files so the makefile is not for me and Ant / Mavern scripts will not work because the testing procedure is automated and uses this makefile and all I am allowed to hand in is .java files. So I need to build a makefile there is no way around that.
The source structure is as follows:
src\\Package1*.java
src\\Package2*.java
auto-generated\\PackageA*.java
There are source files in all 3 folders needed for the thing to compile. The Main() method is in src\\Package1\\1.java
Each of these directories is a package in Eclipse and these 3 packages depend on each other as well as an external Jar file antlr-3.2.jar
So How do I make this makefile. That is my question and I have provided my own attempt below:
JAVAC = javac
CLASS_FILES = src/package1/1.class auto-generated/packageA/2.class auto-generated/packageA/3.class auto-generated/packageA/4.class src/Package2/5.class src/Package2/6.class src/Package2/7.class src/Package2/8.class src/Package2/9.class src/Package2/10.class src/Package2/11.class src/Package2/12.class antlr-3.2.jar.*
Default: $(CLASS_FILES)
%.class: %.java
$(JAVAC) $<
clean: $(RM) *.class
This fails with errors like "org.antlr.runtime does not exist" this is inside the antlr-3.2.jar. I am at my wits end and need to hand in soon. I assume I am simply importing the jar all wrong and maybe I need to use whatever CLASSPATH is. Im sorry if this is a simple question but I have been trying for 6 solid hours now to make one of these. Any help you could give would be most appreciated.
Kind Regards Feldoh
I can see a few issues here:
which version of make are you trying to build a makefile for? the version I know would take a format like:
JAVAC = javac JAVACFLAGS = SRC= Blaise.java \\ package1/1.java \\ packageA/2.java CLS= $(SRC:.java=.class) all: $(CLS) .SUFFIXES : .class .java .java.class : $(JAVAC) $(JAVACFLAGS) $<
If you use a classpath which does not include the current directory, make sure you indicate a source path, too.
JAVAC = javac
CLASS_FILES = src/package1/1.class auto-generated/packageA/2.class auto-generated/packageA/3.class auto-generated/packageA/4.class src/Package2/5.class src/Package2/6.class src/Package2/7.class src/Package2/8.class src/Package2/9.class src/Package2/10.class src/Package2/11.class src/Package2/12.class
CLASSPATH = antlr-3.2.jar
SOURCEPATH = .
Default: $(CLASS_FILES)
%.class: %.java
$(JAVAC) -classpath $(CLASSPATH) -sourcepath $(SOURCEPATH) $<
clean: $(RM) *.class
The alternative would be using a classpath which includes the current directory (since the classpath is used, when you give no sourcepath):
CLASSPATH = .:antlr-3.2.jar
%.class: %.java
$(JAVAC) -classpath $(CLASSPATH) $<
(the rest as above)
Of course, you could add the options to the JAVAC
variable, too.
Fix up your javac call by adding antlr to the classpath. I really despised the automated marking scripts my CS professors used. They stochastically failed based on submission load. Here is a nice intro to Java and Makefiles. Basically try to glob your .java and .class files. Use the JFLAGS to pass antlr in the classpath .
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.