How to write "set classpath" in a makefile for Java on Linux?

I have a newbie question for writing makefile for java on Linux

I have a project with:

A.java
B.java
C.java

A depends on B.java and C.java, they must be in the same folder

It is assumed that when I enter the folder, I can run the make command to generate the classes.

How to set classpath as current ABC file folder?

This question may be easy for you, but I spend hours on Google and still can't get it to work ...

Thanks again.

Details of my make file:

JFLAGS = -g

JC = javac

CLASSPATH = .





.SUFFIXES: .java .class

.java.class:

    $(JC) $(JFLAGS) $*.java



Heap.class: FibonacciHeap.java \

    FileOperation.java \

    MinLeftistTree.java \

    RandomPermutation.java \

    Heap.java 



default: classes



classes: $(CLASSES:.java=.class)



clean:
$(RM) *.class

Heap.java should be compiled after executing other java files ...

I google a lot and don’t quite understand the grammar for the make command ....

Excuse me for my problem with the newbie ...

+3
source share
4

( ):

/src
    A.java
    B.java
    C.java

/classes , /src. , /src, /classes:

javac -d ./classes src/*.java

.class /classes.

C , , :

java -cp .;classes C

, :

A.java:

public class A
{
    public String toString() { return A.class.getName(); }
}

B.java:

public class B
{
    public String toString() { return B.class.getName(); }
}

C.java:

public class C
{
    public static void main(String [] args)
    {
        A a = new A();
        B b = new B();
        C c = new C();

        System.out.println(a);
        System.out.println(b);
        System.out.println(c);
    }


    public String toString() { return C.class.getName(); }
}

make, , :

http://www.cs.swarthmore.edu/~newhall/unixhelp/javamakefiles.html

Swarthmore, ?

, . .java , .

#
# define compiler and compiler flag variables
#

JFLAGS = -g -cp .:./classes -d ./classes
JC = javac 


#
# Clear any default targets for building .class files from .java files; we 
# will provide our own target entry to do this in this makefile.
# make has a set of default targets for different suffixes (like .c.o) 
# Currently, clearing the default for .java.class is not necessary since 
# make does not have a definition for this target, but later versions of 
# make may, so it doesn't hurt to make sure that we clear any default 
# definitions for these
#

.SUFFIXES: .java .class


#
# Here is our target entry for creating .class files from .java files 
# This is a target entry that uses the suffix rule syntax:
#   DSTS:
#       rule
#  'TS' is the suffix of the target file, 'DS' is the suffix of the dependency 
#  file, and 'rule'  is the rule for building a target  
# '$*' is a built-in macro that gets the basename of the current target 
# Remember that there must be a < tab > before the command line ('rule') 
#

.java.class:
        $(JC) $(JFLAGS) $*.java


#
# CLASSES is a macro consisting of 4 words (one for each java source file)
#

CLASSES = \
        Foo.java \
        Blah.java \
        Library.java \
        Main.java 


#
# the default make target entry
#

default: classes


#
# This target entry uses Suffix Replacement within a macro: 
# $(name:string1=string2)
#   In the words in the macro named 'name' replace 'string1' with 'string2'
# Below we are replacing the suffix .java of all words in the macro CLASSES 
# with the .class suffix
#

classes: $(CLASSES:.java=.class)


#
# RM is a predefined macro in make (RM = rm -f)
#

clean:
        $(RM) *.class
+5

ant (http://ant.apache.org/), make.

, javac (, javac -cp. A.java), classpath ( , make).

0

, , . .

classpath , . Linux - " CLASSPATH = $CLASSPATH:.".

0

javac A.java B.java C.java ' java A.java sudo java A.java, / root.

IDE, Eclipse, . .

0
source

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


All Articles