Skip to content
/ java_on_nix Public template

Setting up a java project on nix

License

Notifications You must be signed in to change notification settings

benknoble/java_on_nix

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Java on *nix

This project is considered finished

This is a small sample project that seeks to provide a template or starter kit for java projects on *nix.

With that in mind, it provides a ready-to-go Makefile, along with a complete (dummy) java program as proof of concept that it works. The Makefile is commented and should prove fairly straightforward; I recommend reading the docs if there are questions.

Also check the .gitignore for some suggestions.

Makefile

Using the Makefile requires editing just a few key lines, all of which are variable definitions:

  • JAR_FILE controls the name of the produced jar
  • MAIN should be the path under src to a java file with the main method
  • TEST should be the path under src to a java file with a main method that invokes whatever test setup you have

Other variables can be changed in the Makefile or even set as environment variables, but should "just work" by default.

It assumes the following project structure

  • src contains .java source files
  • lib contains .jar files (libraries) on which the source depends
  • bin will contain generated .class files (and is automatically generated)
  • scripts will contain generated files that can be executed to run the program as if it were a regular CLI binary, passing along all arguments

Key Targets

  • all: the default. Builds the class files
  • jar: make the 'jarchive'
  • runners: make the scripts
  • test: run the tests
  • clean: delete any generated files
  • jdb: run the debugger (jdb)

Related

I've got a script to download the newest version of the Makefile here; it will even save and restore your changes to JAR_FILE and MAIN. If you change lots of things, though, I wouldn't recommend using it. This is a place where it's good to have things in version control.

Vim User?

See my Dotfiles for some examples of ways I make coding Java in Vim easier. Of particular relevance is my javamake compiler plugin.