Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Making a Java Makefile

Tags:

java

makefile

EDIT: Essentially, I am trying to do the same thing as typing "javac sim.java" and then "java sim (commands)". Is there a way to replace this using a makefile?

So I have looked at a lot of examples online and tried to modify them to what I need, but nothing has worked. I need a makefile so that my teacher can create my project just by typing "make" into terminal (this is a requirement of the project for some reason). My end goal is to be able to type "sim" followed by the required commands as defined by my code. The code runs in eclipse, but I can't get it to run using these commands in terminal. It will make the file, but it says "sim: command not found" when I try to type "sim....(arguments)" into terminal. I'm sure this is a dumb question but we have not learned about this in school and I have no experience with Makefile.

Below is my makefile.

JFLAGS = -g
JC = javac
OPT = -O3
#OPT = -g
WARN = -Wall

sim: sim.class

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

clean:
    $(RM) sim.class

clobber:
    $(RM) sim.class
like image 344
Dude Avatar asked Mar 21 '15 16:03

Dude


People also ask

Is there a Makefile for Java?

Use the Makefile to Manage Large Projects in Java A Makefile is a way to manage large project files by compiling and linking them. A simple makefile contains variables and rules. Below is a basic syntax for creating a rule. In the above syntax, a target is the program's name to be generated.

What is Makefile used for?

Makefile sets a set of rules to determine which parts of a program need to be recompile, and issues command to recompile them. Makefile is a way of automating software building procedure and other complex tasks with dependencies. Makefile contains: dependency rules, macros and suffix(or implicit) rules.

What is make and Makefile?

Make is Unix utility that is designed to start execution of a makefile. A makefile is a special file, containing shell commands, that you create and name makefile (or Makefile depending upon the system).


1 Answers

For a simple project without many files or dependencies, I simply use scripts.

To build:

javac -cp .;* *.java

To run:

java -cp .;* SomeMainClass

Replace . with whatever path(s) you need for your source. The * will use any jar on the default path or use a different path like lib/*.

like image 180
Jeff Miller Avatar answered Sep 27 '22 18:09

Jeff Miller