Posts Tagged ‘maven’

Using jOOQ and Build Helper Plugin to Generate Database Metamodels with Maven

Tuesday, June 10th, 2014

When you need to derive meta-models from existing databases and want to create type-safe queries with an elegant, fluent-API, jOOQ definitely is a tool to consider here.

In the following tutorial I’d like to demonstrate how to integrate the jOOQ meta-model generator into a Maven build using the jOOQ Maven Plug-in, the Build Helper Maven Plug-in and Maven profiles to finally create a running application to query an existing RDBMS using such a generated meta-model.

(more…)

Allocating available random Ports in a Maven Build

Wednesday, May 7th, 2014

Recently in a project I encountered the following problem: The development team used Git with a branch-per-feature-like workflow and the integration server, Bamboo in this case, was configured not only to run the integration-tests for the master-branch but also for every change in a feature branch.

As the team  developed a Java EE web application ports like 8080 occasionally were already bound and builds failed.

I knew a plug-in for Jenkins CI I to search for available ports and assign them to a build variable but I wanted to control such information directly within the Maven build life-cycle so I searched and finally found Sonatype’s Port Allocator Plug-in for Maven.

In the following short example I’m going to demonstrate how to allocate available random ports in a Maven build and assign them to an embedded servlet container.

(more…)

Running JavaScript Tests with Maven, Jasmine and PhantomJS

Sunday, May 4th, 2014

Sometimes in a project there is the need to run tests for your client-side code, written in JavaScript from a Maven build.
One reason might be that Maven manages a complex build life-cycle in your project and you need a close integration for your JavaScript tests, another one might be that you’re in an environment where it is complicated to install and manage additional software like an integration- or build-server.

(more…)

Using Apache Avro with Java and Maven

Saturday, March 8th, 2014

Apache Avro is a serialization framework similar to Google’s Protocol Buffers or Apache Thrift and offering features like rich data structures, a compact binary format, simple integration with dynamic languages and more.

In the following short five minute tutorial, we’re going to specify a schema to serialize books in a JSON format, we’re using the Avro Maven plugin to generate the stub classes and finally we’re serializing the data into a single file.

(more…)

Writing Java Integration Tests for MongoDB

Wednesday, October 16th, 2013

MongoDB is matured, document-oriented, cross-platform NoSQL database system with drivers available for a bunch of different programming languages.

In the following short examples I’m going to write some integration tests for MongoDB using the MongoDB Java driver and the Flapdoodle library to create an embedded MongoDB instance for testing.

We’re going to write tests for a simple persist-and-query scenarion and for a map-reduce function and in addition I’m going to show how to bind the start and stop of a MongoDB  instance to a Maven goal using the embedmongo-maven-plugin.

(more…)

Filtering Source Files using the Templating Maven Plugin

Tuesday, September 3rd, 2013

The Templating Maven Plugin looks useful if one needs to copy and to filter source files in a project e.g. to add property values from the build environment to a class.

For a short demonstration I’ve added the following short snippet.

(more…)

Continuous Deployment using GlassFish, Jenkins, Maven and Git

Wednesday, May 29th, 2013

Recently I needed a quick solution to deploy a Java EE 6 web application on a GlassFish instance automatically and subsequent to a successful build of the project on the integration server.

It took only a few steps using Jenkins, Maven and the Cargo plugin and I’d like to share this quick solution with you here.

(more…)

Creating slim Database Projections using JPA2 Constructor Expressions

Sunday, April 14th, 2013

One common question that you may encounter one day when using object-relational-mapping in your application is how to slim down data that you’re retrieving from the persistence layer down to a specific subset for your use-case in an efficient manner and without using complex additional mapping frameworks. In some situations you might declare lazy loaded fields but another approach that I’d like to share with you here are JPA2 constructor expressions.

Constructor expressions allow us to create plain old java objects from the result of an JPA query. The advantage is that we may use different projections for different scenarios and without being managed, the POJOs might help us save some resources here.

In the following tutorial, we’re going to persist 100 book entities with multiple properties to an embedded database and we’re using constructor expressions afterwards to create smaller POJOs using a subset of the information available from each persisted book.

(more…)

Micro Benchmarking your Tests using JUnit and JUnitBenchmarks

Sunday, March 10th, 2013

I recently stumbled upon a nice framework that allows to convert simple JUnit tests into micro benchmarks named JUnitBenchmarks.

