Sunday, August 12, 2007

Maven Download Sources

When using maven, it normally downloads only the binaries from the dependencies your project has.
It is possible, with simple commands, to also download the source and/or documentation from the dependencies you are interested in.

To download sources:

mvn [goal] -DdownloadSources=true


To download javadocs:
mvn [goal] -DdownloadJavadocs=true

Maven Eclipse

The maven eclipse plugin is provided for those who have a ready .pom file for a maven project and want to start using eclipse as the IDE for the project.

The command is as simple as running:

mvn eclipse:eclipse

This command have a number of parameters, but one of the most interesting ones would be the one which allows to create a WTP (Web Tools Platform) aware eclipse project.

mvn eclipse:eclipse -Dwtpversion=1.0

This command will create an eclipse project with WTP 1.0 support.

Friday, August 3, 2007

Adding Repositories to Maven 2

Maven uses on-line repositories to find the dependencies you set in your pom file. By default, maven uses the repository specified in the

If you want to use other repositories, you are able to do so by adding a ~/.m2/settings.xml file. This file should be provided in the following format:


<settings>
<profiles>
<profile>
<id>standard-extra-repos</id>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<repositories>
<repository>
<id>jboss</id>
<url>http://repository.jboss.com/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>jboss-snapshot</id>
<url>http://snapshots.jboss.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>jboss-plugins</id>
<url>http://repository.jboss.com/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>false</enabled>
</snapshots>
</pluginRepository>
<pluginRepository>
<id>jboss-snapshot-plugins</id>
<url>http://snapshots.jboss.org/maven2</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
</profile>
</profiles>
</settings>


Some repositories I've collected and you might be interested in using, because some artifacts are available only through some of these repositories and not all of them. It is important to remember that the more repositories you add, the slower will be your build, so use them with wisely.

Repository
http://www.ibiblio.org/
http://download.java.net/maven/2
http://repo1.maven.org/maven2
http://repository.jboss.com/maven2
http://maven.apache.org/
http://mojo.codehaus.org/


Snapshot
http://snapshots.jboss.org/maven2
http://people.apache.org/repo/m2-snapshot-repository
http://snapshots.maven.codehaus.org/maven2
http://snapshots.repository.codehaus.org


If you want to download snapshot version of maven plugins, there is a page which explains how to setup your settings.xml file.

Using HSQLDB database - the basics

HSQLDB is a powerful database engine. It is normally used to provided an embedded database functionality for java applications.

It is as simple as downloading a zip file, extracting it into your system and you have a functioning RDBMS.

After extracting the zip file, you should have the following (resumed) structure in your system:


/hsqldb
/bin (scripts for running the server and utilities)
/demo (scripts and applet examples)
/doc (guess what?)
/lib (all binaries - including hsqldb.jar)
/src (all source code)
index.html (documentation about the distribution)


The hsqldb.jar is everything you need to run the database application. It contains the RDBMS, the driver and some tools (the database manager, the query tool and the command line tool).

Running the tools

To run some of the tools, enter the lib folder and run the following command, which will run the database manager.

java -cp hsqldb.jar org.hsqldb.util.DatabaseManager


The main classes for the tools deployed with the hqsldb.jar are:


  • org.hsqldb.util.DatabaseManager

  • org.hsqldb.util.DatabaseManagerSwing

  • org.hsqldb.util.Transfer

  • org.hsqldb.util.QueryTool

  • org.hsqldb.util.SqlTool



HSQLDB may run in standalone (in-process) or server mode. There are three server modes, based on the protocol used for communications between the client and server and they are HSQLDB Server, Web Server and Servlet. It is also possible to run HSQLDB in a way that the database is not persistent and exists entirely in random access memory.

The default user and password for connecting to the database is "sa" / "sa".

For more information on this powerful tool, read the online manuals or the documentation provided with the distribution zip file in the doc folder.

Sunday, July 15, 2007

Debugging Struts Information

Some time ago I posted an article about debugging information in a JSP page. Struts tags have an interesting tag with almost the same functionality I wrote before.

It is very simple to use. All you need, is add the tag below to your code, provided all the jstl information are correct (in web.xml and/or standard.jar and/or jstl.jar).


<%@ taglib prefix="s" uri="/struts-tags" %>
...
<s:debug/>

Choose Java Version for Maven compile

It is possible to set the version of the jdk one wants to use when compiling code using maven.

This might be mandatory if your code uses generics or annotations. So here is the code you should add to your pom.xml.


<build>
...
 <plugins>
...
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <source>1.5</source>
     <target>1.5</target>
    </configuration>
   </plugin>
 </plugins>
...
</build>
...

Friday, June 8, 2007

Build Struts 2 Application Using Maven 2

I really think that using Maven as tool to build Java Projects is simply great, but if there is one thing I hate is searching ibiblio for the dependencies I need for my project. So I will post below the path for the main components one will need to get started with Struts 2 on his project.

By default, Maven will look for the dependencies on its central repository http://repo1.maven.org/maven2. It is possible to configure the repositories where you want maven to look up for files. These two below are some alternative repositories where you can try to find components you need. In the apache repository below is possible to find the SNAPSHOT version of the components.

Just add the code below into your pom file.


<repositories>
  <repository>
    <id>ibiblio</id>
    <name>iBiblio Maven2 Repository</name>
    <url>http://www.ibiblio.org/maven2</url>
  </repository>
  <repository>
    <id>apache-repo</id>
    <name>Apache Repository</name>
    <url>http://people.apache.org/repo/m2-snapshot-repository</url>
  </repository>
</repositories>


Check the official Maven site about how to setup multiple repositories.

Now, we can reach for those components! :)
As advised by the struts team, the minimum set of components one might need is below.

  • struts2-core.jar

  • xwork.jar

  • ognl.jar

  • freemarker.jar

  • commons-logging.jar


Fortunately, to download all of them automagically, all you need to add to your pom files are the lines below:


  <dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>2.0.6</version>
  </dependency>


Wanna do this even faster? Use maven archetypes to create a struts2-aware project! ;)


mvn archetype:create -DgroupId=tutorial \
    -DartifactId=tutorial \
    -DarchetypeGroupId=org.apache.struts \
    -DarchetypeArtifactId=struts2-archetype-starter \
    -DarchetypeVersion=2.0.5-SNAPSHOT \
    -DremoteRepositories=http://people.apache.org/repo/m2-snapshot-repository