Javadoc examples: Comments and usage in Eclipse

 IT, Java  Kommentare deaktiviert für Javadoc examples: Comments and usage in Eclipse
Jul 052014
 

Javadoc for java Packages

It is also possible to add a comment / short description of a package. This can be done using a file called package-info.jave inside the package. When using eclipse, you can check the option „Create package-info.java“:

Create package-info.java

Create package-info.java

Change the default comment to something like this. Important: Use only one sentence and don’t forget the point at the end.

Change comment to something like this

Change comment to something like this

This will result in:

Package description

Package description

 

Using Javadoc for classes

To describe classes, you should start with a single sentence at the beginning. This sentence is used on the overview page of a package where all classes are listed (with a short description which is this sentence). Dont forget the point at the end.

The next paragraph contains a more detailed description that will be shown on the detail page of the class. Here you can use some html tags. In this case I used a list. After that you can add some javadoc parameter.

package com.pbo.Game;

/**
 * This Class represents the main class of the F1 Betting Game.
 * <p>
 * This Class handles all the database connection stuff, it creates the GUI
 * and it contains all the rules. See method: displayRules.
 * <br>
 * It also Starts the database connection, create instances of users and rankings and so on.
 * <ul>
 * 		<li>You can also</li>
 * 		<li>use a list</li>
 * 		<li>here in the description of the class</li>
 * </ul>
 * 
 * @author philipp
 * @version 0.1
 */
public class GameStarter {
    // your class here
}

Result of that comment:

Package Overview shows all classes with a short description

Package Overview shows all classes with a short description

 

Overview of one class

Overview of one class

 

Javadoc for methods

To describe methods you should begin with a short description in a single sentence. This sentence will be displayed in the method-overview of the class. After that sentence you should describe your method more detailed. This will be the description of the method. There you can use html-tags like linebreak <br> , lists <ul> , <li>, and more. You can create paragraphs by using the <p> tag. See the example below:

/**
 * This method displays all the rules for the game.
 * <p>
 * Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
 * eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
 * voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
 * clita kasd. <br>
 * Nonumy eirmod tempor invidunt ut labore et dolore magna aliquyam erat,
 * sed diam voluptua.
 * <p>
 * Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
 * eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
 * voluptua. At vero eos et accusam et justo duo dolores et ea rebum. Stet
 * clita kasd gubergren, no sea takimata sanctus est Lorem ipsum dolor sit.
 * <p>
 * Lorem ipsum dolor sit amet, consetetur sadipscing elitr, sed diam nonumy
 * eirmod tempor invidunt ut labore et dolore magna aliquyam erat, sed diam
 * voluptua dolor sit amet.
 * <ul>
 * <li>Rule 1 ...</li>
 * <li>Rule 2 ...</li>
 * <li>Rule 3 ...</li>
 * </ul>
 * 
 * @param userName
 *            The username of the Player
 * 
 * @param difficulty
 *            The difficulty of the game, from 1 to 10, where 1 is simple
 *            and 10 means strong
 * @return the status code after the game has finished. 1=won, 2=lost
 */
public int displayRules(String userName, int difficulty) {
	// your code goes here
	return 2;
}

Results in:

Javadoc Method Overview

Javadoc Method Overview

and:

Javadoc Method Details

Javadoc Method Details

 

Apache Ant – Copy files to ftp server

 Eclipse, IT, Java  Kommentare deaktiviert für Apache Ant – Copy files to ftp server
Jul 162013
 

Sample for copying files to an FTP Server:

<?xml version="1.0" encoding="UTF-8"?>
<project name="project" basedir="." default="deploy">
	<target name="deploy">

		<ftp server="myserver.de"
	   port="21"
	   remotedir="/html/testing/"
	   userid="myUser"
	   password="myPassword"
	   passive="yes"
	   depends="yes"
	   binary="no">
			<fileset dir="Testing">
				<include name="*.php"/>
				<include name="*.js"/>
			</fileset>
		</ftp>

	</target>
</project>

By default, ant is not able to process this, because the ftp classes are not included by the typical ant installation.

To enable ant to use ftp tasks, you have to download the apache commons ftp package. The dependencies of Apache Ant can be found here: http://ant.apache.org/manual/Tasks/ftp.html

Place the downlaoded commons-net.jar file into the lib folder of your ant installation. Now you can execute the ant tasks in your cmd shell.

If you have placed the jar-file outside the ant-lib directory you can run the ant-script with the lib-parameter:

