Makefile with Jar and Package settings

I tried all day to get this work to work. Basically I need to create a makefile to create my project from its sources. I am a little versed in Linux, but not really, and I am a complete beginner in makefile.

I have tried many examples from across the network and everyone complains that they have no dependencies. Others have suggested using Ant or Mavern, but this is not possible because the exact delivery notification:

Quote from specification

Your view should consist of a single file comp2010.tar suitable for use on a Linux system. This should contain the Makefile and all sources. You do not have .class files. Your Makefile should build the tool from Java sources. the main class should be called Blaze. In a short, (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 Linux training environment with Java 1.6. CLASSPATH will include ANTLR Bank, version 3.2.

NOTE. Make sure your presentation can be compiled and executed on a standard departmental machine. Make sure you use the correct version of Java and that you are not using absolute paths. If you use any external libraries, you must also submit them.

So, you see that I cannot configure any environment variables since the machine to start is not mine and I am not allowed access to the administrator. I cannot transfer class files, so the make file is not for me, and the Ant / Mavern scripts will not work, because the testing procedure is automated and uses this make file, and all that I am allowed to use is .java files. Therefore, I need to create a make file, and it is not.

The structure of the source is as follows:

SIC \ Package1 * .java

SIC \ Package2 * .java

automatically generated \ package Hotel * .java

There are source files in all 3 folders required for compilation. The Main () method is in src \ Package1 \ 1.java

Each of these directories is a package in Eclipse, and these 3 packages are dependent on each other, as well as the external Jar file antlr-3.2.jar


So how do I make this make file. This is my question, and I made 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 happens with errors like "org.antlr.runtime does not exist", it is inside antlr-3.2.jar. I am alone with myself and must give up soon. I assume that I am just importing the jar incorrectly and maybe I need to use any CLASSPATH. I'm sorry if this is a simple question, but I tried six hours to make one of them. Any help you could give would be most appreciated.

Regards Feldoh

+4
source share
3 answers

Here I see several problems:

  • as described, you need to install the Blaise class in the default package in the root directory of the tar file
  • any packages you use should also be present directly in the root directory, and not in the source subdirectory (since Java / Javac cannot find them there)
  • make is specific when you use spaces and tabs.
  • your makefile does not use javac command options
  • In what version of make are you trying to create a makefile? the version I know will take the format:

     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) $< 
+4
source

If you are using a class path that does not include the current directory, make sure you also provide the path to the source.

 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 

An alternative would be to use a classpath, which includes the current directory (since the class path is used when you do not specify the source path):

 CLASSPATH = .:antlr-3.2.jar %.class: %.java $(JAVAC) -classpath $(CLASSPATH) $< 

(rest as above)

Of course, you can also add parameters to the JAVAC variable.

+3
source

Correct your javac call by adding antlr to the classpath. I really despised the automated labeling scripts that my CS professors used. They stochastically failed based on load. Here is a good introduction to Java and Makefiles. Basically try combining your .java and .class files. Use JFLAGS to pass antlr to the class path .

0
source

Source: https://habr.com/ru/post/1345895/


All Articles