title: Java makefile run
body: <p>I have a project that I created with eclipse.
  Now I want to copy this project to my linux computer to compile and run it there.</p>
  
  <p>For this I want to create a makefile for compiling and running automatically.</p>
  
  <p>I already have created a makefile and it can compile my project.
  But now it should start my program after compiling and I dont know how to make this.</p>
  
  <p>I want to type "make" and it should compile the source and after that it should start my main automatically. For now I have a shellscript that does the following.</p>
  
  <pre><code>make
  java Main
  </code></pre>
  
  <p>I already tried to run "make run" but I get an error.</p>
  
  <pre><code>No rule to make target 'Main', needed by 'run'.
  </code></pre>
  
  <p>This is my Makefile.</p>
  
  <pre><code>JFLAGS = -g
  JC = javac
  JVM= java
  FILE=
  .SUFFIXES: .java .class
  .java.class:
      $(JC) $(JFLAGS) $*.java
  CLASSES = \
      Main.java \
      Class1.java \
      Class2.java \
      Class3.java \
      Class4.java
  
  MAIN = Main
  
  default: classes
  
  classes: $(CLASSES:.java=.class)
  
  run: $(MAIN).class
      $(JVM) $(MAIN)
  
  clean:
      $(RM) *.class
  </code></pre>