Shaun Abram
Technology and Leadership Blog
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
Stacks and Queues in Java
I have been working on some Java code recently that required both a stack and a queue. The choices to use aren’t immediately obvious. There is a Queue interface, but no clear concrete implementation to use. There is also a Stack class, but the javadocs point out that other classes “should be used in preference to this class”. So, what implementation do you use for stacks and queues in Java?
I found my quick rule of thumb to be that you can use the ArrayDeque class for both Stack and Queues, but some more details are below.
(more…)
Tags: collections, datastructures, queue, stack
Builder Pattern: Good for code, great for tests
I’ve found the builder design pattern occasionally useful in code, but frequently useful in tests. This article is a quick summary of the pattern in general, followed by look at a working example of using it in tests. See the code in github.
(more…)
Tags: builder, designpatterns, Testing, unittesting
SpringMVC file download
This post shows how to download a file using Spring MVC. For example, you have a SpringMVC web app and you want to include a link on a page that downloads a file to be opened on the user’s machine (e.g. a Microsoft Excel).
Read more
MyMoney – A simple SpringMVC app
I created a small, open source web app called MyMoney for entering and tracking spending details. It allows you to create accounts (for example Cash or Checking) and enter transactions associated with those accounts.
(Previously I had the code deployed on a CloudBees instance at http://mymoney.shaunabram.cloudbees.net, but CloudBees have since unfortunately shut down their free tier). Read more
Tags: Hibernate, spring, springmvc
415 ‘Unsupported Media Type’ error when submitting JSON from a JSP
I’ve been experimenting with submitting JSON data from a JSP to a Spring MVC Controller, using the Spring MVC Ajax example as my guide.
But after setting everything up, I continually ran into this error:
NetworkError: 415 Unsupported Media Type
The server refused this request because the request entity is in a format not supported by the requested resource for the requested method().
After much googling, I found a plethora of solutions, none of which worked for me. In the end, I found it was because I had omitted this line from my JSP:
">
Hope that helps someone else…
Tags: json, jsp, spring, springmvc
Spring MVC Hello World with Continuous Deployment
Oh dear, yet another ‘Hello World!’. But although the functionality is trivial, this little SpringMVC project is complete enough for me to use as a template to bootstrap more complex projects. It consists of:
- HTML/JSP client
- SpringMVC server using a Controller/Service/DAO design
- Maven for build and dependency management
This is an updated version of an older project I created, with the following enhancements:
- Added a full suite of automated tests (unit, integration and browser based)
- Added placeholders for JavaScript and images (both can be a little tricky to put in the correct place with SpringMVC)
- Incorporated into a continuous deployment environment
More details below, but you can find the full source code on this GitHub repository
(Previously I had the code deployed on a CloudBees instance at http://springmvc.shaunabram.cloudbees.net, but CloudBees have since unfortunately shut down their free tier).
Tags: cloud, cloudbees, continuousdeployment, continuousintegration, easymock, fest, helloworld, jenkins, spring, springmvc, Testing, unittesting
Running Jenkins jobs sequentially
I am a huge fan of the Jenkins continuous integration tool, using it not just for continuous integration, but also continuous delivery, server monitoring and performance testing.
Although using Jenkins is normally a breeze, I recently had a need to run several Jenkins jobs sequentially and it proved a little trickier than expected, so I thought worth posting about.
Basically, I wanted to call a database backup job before calling the deploy build job, which obviously shouldn’t be done in parallel. After a bit of research, I found a number of ways to have Jenkins run jobs sequentially.
Read more
Tags: agile, ci, continuousintegration, devops, hudson, jenkins
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
Tags: helloworld, jnlp, Maven, mvn, swing, webstart
JavaOne: Tuesday’s Keynote
This morning’s Keynote at JavaOne contained a few interesting announcements, including
- JDK7 for MacOS X Developer Preview announced by Hasan Rizvi (SVP @ Oracle). Available here.
- Java FX to be open sourced, and it will be proposed to the JCP (Confirmed, see press release)
- JDK8 will be released in the summer of 2013 (not 2012 as previously discussed), as announced by Adam Messinger from Oracle
There was also mention of an Oracle Java Magazine, which I confess I had never heard of before.
For a summary of this morning’s announcements, see here.
Overall, not the most exciting keynote I have seen. It opened with a presentation from Juniper Networks. I didn’t find the topic of “Programming the network” to bring networks and apps closer together particular relevant for me personally. They then rolled out a bunch of other corporate folks from the likes of Intel, Redhat, IBM and ARM. The Twitter guy did announce that Twitter are joining OpenJDK as well as the JCP though.
On to the sessions…
Tags: javaone, javaone2011
JavaOne: Comparing Java Web Frameworks
The first talk I attended at this year’s JavaOne was “Choosing Your Java Web Framework” by Richard Pack from salesforce.com
Overall, I found this a really interesting talk. It was lacking in any sales pitch, nor did it have the unquestioning devotion to one particular framework that I felt some of the Java FX talks had. Instead it seemed like an unbiased look at web frameworks in general and a handful of frameworks in more detail, based on Richard’s extensive and hands on experience and SalesForce and Hyperic.
Read more
Tags: grails, gwt, javaone, javaone2011, jsf, tapestry, webframework, wicket
@JavaOne
I am at JavaOne 2011 right now. Always fun and it seems to be bigger than last year, with a huge selection of talks and presentations (although frustratingly flaky wifi!).
Some of the themes of this morning’s keynote talk were JavaFX 2.0, what will be coming in Java 8 and a new Oracle NoSQL Database. There are some links here, here and here (and I believe the videos will be posted soon here).
I just attended a very useful Java Web Framework comparison talk that I will try to post about shortly. I also met up with some of the DZone team. For now, I am going to some JavaFX talks.
If any of you are attending, let me know!
Tags: javaone, javaone2011
Spring MVC Hello World
There is a good Getting Started with Spring MVC blog post over on the Spring team blog.
I have created several Spring MVC projects for both work and play, and am attaching my own simple version of the HelloWorld example here, based on the Spring blog example.
Find my maven ready source here.
Like my previous JSP/Servlet example, I find these templates useful for getting prototypes up and running.
Tags: helloworld, jsp, servlet, spring, springmvc, webapp, webframework
SLF4J & Logback is the new commons-logging & log4j
Interesting post on which logging framework to choose from the logging mess. TLDR; Use SLF4J and logback.
I still default to log4j, but it sounds like logback (as the new alternative to log4j), wrapped by SLF4J (as the new alternative to commons logging) is the way forward. Both are written by Ceki Gülcü (blog), the original log4j author.