It allows to set basic benchmark options and and to generate charts by adding some simple annotations and a test rule to your tests.

One might argue if it is wise to mix the aspects, testing and benchmarking and I’d agree for sure – nevertheless I think this framework can be handy sometimes so let’s create some benchmarks using JUnit and JUnitBenchmarks..

(more…)

Running categorized Tests using JUnit, Maven and Annotated-Test Suites

Thursday, December 6th, 2012

Sometimes we need to classify the tests in a project and a possible solution to achieve this goal is to assign different categories to the tests.

Often we’re doing this to separate the execution of fast-running and long-running tests or to run a specific set of tests that is only applicable in special situations.

To run a specific set of categorized tests there are different options and in the following tutorial we’ll be covering two of them: by configuring the Maven Surefire Plug-in or by using a JUnit Test Suite and the JUnit annotations.

(more…)

Content Detection, Metadata and Content Extraction with Apache Tika

Sunday, December 2nd, 2012

Encountering the situation that you want to extract meta-data or content from a file – might it be an office document, a spreadsheet or even a mp3 or an image – or you’d like to detect the content type for a given file then Apache Tika might be a helpful tool for you.

Apache Tika supports a variety of document formats and has a nice, extendable parser and detection API with a lot of built-in parsers available.

(more…)

New features in JUnit 4.11

Sunday, November 18th, 2012

JUnit is one of the most popular testing frameworks out there. Version 4.11 has just been released and offers some nice improvements that you shouldn’t miss.

(more…)

Lucene Snippets: Faceting Search

Tuesday, August 28th, 2012

The latest snippet from my Lucene examples demonstrates how to achieve a facet search using the Lucene 4.0 API and how easy it is to define multiple category paths to aggregate search results for different possible facets.

In the following example we’re indexing some books as a classical example and create multiple category paths for author, publication date and category afterwards ..

(more…)

Creating a Windows Executable from a Jar using Maven

Tuesday, August 7th, 2012

Often in the life of a developer there is the need to create a windows executable for a Java application that is build and packaged in a Jar file.

The following short example shows how to create an executable Jar first and a windows executable containing vendor information, a nice icon and other stuff afterwards by using a combination of the Maven Shade Plugin and the launch4j Plugin for Maven.

(more…)

Integration Testing IMAP, SMTP and POP3 with GreenMail

Tuesday, July 31st, 2012

Having written some e-mail handling, sending or receiving library you’d like to run some integration tests against a real mail server?

Then GreenMail might help you out here .. the framework is not quite new on the market but it is really easy to setup IMAP,SMTP or POP3 services with it and it comes with some helpful libraries making your life a bit easier here.

That’s why I’ve come to the idea to share some examples for setting up different server instances, creating user accounts and – at last – fetching and validating e-mails…

(more…)

Aspects of Functional Programming in Java

Monday, July 16th, 2012

Functional programming is a trending topic these days and a lot of Java programmers are hot for the features that modern functional programming languages might offer.

Waiting for Java 8 and native closure support is a nice thing but for now we’re going to take a look at several Java frameworks that are trying to implement typical structures from those functional languages where possible using the capabilities of the Java language to emulate elements like higher-order-functions, closures, options and others …

(more…)

Task Scheduling in Java EE 6 on GlassFish using the Timer Service

Friday, June 22nd, 2012

Creating cronjobs or scheduled service executions is made really easy in Java EE 6. Scheduled tasks may be created in a programmatical style or simply by adding some annotations to an EJB.

In the following tutorial we’re creating some simple scheduled tasks and let them run on an embedded GlassFish instance using the Maven Embedded GlassFish plugin..

(more…)

Creating updatable Java Applications using Getdown and the Getdown Maven Plugin

Sunday, May 27th, 2012

Many programmers have suffered when trying to setup an environment to handle updates for their application without much effort. Some tried Java Web Start for this purpose and many encountered difficulties with this approach.

Now there is getdown that aims to replace Java Web Start by offering a simple architecture to handle updates that is fast, realiable and the only thing you need is a normal http server. Though getdown lets us handle our updates really easy it is possible to make this process even easier with the getdown maven plugin.

In the following example we’re building a simple swing application to be installed, updated and launched using getdown.

(more…)

Compiling CoffeeScript with Maven

Friday, May 18th, 2012

