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

 

Using javadoc ant task

 IT, Java  Kommentare deaktiviert für Using javadoc ant task
Jul 052014
 

Javadoc is a very powerful and helpful tool of java. You can document your source, as well as insert installation or configuration information. The usage of javadoc in ant is very comfortable, setup once, use every build.
Here is an example of a simple javadoc ant task:

<target name="createJavadoc">
	<!-- this classpath is only necessary when using 3rd party libs or annotation processing -->
	<path id="annotations.classpath">
		<fileset dir=".">
			<include name="lib/**/*.jar" />
		</fileset>
	</path>
	
	<!-- creata javaDoc for package com.pbo.* inside src folder. Store javadoc in folder javaDoc -->
	<javadoc packagenames="com.pbo.*" 
		sourcepath="src" 
		defaultexcludes="yes" 
		destdir="javaDoc" 
		author="true" 
		version="true" 
		use="true" 
		classpathref="annotations.classpath" 
		splitindex="true" 
		nonavbar="true"
		windowtitle="F1 Betting Game : Documentation">
			<doctitle>
				<![CDATA[<h1>F1 Betting Game</h1>]]>
			</doctitle>
		<bottom>
			<![CDATA[Copyright © Philipp Boss.<br/> <b>Please contact Philipp Boss in case of questions</b>]]>
		</bottom>
	</javadoc>
</target>

This task creates the javadoc for the package com.pbo.* inside the src-folder and stores the created doc files inside the javaDoc folder.

The parameter nonavbar hides the navigation bar in the created doc files. For my opinion this generates more „clean“ javadoc pages. The windowtitle is the title of the html-page (what you can see in your browser tab), the doctitle is the one beeing displayed inside the web page. The value of bottom is beeing displayed at the end of the page.

Here you can see the created page:

Javadoc created Webpage

Javadoc created Webpage

Using SVN in Ant

 IT, Java  Kommentare deaktiviert für Using SVN in Ant
Jun 062014
 

In my current ant-script I need to get the SVN revision to insert that info into the deployment-package.

There are three commands available.

svn info is the first one:

D:\Projekte\workspace\myCode >svn info
Pfad: .
URL: https://svn.xxx.xx/abc/def/
Basis des Projektarchivs: https://svn.svn.xxx.xx/abc/def/
UUID des Projektarchivs: hidden
Revision: 12955
Knotentyp: Verzeichnis
Plan: normal
Letzter Autor: pbo
Letzte geänderte Rev: 12859
Letztes Änderungsdatum: 2014-05-21 10:10:14 +0200 (Mi, 21. Mai 2014)

The Revision is the current Revision of the Repository (that means, that if you checkin some changes now, you will get the Revsion 12955+1). The „Letzte geänderte Rev“ (last changed revision) ist the one which was assigned on the last commit/checkin. This is the revision of code that is checked in on the repository. This format is diffiult to handle in ant, that’s the reason why I present another solution:

svnversion

svnversion without any parameter will display the revsion of the repositry:

D:\Projekte\workspace\myCode>svnversion
12955M

„M“ means, that the local code has changed (modified). If you need the latest commited revision, you can append the parameter „-c“:

D:\Projekte\workspace\myCode>svnversion -c
11789:12859M

The firs number is the revision that was assigned during first checkin of this project / path. The second number is the revision of the latest commit. There is also a third solution:

svn log

With the svn command with the log parameter you are able to see the commit-messages. With some parameters you can display only the latest commit, including revsion number, date and author:

D:\Projekte\workspace\myCode>svn log -r COMMITTED -q
------------------------------------------------------------------------
12859| pbo | 2014-05-21 10:10:14 +0200 (Mi, 21. Mai 2014)
------------------------------------------------------------------------

How to use this in ant:

<target name="svnversion">
	<exec executable="svnversion" outputproperty="svnversion" />
	<echo message="SVN Version: ${svnversion}" />
</target>

Results in:

Buildfile: D:\Projekte\workspace\myCode\svn.xml
svnversion:
     [echo] SVN Version: 129555M
BUILD SUCCESSFUL
Total time: 834 milliseconds

 

<target name="svnLog">
	<exec executable="svn" outputproperty="lastCommittedRevision">
		<arg value="log" />
		<arg value="-r" />
		<arg value="COMMITTED" />
		<arg value="-q" />
	</exec>
	<echo message="lastCommittedRevision = " />
	<echo message="${lastCommittedRevision}" />
</target>

Results in:

Buildfile: D:\Projekte\workspace\myCode\svn.xml
svnLog:
     [echo] lastCommittedRevision = 
     [echo] ------------------------------------------------------------------------
     [echo] r12859 | pbo | 2014-05-21 10:10:14 +0200 (Mi, 21. Mai 2014)
     [echo] ------------------------------------------------------------------------
BUILD SUCCESSFUL
Total time: 1 second

 

Configure ActiveMQ Web console for password secured broker / Queues

 IT, Java  Kommentare deaktiviert für Configure ActiveMQ Web console for password secured broker / Queues
Aug 162013
 

In my last post about ActiveMQ I showed how to configure ActiveMQ in order to secure the Queues by Username and Password.

In the last days I noticed, that the web console throws an exception when I try to click on one of the queues. I realized, that the webconsole couldn’t open the queue because it is password protected.

In the logfile there was an exception like this (see the bold words):

2013-08-15 17:09:23,486 | WARN  | Failed to add Connection ID:PBOSS-56722-1376579349017-3:1, reason: java.lang.SecurityException: User name [system] or password is invalid. | org.apache.activemq.broker.TransportConnection | ActiveMQ VMTransport: vm://localhost#1-1
2013-08-15 17:09:23,489 | INFO  | Connector vm://localhost Stopped | org.apache.activemq.broker.TransportConnector | qtp2024674927-37
2013-08-15 17:09:23,490 | WARN  | /admin/browse.jsp | org.eclipse.jetty.servlet.ServletHandler | qtp2024674927-37
org.springframework.beans.factory.BeanCreationException: Error creating bean with name ‚queueBrowser‘ defined in ServletContext resource [/WEB-INF/webconsole-query.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [org.apache.activemq.web.QueueBrowseQuery]: Constructor threw exception; nested exception is javax.jms.JMSException: User name [system] or password is invalid.

Ok, now we see, that the web console seems to use the username „system“ by default. But in my configuration the queues are secured by „superman“ and „boss“. So I have to „tell“ the web console this information. You can define that in the file: <activemq-home>/conf/credential.properties:

#this is the queue User
activemq.username=supermann
#this is the queue password
activemq.password=boss

Now you have to restart MQ and the web console will work fine 🙂

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