In java, packages are used to organize files, physically. It has no significance as far as source files are concerned. The real use comes when dealt with class files- they should be in the package hierarchy as defined by the package statement which comes as the first statement of the source code. Source files need not be in the package defined.
MainFrame.java need not be in path current-directory\src\ui\ when it is compiled. But MainFrame.class should be in the path current-directory\src\ui when it is executed.
source-directory-path\src>javac -d ..\build com\dh\lang\*.java com\dh\math\*.java
: The option “-d” is used to create the class files in some defined directory. Here the produced class files will be in the path
source-directory-path\build\com\dh\lang\ & source-directory-path\build\com\dh\math\
[follows that the source files are in source-directory-path\src\com\dh\lang\ and in source-directory-path\src\com\dh\math\]
source-directory-path\build>jar -cf ..\dist\MyAPI.jar com
: Here the jar file MyAPI.jar is created in source-directory-path\dist\
using the class files in package com. (cf = create file)
source-directory-path\build>jar -cvf ..\dist\MyAPI.jar com
: Here the progress of jar file creation will be displayed.(option v)
source-directory-path\src>javac -cp ..\lib\MyAPI.jar;..\lib\YourAPI.jar -d ..\build com\dh\appl\*.java
: Here we create an application using the API collection in MyAPI.jar, which reside in source-directory-path\lib (option -cp is used). If there is more than one jar file, each is separated by a semi-colon in Windows and colon in Linux.
Making application executable on double click...
- While creating a jar file META-INF\MANIFEST.MF is automatically created with some default attributes.
Created-By: 1.6.0_17 (Sun Microsystems Inc.)
- for jar file to be executable we must include some more attributes using a text file manifest.txt--
Class-Path: ..\lib\MyAPI.jar ..\lib\YourAPI.jar
source-directory-path\build>jar -cvmf manifest.txt ..\dist\MyAppl.jar com
: The appends the attributes defined in manifest.txt(option m) to META-INF\MANIFEST.MFand create a jar file MyAppl.jar which will be executable.