RSS Feed Subscribe to RSS Feed

 

Creating a Maven multi module project

There is no easy way, or simple archetype, to create a maven multi module project. The approach below is the best way I’ve found so far.

(more…)

Tags: , ,

Running an individual unit test with maven

mvn -Dtest=com.your.package.YourTest test

Run from within the folder that contains the src (as in src/test/java) folder, which will likely be either be the root of your maven project, or in one of your modules.

This is covered maven surefire plugin docs but the example always confuses me slightly since it omits the packages names, which are required.

Tags: , , ,

Running tests in IntelliJ for a multi module maven project

This post shows how to run all the tests in IntelliJ for a multi module maven project.

(more…)

Tags: , , ,

Maven Quickweb Archetype

The maven Quickweb archetype allow you to create a new project with a layout that is essentially a combination of what you get with the standard maven archetypes of quickstart and webapp. The readme on Github contains more details: https://github.com/sabram/maven-archetype-quickweb

If you are interested in the underlying workings, the ‘recipe’ for the archetype is the archetype descriptor, archetype.xml, which is located in the src/main/resources/META-INF/maven/ directory. It specifies what files the generated project will be made up of, in addition to the prototype pom, all of which are located in the archetype-resources folder.

Links:


						

Tags: , , ,

Using Java8 with Maven in IntelliJ (invalid target release: 1.8)

I recently started trying out the early access version of Java8. When I tried using it with maven in IntelliJ however, I got the following error when I ran the maven install command:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.1:compile (default-compile) on project xyz:

Fatal error compiling: invalid target release: 1.8\

Although I saw some suggestions on stackoverflow here about hardcoded JAVA_HOME paths, the solution was just changing the maven specific version of Java that IntelliJ uses. This can be done via:

File > Settings > Project Settings > Maven > Runner

and selecting the 1.8 version of the JRE.

Tags: , , , ,

Maven archetypes to create your project folder structure

Maven archetypes are useful for many things, including creating a folder structure to start with, even if you aren’t planning to use maven as your build tool. See a list of available archetypes here.
(more…)

Tags: , , , ,

Cloudbees

I’ve been using CloudBees a lot recently for deploying to ‘the cloud’.
There are a couple of things that attract me to CloudBees…
Read more

Tags: , , , , ,

Swing, Webstart and Maven – An Example

Following my introductory rant on the subject, this post is a working example of using Swing and Webstart with a multi-module maven project.

Complete source can be downloaded from here.
Read more

Tags: , , , , ,

Swing, Webstart, Maven – a difficult combination

I have spent the last few weeks struggling with a Swing app that I wanted to deploy via Webstart and build using Maven, via the the Webstart Maven Plugin. It has been a hugely painful process. I found the plugin documentation difficult to follow, struggled to understand the subtle config differences in jnlp, took longer than I expected to get jar signing working, had problems with webstart caching and suffered through a plethora of vague error messages. I found this posting where the author vowed to never use Webstart again, and I can empathize. Postings of people asking for help with Webstart problems certainly aren’t difficult to find. Using maven to build the jnlp provides some conveniences, but introduces new problems too. Overall, I’d prefer to avoid using a Swing/Webstart/Maven solution again.
Read more

Tags: , , , , ,

Running Hibernate unit tests with Maven

I recently converted a project I have been working on to use Maven. After setting up all the dependencies in the pom, I got everything compiling fine but ran into problems getting the unit tests to pick up the hibernate config (hibernate.cfg.xml) and hibernate mapping (*.hbm.xml) files. With hindsight, it is straightforward, but it took me a while to figure it out so I thought I’d post the solution here.

Initially, I had my hibernate.cfg.xml file in the following directory

my-app/src/main/java

And when I first tried to run my hibernate unit tests (mvn test), I got this error:

SessionFactory creation failed.org.hibernate.HibernateException: /hibernate.cfg.xml not found

Some checking of the maven docs and some forums revealed the following possible solutions:
1) Copy the hibernate.cfg.xml file to

my-app/target/classes

This works, however I think it is a hack as the target folder is generated rather than being somewhere you should actually manually create files.
2) The next solution I found suggested moving the hibernate.cfg.xml to

my-app/src/main/resources

This works well as the contents of this folder are copied to the base level of the my-app/target/classes folder so it is basically a ‘more correct’ solution than the first.
3) The next and I think best solution was to create a new, duplicate hibernate.cfg.xml inside

my-app/src/test/resources

This allows a different hibernate.cfg.xml file to be used for testing and, for example, facilitates connecting to a different database (such as hsqldb) for testing while continuing to use your regular database (such as MySQL) for the app itself.

A couple of points to note:

1) The hibernate mapping files (i.e. the *.hbm.xml files) should also be in the resources folder (in whatever directory structure you choose) to ensure that these too are accessible by the unit tests.

2) I am not (yet) using Spring with the hibernate components, which would likely have changed the above setup.

Refs/links

http://maven.apache.org/guides/getting-started/index.html#How_do_I_add_resources_to_my_JAR

http://www.mail-archive.com/users@maven.apache.org/msg54720.html

Tags: , ,