ant -lib "/home/philipp/java/libs/commons-net-3.3/commons-net-3.3.jar"

Links:

Apache commons net: http://ant.apache.org/manual/install.html#commons-net

Ant FTP Task: http://ant.apache.org/manual/Tasks/ftp.html

Eclipse Updates or Plugins are not working – Linux / RHEL

 Eclipse, IT, Java, Linux  Kommentare deaktiviert für Eclipse Updates or Plugins are not working – Linux / RHEL
Sep 242012
 

Few days ago I wrote an article about how to Install Eclipse on RHEL (https://philipp-boss.de/it/linux/how-to-install-svn-eclipse-on-redhat-6-3-rhel-6/)

After I installed some plugins I noticed, that they are not working with the „standard“ user. When installing the plugins as root they worked well.

I found a very good explanation on the Google GWT Plugin Page:

https://developers.google.com/eclipse/docs/faq?hl=de#multiuser

To avoid any problems with the installation and update of plugins, you should directly after you extracted the eclipse*.tar change the owner via:

sudo chown -R <user> eclipe

After I changed the owner to my current user, the installation and updates of my plugins worked perfectly fine.

I hope this tip can also help you 😉

 

Java RMI – How to setup java.rmi.server.codebase in Eclipse

 Eclipse, IT, Java  Kommentare deaktiviert für Java RMI – How to setup java.rmi.server.codebase in Eclipse
Aug 302012
 

A typical problem when running and building java RMI Applications is the following Exception:

Registering server with rmiregistry
Error happened: RemoteException occurred in server thread; nested exception is: 
    java.rmi.UnmarshalException: error unmarshalling arguments; nested exception is: 
    java.lang.ClassNotFoundException: com.ibm.pbo.rmi.HelloInterface

To handle that problem, you have to set the following JVM Argument when running the ServerApplication:

-Djava.rmi.server.codebase=file:/abc/def

When using Eclipse, you can set this Argument in the Run Configuration:

Right Click on the ServerApplication java file -> Run As -> Run Configuration

Go to the Arguments Tab and insert the codebase argument in the VM Arguments Section:

 

Be careful with the trailing slash at the end. This slash is NECESSARY.

When I tried to point to the src directory of my Project it did not work, but if it points to the bin directory it worked fine.

-Djava.rmi.server.codebase=file:/home/philboss/Projekte/Eclipse_workspace/JavaRMI/bin/

Have fun with Java RMI 🙂

Eclipse User Libraries – How to manage build path libraries for several projects easily

 Eclipse, IT, Java  Kommentare deaktiviert für Eclipse User Libraries – How to manage build path libraries for several projects easily
Aug 272012
 

After switching my Workspace from Windows to Linux, I had to reconfigure the build-Path for each Eclipse project separately. This was a lot of work, so I took a look on how to manage build path libraries easily.

Eclipse ships a great solution for that, called „User Libraries“.

I will show you the advantages of user libraries and how to use them:

The Problem:

After switching my workspace to Linux, I had several Build Path errors like this:

 

The Solution:

To solve that, I had to reconfigure the build Path for all of my Projects in order to make them working.

This is a lot of work and if you want to upgrade your required Libraries (in this case you want to upgrade from ActiveMQ 5.4.3 to ActiveMQ 5.6.1) you have again to reconfigure all Build Paths that require that jar-File.

The Solution: User libraries

To avoid that, I decided to use User Libraries. How is it working? You can create your own libraries in which you can put several jar files (or classes). Then you have to reconfigure your build path in the projects to use the user libraries instead of the single jar files. If you now upgrade your Jar file (for Example ActiveMQ) you only have to modify your user library instead of all your project build paths.

 

Example in Pictures:

3 Projects that are using the same libraries:

Now we will create a User Library that contains the activemq-all.jar and log4j.jar file (Window -> Preferences:)

Add the needed jar-files to that library:

Then you see something like this:

Then you can reconfigure your projects to use this user library instead of the single jar-files (right click on project -> Build Path -> configure Build Path), remove the single jar files, and Add your user library (Add Library -> User Library -> „Your own Lib“):

Old build path:

New Path (with user library):

 

Projects View old:

 

Project View with user library:

 

Now you can apply that for all your Projects that are using ActiveMQ and/or log4j:

 

In the future you only have to maintain your user library and it will effect all the projects that are using that library:

Have fun with your own user libraries 😉