Though it\'s probably reccomended one uses and IDE for coding advanced java projects, I personally prefer running almost entirely command-line (using gedit as a text-editor)
There are three parts to it: (1) create directory structure; (2) indicate package in java file; (3) compile it.
For example, if you want to create package com.mycompany.myproject
, then you need to start in the base directory for your project and then:
(1) create directory com/mycompany/myproject
(2) create java files in that directory, stating package com.mycompany.myproject
in them;
(3) compile the files, for example, with javac -cp . com/mycompany/myproject/*.java
You may want to specify a different output directory so as to not mix sources and compiled classes.
If you need to use external libraries (.jar files) to compile, then you need to use -cp
or -classpath
command-line parameter to javac
tool to specify them, e.g.
javac -cp .:some_library.jar:lib/another_library.java com/mycompany/myproject/*.java
It may be a good idea to put all external libraries in one place, e.g. lib
subdirectory of your main project directory. And, by the way, the above javac
command assumes unix-like environment. If you're on Windows, then you'll need to use ;
for path separation.