CoffeeScript is a neat language that is transcompiled into JavaScript but is more predictable and allows to write the same code with 1/3 fewer lines and of course with a (imho) nicer syntax.

CoffeeScript is nice but a vivid integration into our application build lifecycle with Maven is better  and that is what the following example is all about.

(more…)

Wiring made easy using OSGi Blueprint and Apache Karaf

Monday, April 16th, 2012

The OSGi Blueprint Container specification allows us to use dependency injection in our OSGi environment, declarative import and export of OSGi services, registering lifecycle listeners and wiring dependencies into our services with a few lines of XML code.
In the following tutorial we’re first building an OSGi bundle classical style and afterwards take a trip into the advantages of the Blueprint specification.

Our OSGi container of choice here will be Apache Karaf a lightweight container with a lot of nice features and – of course – blueprint enabled…

(more…)

Snippet: Mixing Scala, Java in a Maven Project

Friday, March 23rd, 2012

Having just returned from the Atlassian Camp 2012 I just toyed around with Java and Scala and wanted to share the following snippet that demonstrates how to mix code from both languages in a Maven project using the maven-scala-plugin.

(more…)

Selenium WebDriver, Selenium Server and PageObjects by Example

Tuesday, March 6th, 2012

A lot has changed since Selenium RC and WebDriver has given us a new syntax to write tests for our web pages. PageObjects add an abstraction to the pages under test and finally we’re able to programatically start Selenium server instances and use them to run the tests.

In the following tutorial, we’re writing some tests using PageObjects, WebDriver, Selenium Server and finally we’re even taking some screenshots of our tested web pages..

(more…)

Create Mobile Websites using Java Server Faces and PrimeFaces Mobile

Sunday, January 8th, 2012

The more smartphones and tablets are sold the bigger the need for a mobile version of a modern website. PrimeFaces Mobile helps us developers here  and allows us to quickly create mobile websites that display well on an iPhone, Android, Palm, Blackberry, Windows Mobile and others.

In the following tutorial we’re going to create a web application that is using Java Server Faces 2.1, PrimeFaces 3.1 and PrimeFaces Mobile 1.0 and runs on a simple web container like Tomcat or Jetty.

(more…)

Maven Tomcat Plugin: Adding Authentication to an Embedded Tomcat

Wednesday, October 12th, 2011

The Tomcat Maven Plugin not only allows us to deploy our mavenized application to an existing Tomcat server but also to run our web application with an embedded instance from our project’s directory. Recently I needed to add basic authentication to such an instance and wanted to share the steps necessary here

(more…)

Java EE 6 Development using the Maven Embedded GlassFish Plugin

Tuesday, September 20th, 2011

Today we’re going to take a look at the Maven Embedded GlassFish Plugin and how it allows us quick creation of GlassFish server instances in no time and Java EE 6 application deployment.

With a few lines of configuration in your Maven’s pom.xml we’ve got a running GlassFish instance and are able to  redeploy our application fast by pressing enter in our console.

In the following tutorial we’re going to build a Java EE 6 Web Application with a stateless session bean and a web servlet and finally deploy – and redeploy the application using the Maven GlassFish Plugin.

(more…)

Screenscraping made easy using jsoup and Maven

Tuesday, August 30th, 2011

Sometimes in a developer’s life there is no clean API available to gather information from a web application .. no SOAP, no XML-RPC and no REST .. just a website hiding the information we’re looking for somewhere in its DOM hierarchy – so the only solution is screenscraping.

Screenscraping always leaves me with a bad feeling – but luckily there is a tool that makes this job at least a bit easier for a developer .. jsoup to the rescue!

(more…)

Contract-First Web-Services using JAX-WS, JAX-B, Maven and Eclipse

Tuesday, August 23rd, 2011

Using the contract-first approach to define a web service offers some advantages in contrast to the code-first approach.

In the following tutorial we’re going to take a look at some details of this approach and we’re going to implement a real SOAP service using JAX-WS, Maven and the Eclipse IDE.

Finally we’re going to run our service implementation on an embedded Jetty instance and we’re going to take a look at soapUI and how to test our service using this neat tool.

(more…)

Integrating Groovy in your Maven builds using GMaven

Tuesday, July 12th, 2011

Often ant tasks are used in Maven builds but wouldn’t it be more attractive to integrate the Groovy language into our build process?

