Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>If you have an arrangement like this (I'll assume no packages for now):</p> <pre><code>/src A.java B.java C.java </code></pre> <p>Create a directory <code>/classes</code> at the same level as <code>/src</code>. Then run this command in a command shell after navigating to the folder that contains both <code>/src</code> and <code>/classes</code>:</p> <pre><code>javac -d ./classes src/*.java </code></pre> <p>You'll find all your .class files in the <code>/classes</code> folder.</p> <p>If C has the main method you need to run, you'll do it like this: </p> <pre><code>java -cp .;classes C </code></pre> <p>Here are the samples that I used to do it:</p> <p>A.java:</p> <pre><code>public class A { public String toString() { return A.class.getName(); } } </code></pre> <p>B.java:</p> <pre><code>public class B { public String toString() { return B.class.getName(); } } </code></pre> <p>C.java:</p> <pre><code>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(); } } </code></pre> <p>If you insist on using make, perhaps this will help:</p> <p><a href="http://www.cs.swarthmore.edu/~newhall/unixhelp/javamakefiles.html" rel="noreferrer">http://www.cs.swarthmore.edu/~newhall/unixhelp/javamakefiles.html</a></p> <p>You aren't a Swarthmore student, are you?</p> <p>Here, I've doctored their make for your case. Change the .java files and see if it works.</p> <pre><code># # 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 &lt; tab &gt; 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 </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload