Java and Technology weblog
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.
I’ve been looking at some .Net code recently, and I wanted to do some comparisons on Java access modifiers vs .Net to help me better understand the code.
A microservice is a small, focused piece of software that can be developed, deployed and upgraded independently. Commonly, it exposes functionality via a synchronous protocol such as HTTP/REST.
That is my understanding of microservices, at least. There is no hard definition of what they are, but they currently seem to be the cool kid on the block, attracting increasing attention and becoming a mainstream approach to avoiding the problems often associated with monolithic architectures. Like any architectural solution, they are not without their downsides too, such as increased deployment and monitoring complexity. This post will have a look at some of the common characteristics of microservices and contrast them with monolithic architectures.
There is no right answer to the question of what is the best Java web framework. Still I end up asking it to myself every time a new project crops up. I did a post on a related talk I saw at JavaOne last year, which provoked a lot of debate and some really interesting responses. More recently, this report from Zero Turnaround is useful and this comparison from Matt Raible is also well written.
I have also been swayed in the past by the Thoughtworks technology radar in which component based frameworks (which, I think, in the Java world includes JSF, Wicket and Tapestry) get a thumbs down e.g. see the May 2013 radar. GWT has also in the past (see July 2011 radar) been singled out as something to avoid. Presumably Vaadin falls in to the same ‘hold’ category. Full disclosure, I’ve had limited exposure to these types of frameworks personally though.
My own preference remains Spring MVC. It is relatively easy to setup (especially with Spring Boot), provides decent testing support, and obviously integrates well with the rest of the Spring ecosystem. I am admittedly biased due to already knowing Spring core, but so be it.
My recent, albeit limited, experience with Struts2 is that I have been fairly pleasantly surprised. It wasn’t as bad I was expecting! The Action classes, which are instantiated for each request, and hence threadsafe, are fairly easy to use and test. I am not so fond of the xml mappings and the variable passing that gets done there though. It seems kind of clunky, although there may be a better way I am not aware off.
Still, I am not likely to start using Struts by choice on my own projects anytime soon. Spring MVC remains my go-to web framework.
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.
- 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
As described here, IntelliJ’s live templates let you easily insert predefined code fragments into your source code.
I have posted some of my most used templates below, a link to my complete list of template files on GitHub (as a reference for myself when I setup new IntelliJ environments) and the steps I took to add the IntelliJ settings file to GitHub.
Unit tests are used to verify that a piece of code operates as the developer expects it to. Sometimes, that means checking that the code throws expected exceptions too. JUnit is the standard for unit testing in Java and provides several mechanisms for verifying exceptions were thrown. This article explores the options and their relative merits.
Java8 isn’t scheduled for for release until March 2014, but early release versions have been available for a while.
Some of the most interesting new features are:
- Functional interfaces
- Default methods
- Java Time
I started writing a blog post on what’s new in the upcoming Java8 release, and thought I would start by doing a quick look back at what Java7 brought to us.
Java7 was released back in July 2011, and was described as “more evolutionary than revolutionary”.
“There are some significant improvements, but no really earth-shattering or ground-breaking kinds of features.” – Oracle chief Java architect Mark Reinhold
It didn’t contain the much hyped lambda expressions for example. Still, it did bring a lot of other neat additions to the Java language. You can see the more at http://docs.oracle.com/javase/7/docs/, or read on for my summary.
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.