GMaven is the answers to this problem and brings together Maven and Groovy. It allows us to execute Groovy scripts inline from our Maven configuration, from a local script or even from a remote location. In the following short examples I am going to show how to configure Maven to execute Groovy scripts from different locations.

(more…)

Creating a sample Java EE 6 Blog Application with JPA, EJB, CDI, JSF and Primefaces on GlassFish

Tuesday, February 8th, 2011

Java EE 6 is out and it indeed offers an interesting stack of technologies. So in today’s tutorial we are going to build a small sample web application that builds on this stack using Enterprise JavaBeans, Java Persistence API, Bean Validation, CDI and finally Java Server Faces and PrimeFaces.

The application we’re going to develop is a simple blog app that allows us to create new articles, list them and – finally delete them. We’re also covering some additional topics like JSF navigation, i18n, Ajax-enabled components and the deployment on the GlassFish application server.
(more…)

Enterprise Java Bean / EJB 3.1 Testing using Maven and embedded Glassfish

Saturday, January 1st, 2011

Are you playing around with the shiny new 3.1 EJB API?

Using Maven for your Java projects?

Need an easy way to write and execute tests for your EJBs that depends on an Java Application Server?

No problem using Maven Archetypes, the Maven EJB Plugin and the GlassFish embedded Application Container..

(more…)

Creating a REST Client Step-by-Step using JAX-RS, JAX-B and Jersey

Thursday, November 25th, 2010

Often in a developer’s life there is a REST service to deal with and nowadays one wants a fast and clean solution to create a client for such a service.

The following tutorial shows a quick approach using JAX-RS with its reference implementation, Jersey in combination with JAX-B for annotation driven marshalling between XML or JSON structures and our Java-Beans.

(more…)

How to create a simple Messaging Application using RabbitMQ 2 and Maven

Sunday, September 5th, 2010

Having read an interesting comparison by Lindenlabs evaluating modern message broker systems like ActiveMQ, ApacheQpid and amongst others – RabbitMQ – I wanted to take a quick look at the last one and built a small application producing and consuming some sample messages.

If you need some lecture on getting started with RabbitMQ or the key concepts of messaging I strongly recommend reading this list of introductional articles from the RabbitMQ homepage.

(more…)

Spring 3, Maven and Annotation Based Configuration

Sunday, August 22nd, 2010

There is still the urban myth that using Spring IoC container without thousands lines of XML code isn’t possible – so today we’re taking a look at annotation based configuration with Spring 3 and of course we’re using Maven..

(more…)

How to create a simple OSGi Web Application using Maven

Sunday, July 25th, 2010

In this tutorial we will take a look at the development of a simple OSGi Web Application and what tools can save us some time.

The Maven Bundle Plugin makes our life much easier here as does the OSGi Bundle Repository that offers some nice bundles – in our case the servlet API and an embedded Jetty web server.

So lets develop some bundles ..

(more…)

How to create a Template Bundle Plugin in Confluence

Monday, July 12th, 2010

Since Confluence 3.2. there is a new plugin module type that allows you to deploy templates in a bundle via the plugin API.

In addition it is possible to assign these templates to specific spaces and preview available templates in the Confluence administration area.

So let’s build some sample templates..

(more…)

A look at Google’s Protocol Buffers

Tuesday, July 6th, 2010
Protocol Buffers are a serialization format developed by Google- you might ask if another IDL is really needed here – is Google barking at the wrong tree?
But protocol buffers offer some advantages over data serialization via XML or JSON – Google says they (compared to XML)..
  • are 3 to 10 times smaller
  • are 20 to 100 times faster
  • provide generated data access classes for programmatic use
  • provide backward compatibility
So lets play around a little with protocol buffers in Java and build a small application that serializes and deserializes some data using a defined format..

Java Server Faces/JSF 2 Tutorial – Step 1: Project setup, Maven and the first Facelet

Saturday, June 5th, 2010

In this short tutorial we are going to build a Java Server Faces Web-Application using JSF2.0, Facelets, Maven and Hibernate as ORM Mapper.

The goals for this first step are: Setting up the project structure using Maven, defining a frame template/decorator and a registration facelet, creating a managed bean and mapping it’s values to the facelet, adding some basic validation, displaying validation errors and finally adding a navigation structure.

In step2 of this tutorial we are going to add persistence using Hibernate, add some security, create a custom UI component and add some AJAX.

The Mojarra JSF implementation is used for this tutorial – perhaps I’m going to post more about the MyFaces implementation in another tutorial.

