Showing posts with label java. Show all posts
Showing posts with label java. Show all posts

Saturday, October 5, 2013

Simple Java development setup

A simple setup for small Java development projects could be:
  • Create the source directory ($PROJ_HOME) which will contain all .java files.
  • Create the directory $PROJ_HOME/proj_name which will contain all the .class files.
  • Add $PROJ_HOME to the CLASSPATH.
  • During development, keep a terminal open with working directory $PROJ_HOME, and run "javac *.java -d ." to compile all source files and store the class files in proj_name.
  • Run a class from anywhere using java proj_name.ClassName [args].
In addition:
  • Store metadata files etc. required by the code in $PROJ_HOME/meta. If they need to be passed by command line arguments, you can pass $PROJ_HOME/meta/datafile.txt as an argument wherever you are running the class.
  • Store sample test data files to quickly test the code in $PROJ_HOME/test.

Friday, February 4, 2011

Setting classpath when compiling/running Java

Set the CLASSPATH environment variable to
- the directories having .class files
- the .jar files which contain relevant .class files

Then run javac and java; it will pick required the .class files from its location.

If you say
export CLASSPATH=dir1
and the .class file is dir1/dir11/abc.class, then you must say
java dir11.abc
to enable java to find abc.class.