Shaun Abram
Technology and Leadership Blog
Intellij Maven folders
I haven’t been coding a lot recently, and when I spun up a new maven spring boot project and imported in to IntelliJ, I got confused about which folders are supposed to be marked as source (src, src/main or src/main/java?) and test (src/test or src/test/java?).
Using Docker with a maven project
If you have a maven project, there are a plethora of ways to enable it to run within a docker container.
Tags: containers, docker, helloworld, Maven, mvn, springboot
Maven (mvn) build hanging
I recently had a problem with a maven build hanging when doing a ‘mvn install’.
I found some pointers in this post, and posting here in a modified form: http://forum.spring.io/forum/spring-projects/roo/121725-what-diagnostic-action-to-take-when-maven-hangs
1. In the hanging shell, hit CTRL-Z – this will suspend the program and give you a pid. An alternative way to get the pid is to do a “ps -ef” and search for you mvn command e.g. “clean install”
2. type bg [ENTER] – this will send the program to the background
3. Do a kill -3 of the process – it will dump a large amount of text – make sure your command line terminal history window is long enough to capture it all – will be several thousand lines of text
(alternative to #3 – you can try jstack with the pid, it is a Java stack trace generator)
4. You can see what threads are waiting on other threads from there (maybe, sometimes it’s a tight CPU loop)
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.
Running an individual unit test with maven
Individual tests can be run from maven. This must be done from within the folder that contains the source (as in the folder that contains src/test/java), which will likely be either be the root of your maven project, or in one of your modules.
For surefire (unit tests), to run a whole test class, this will be something like:
mvn -Dtest=com.your.package.YourTest test
or, to run a specific test method:
mvn -Dtest=com.your.package.YourTest#testMethod test
For failsafe (integration tests), it will be something like:
mvn -Dit.test=com.your.package.YourIT verify
This is covered in the maven surefire plugin docs and maven failesafe plugin docs respectively, but those examples don’t mention packages names, which are required.
Tags: failsafe, integrationtesting, JUnit, Maven, mvn, surefire, Testing, unittesting
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.
Tags: intellij, Maven, mvn, Testing
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:
- Apache source code for maven-archetype-quickstart and maven-archetype-webapp
- Apache guide to creating archetypes; Wiki on creating an archetype
- How is metadata about an archetype stored?
- Stackoverflow question on how to create the src/main/resources folder with the quickstart folder. I posted a link to my maven-archetype-quickweb archetype there.
- Stackoverflow question on how to use a custom maven archetype
Tags: archetype, Maven, mvn, quickweb
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: intellij, Java, Java8, Maven, mvn
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: archetype, devops, gradle, Maven, mvn
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: helloworld, jnlp, Maven, mvn, swing, webstart
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