(more…)

Extending the Confluence Search Index

Sunday, May 23rd, 2010

Developing plugins for the Confluence Wiki a developer sometimes needs to save additional metadata to a page object using Bandana or the ContentPropertyManager. Wouldn’t it be nice if this metadata was available in the built-in Lucene index?

That is were the Confluence Extractor Module comes into play..

(more…)

Signing APK with the Maven-Jar-Signer Plugin

Saturday, April 17th, 2010

There is a nice Maven plugin helping you signing your Android app – the Maven Jar Signer Plugin. If you want to learn more about Maven integration in an android project take a look at this article. (more…)

Coding Katas with Maven

Thursday, April 15th, 2010

Searching for nice coding kata sites I found this one – codingkata.org – I really liked because of the quick start and nice maven integration.

Just head over to the kata overview select the kata you wish to try out, copy the generated maven command line option and run it in the console – heres the code for the hello-world sample: (more…)

How to build a Confluence Macro Plugin

Tuesday, April 13th, 2010

The goal is to build a small macro plugin deployable via the Confluence plugin API rendering some spaces.

Please note that I am going to build the plugin using just Maven and not the Atlassian Maven Wrapper called the “Atlassian Plugin SDK” – more information about that is available at the Atlassian website.

The macro output will be rendered using a Velocity template and all messages are stored for i18n in properties files bundled with the plugin.

If you need to set up an instance of Confluence first, head over to this article. (more…)

Create a SOAP client using the JAX-WS Maven Plugin

Thursday, April 8th, 2010

Having written the article “How to build a Confluence SOAP client in 5 minutes” some readers asked me for some more information and help using the  JAX-WS plugin that I mentioned in the article instead of the Axis plugin – so here we go ;) (more…)

Manage dependencies with the Maven Dependency Plugin

Sunday, April 4th, 2010

In a maven project there are lots of dependencies to handle – often one wants to know which version of a software comes from.

The solution to this problem is the Maven Dependency Plugin which helps you to find used/unused/declared/undeclared dependencies in your project.

In addition the plugin allows you to copy or unpack artifacts. (more…)

Snippet: Simple One-Minute IMAP Client

Saturday, April 3rd, 2010

Building a simple IMAP Client that displays the subject of the messages in the “inbox” Folder using Maven (I just like Maven). (more…)

How to integrate Android Development Tools and Maven

Friday, April 2nd, 2010

With the Maven Android Plugin it is possible to build and deploy/undeploy your android app and start/stop the emulator – if you’re used to maven you won’t be going without it ;)

If you’re interested in signing your apk using maven – take a look at this article. (more…)

How to build a Confluence SOAP client in 5 minutes

Sunday, March 28th, 2010

In this tutorial we are going to build a SOAP client for the popular Confluence Wiki in about five minutes. The client is going to receive rendered HTML Markup from a specified Confluence Page.
(more…)

How to build a quick lucene search

Thursday, March 25th, 2010

Helo – today I wanted to post a small tutorial for a small index and search operation using the Lucene indexer and Maven for the project setup. (more…)

Dependency management in Grails 1.2

Tuesday, March 23rd, 2010

Sometimes I get the impression that there are many Maven haters in the Groovy/Grails community – now with version 1.2 of the Grails framework they are able to abandon the evil satanic Grails Maven Plugin and embrace the neverending joys of a slim, nice, sexy dependency resolution dsl .. here we go .. lets define some dependencies wheee … (more…)

A look at Maven 3 alpha

Monday, March 22nd, 2010

We are all waiting for a stable release of Maven3 with following updates ..

  • faster, more performant .. save us time building our software and some precious memory ;)
  • improved artifact resolution api and plugin api
  • better osgi integration
  • a few bugfixes
  • no mixing of application dependencies and tooling dependencies
  • though it does not matter that much to me: polyglot features .. e.g.: “Writing your pom files in Groovy”
  • version-less parent elements for multi-module or multi-pom projects, no need to define the parent version in every submodule
  • better artifact resolution, which dependency or pom supplied which artifact to the outcome .. got that information from: “Splitter from the world of Java”

(more…)

How to add a local lib directory to Maven

Thursday, March 18th, 2010
Sometimes there is a dependency not available at a remote repository and one is too lazy to set up a local maven repository – that’s when one adds a directory in the project structure and wants maven to find dependencies there. (more…)
Search
Categories