I am attempting to write a makefile for any java project as below. I've got a database connected (installed and examined working after i compile with another IDE rather than javac). I don't know crafting the motive force into makefile. For an additional makefile, after typing make, I acquired message: package com.mysql.jdbc doesn't exist. However I have mysql-connector-java-5.1.16-bin.jar within the same folder as my makefile.

JC = javac\

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

JavaLibraries = \


default: classes

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

    $(RM) *.class

Thank you for any input.

I am unable to stress enough that Java making does not fit well together. It's likely you'll encounter serious problems because they build a Java project with make.

However, if you want to make use of make, despite all alerts, then you've to regulate the classpath configurations for that Java compiler:

JC = javac

.SUFFIXES: .java .class
      $(JC) $(JFLAGS) -cp $(CLASSPATH) $*.java


Therefore the CLASSPATH includes all used JARs and also the package root directory of the *.java files (I believed that's the present directory), separated with a colon on Unix/Linux systems or semicolon on Home windows. Then within the .java.class rule you need to call the Java compiler using the -cp flag to pass through the classpath.

This Database Schema Definition Language project consists of an exemplary [cde] that shows how you can initialize and test a database via JDBC. Observe that build.xml targets are perfectly fine as make instructions.


I want is write a ant for other people to make use of.

This other answer shows among invoking makefile from a javac. It shows how you can range from the makefile, which might solve your immediate problem however the approach quickly becomes unwieldy for additional elaborate develops, for example individuals including packages. This is often somewhat mitigated using the [cde] function:


A far simpler plan would be to write a small subst target, for example PKG = com.name.util PKG_PATH = $(subst .,/,$(PKG)) , as proven here then your corresponding ant command is straightforward:

<target name="compile"…>

Certainly, the make now is dependent on .SUFFIXES: .java .class .java .class: ant compile , but makefile is rather ubiquitous.