Showing posts with label Eclipse. Show all posts
Showing posts with label Eclipse. Show all posts

Thursday, July 24, 2014

Including Java Documentation in Eclipse projects


1- Create an Eclipse project
1-a. On "File" menu of Eclipse menu bar, select "New" menu item, and then select "Other...".
1-b. In the "New" window, open the "Java" folder from the list, and select "Java Project" within it. Click on "Next" button.
1-c. In the "New Java Project" window fill the "Project name" text field, e.g. "UtilityLibrary", and click on "Finish".
1-d. In the "Package Explorer", right click on the project name, select "New" and then, "Package".
1-e. In the "New Java Packge" window fill the "Name" text box, e.g. "domain.app.libraries.utilities". Click on "Finish" button.
1-f. In the "Package Explorer", right click on the package name, select "New" and then, "Class".
1-g. In the "New Java Class" window fill the "Name" text box, e.g. "Utility". Select "Generate comments" check box. Click on "Finish" button.
1-h. In the "Utility.java" file complete the following code:
/**
 * Utility.java
 *  Author name 24/7/2014
 */
package domain.app.libraries.utilities;
/**
 * Utility class.
 * @author Author name
 */
public class Utility {
/**
* This method return a customized phrase.
* @param name The name.
* @return Customized phrase.
*/
public static String getPhrase(String name) {
return "Welcome back, " + name + "!";
}
}
2- Generate Javadoc and export the  project
2-a. From "Project" menu, select "Generate Javadoc...".
2-b. In the "Generate Javadoc" window, accept the default options by clicking "Finish". (A "doc" folder is generated in the project, with the Java documentation of this library.)
2-c. In the "Package Explorer", right click on the project name, select "Export...".
2-d. In the "Export" window, open "Java" folder from the list, select "JAR file" and click "Next" button.
2-e. In the "JAR Export" window, fill the "JAR file" text box with the appropiate path, e.g. "\home\username\Development\lib\utilitylibrary.jar", and click "Finish".

3- Library usage
3-a. On "File" menu of Eclipse menu bar, select "New" menu item, and then select "Other...".
3-b. In the "New" window, open the "Java" folder from the list, and select "Java Project" within it. Click on "Next" button.
3-c. In the "New Java Project" window fill the "Project name" text field, e.g. "Program", and click on "Finish".
3-d. In the "Package Explorer", right click on the project name, select "New" and then, "Package".
3-e. In the "New Java Packge" window fill the "Name" text box, e.g. "domain.app.console.program". Click on "Finish" button.
3-f. In the "Package Explorer", right click on the package name, select "New" and then, "Class".
3-g. In the "New Java Class" window fill the "Name" text box, e.g. "Program". Select "public static void main(String[] args)" and "Generate comments" check boxes. Click on "Finish" button.
3-h. In the "Package Explorer", right click on the project name, select "Build Path" and then, "Configure Build Path...".
3-i. In the "Properties for Program" window, select "Libraries" tab and click on "Add External JARs" button.
3-j. In the "JAR Selection" window, browse to the location where you saved the JAR file in step 2.e ("\home\username\Development\lib\") and select it ("utilitylibrary.jar").
3-k. Open the newly added JAR file from the list, select "Javadoc location: (None)" and click on the "Edit..." button.
3-l. In the "Javadoc For 'utilitylibrary.jar'" window select "Javadoc in archive" and "External file" and fill the "Archive path" text field with the JAR file's location ("\home\username\Development\lib\utilitylibrary.jar"). Also, fill the "Path within archive" text box with "doc". Then, click "OK" button.
3-m. Click "OK" button in the "Properties for Program" window.
3-n. Now, you can write code in the "Program" class with the help of the Javadoc generated in "UtilityLibrary" project. Complete the following code in the "Program" class of the "Program" project:
(Please, observe the help as you write the code.)
/**
 * Program.java
 *  Adrián E. Córdoba 24/7/2014
 */
package domain.app.console.program;
import domain.app.libraries.utilities.Utility;
/**
 * Main class that use a JAR file as library.
 * @author Adrián E. Córdoba
 */
public class Program {
/**
* Main method that prints a statement obtained from the Utility class library.
* @param args Not used.
*/
public static void main(String[] args) {
String phrase = Utility.getPhrase("Adrián Córdoba");
System.out.println(phrase);
}
}

Monday, July 21, 2014

Eclipse installation on Linux platforms


1. Download the appropiate Eclipse IDE for Java EE Developers version for your architecture (32 or 64 bits) from http://www.eclipse.org/downloads/.
     For this explanation, I suppose the file is downloaded to "Downloads" directory of the "username" home directory ("/home/username/Downloads/").
2. As a root user, extract the archived files from downloaded file in step 1.
 $ su
Password: <Type the root password>
# cd /usr/local/
# mv /home/username/Downloads/eclipse-jee-luna-R-linux-gtk-<version>.tar.gz .
# tar -zxvf eclipse-jee-luna-R-linux-gtk-<version>.tar.gz
     In this step, Eclipse Luna was installed on "/usr/local/" directory. Now you can remove the downloaded file:
# rm eclipse-jee-luna-R-linux-gtk-<version>.tar.gz
3. In order to run Eclipse from the graphic interface, create a link to Eclipse in your desktop. As normal user, enter in a terminal:
$ cd /home/username/Desktop
$ ln -s /usr/local/eclipse/eclipse Eclipse