Minimal pom.xml for executable jar

When you develop a stand-alone Java application, Maven can create the executable jar for you, with main-class and classpath manifest entries. You just need the configuration of the maven-jar-plugin shown below.

The sample pom.xml also specifies that we use Java 7 and UTF-8. You can take out the sourceEncoding and maven-compiler-plugin configurations, if you want to go with defaults instead.

<project xmlns="http://maven.apache.org/POM/4.0.0"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <modelVersion>4.0.0</modelVersion>

    <groupId>net.doepner</groupId>
    <artifactId>executable-jar-sample</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.0</version>
                <configuration>
                    <source>1.7</source>
                    <target>1.7</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <mainClass>net.doepner.sample.Main</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
        </plugins>
    </build>

</project>

Here is a matching minimal main class, src/main/java/net/doepner/sample/Main.java:

package net.doepner.sample;

import javax.swing.JOptionPane;

/**
 * The class that has the main method
 */
public class Main {

    public static void main(String[] args) {
        JOptionPane.showMessageDialog(null, "It works!");
    }
}

JRuby on Rails 3.2

I currently have to work on an application using JRuby on Rails 3.2. My background is 12+ years of Java centric web development using Eclipse or IntelliJ.

There are a few things that I love about working with Java in Eclipse or IntelliJ that I miss when working with Rails:

  • Java’s backwards compatibility
  • Java’s cross-platform consistency
  • That Java has a static type system and is a compiled language
  • The relatively rigid syntax of Java that prevents idiosyncratic DSLs
  • Being able to control mutability, extensibility and visibility at compile-time (private, final)
  • Java’s distinction of interfaces vs implementation classes
  • Powerful auto-completion and Refactoring in the IDE
  • Powerful code inspections and quickfixes in the IDE
  • IDE and compiler feedback about mistakes and design flaws in my code
  • The powerful and rich ORM features of JPA and Hibernate

Dynamic language fans might cringe at some of the points listed above. Feel free to provide constructive feedback or well-reasoned criticism.

There are however a couple of things that I like about Ruby on Rails 3.2:

  • Dependency management using gems and bundler
  • A very standardized project layout (directory structure and conventions)
  • Code generation (as a convenient way to quickly create sample code)
  • Out-of the box integration and support for JQuery, CoffeeScript, SASS
  • Cool gems like colorbox-rails for turning a regular view into a modal dialog
  • The asset pipeline

I am still in the early phase of my Rails experience and I will try to post more about it as things evolve.

Version Control for corporate development: Git

What is Git?
http://en.wikipedia.org/wiki/Git_(software)
http://git-scm.com/downloads
http://git-scm.com/download/win

Reference documentation
http://git-scm.com/docs

About Git, compared to alternatives
http://git-scm.com/about

A very useful post on stackoverflow:
Typical problems using Git in corporate environment with solutions

Linus Torvalds’ famous “rant” style presentation about Git vs Subversion:
https://www.youtube.com/watch?v=4XpnKHJAok8

Questions, discussions and answers on stackoverflow.com:
Distributed Version Control Systems and the Enterprise – a Good mix?
Can we finally move to Distributed VCS in Corporate Software?
Git-Based Source Control in the Enterprise
Reasons against using “Git” in the enterprise

Article: “Benefits of Git for business” (from 2008 but still valid):
http://pathfindersoftware.com/2008/08/selling-git-on-the-business-end/

Presentation: “Git for Companies” (Video and Slides, from 2012):
http://2012.con-fess.com/sessions/-/details/169/GIT-for-Companies

Pre-tested commits with git and Jenkins:
http://blog.cloudbees.com/2012/03/dont-phunk-with-my-stable-branch.html

IDE support
http://www.eclipse.org/egit/
http://netbeans.org/kb/docs/ide/git.html
http://www.jetbrains.com/idea/webhelp/using-git-integration.html

Commercial Git Hosting (for no-hassle repo infrastructure)
https://github.com/plans
https://bitbucket.org/plans

Java DSL for object-oriented type-safe CSS styling

I am looking for something like this Java-CSS-Library, to implement server-generated CSS stylesheets backed by a type-safe object-oriented model of CSS classes and rule sets.

This is part of my ongoing quest for the perfect “pure Java” web development framework that would allow me to

  • Focus on my strongest area of expertise: Elegant Java code
  • Use refactorings and other advanced Java tooling in Eclipse or IntelliJ Community Edition
  • Ignore the HTML/HTTP vs JVM objects impedance mismatch as much as possible

Sharing IntelliJ project configuration (.idea, *.iml) in version control

Me and my team do exactly what Christof Schablins describes in this blog post and what the Jetbrains folks recommend here: We use IntelliJ IDEA and share *.iml files (modules) and most files in .idea directory (project config) in the Version Control System (in our case CVS), including shared ant configs, shared run configs for Tomcat 6 and JUnit tests, shared project specific code inspection profile, shared data source definitions, etc.

Overall it works great. But we noticed a few things:

  • Needed an IntelliJ Path variable TOMCAT_HOME because devs have Tomcat installed in different places
  • Dialog “Do you want to add workspace.xml to CVS” keeps popping up (despite an entry in .cvsignore file within the .idea directory)
  • If devs have different sets of IntelliJ plugins enabled, each plugin adds its default code inspection rules to the shared profile (even if the project does not use them, e.g. Ruby stuff in a pure Java project). So developers have to be cautious not to check in those changes (or accept the bloat they cause)

So my question is: Have you come across these or similar issues and did you solve them?

Maven integration (m2e) for Eclipse 3.7.x (Indigo)

Sonatype’s Maven integration for Eclipse (m2e) has been migrated to eclipse.org and is now available from the default update site for Indigo.

This means that you no longer have to add any Sonatype update sites as mentioned on the old (now outdated) m2eclipse site.

In particular, this also means that the old “m2e-extras” update site is obsolete for Eclipse 3.7.x and later. Things like WTP integration or Subclipse integration are now available as “m2e connectors” through Window – Preferences – Maven – Discovery.

All of this is very poorly (or not at all) documented on the new m2e home page and some people had problems with these changes.

Jenkins on minimalistic Debian Virtualbox VM (64bit)

Update 14/Aug/2018: I no longer maintain the package mentioned and the download links below are most likely broken.

A Jenkins build server (LTS release) can now be easily installed on the minimalistic Debian VM:

  1. Download and install Virtualbox
  2. Download debian-stable-amd64-minimal.ova and import it into Virtualbox
  3. Start the “debian-stable-amd64-minimal” VM in Virtualbox
  4. If you are outside Nova Scotia, please review debian-stable-amd64-minimal.txt and adjust locale, timezone and Debian mirror based on your location
  5. Start an ssh session to localhost, port 1111 (using PuTTY, for example)
  6. Log in as user (default password is “user”)
  7. Issue “sudo install.sh jenkins” (default root password is “root”)
  8. Press enter for any questions during installation
  9. Open http://localhost:8888/ in a browser on the host OS for Jenkins web ui

You can go to “Manage Jenkins” – “Configure System” and see that JDK, Ant and Maven entries are already configured for you.

Both OpenJDK 6 and OpenJDK 7 are installed automatically for you in the VM. Please note that openjdk-6 is the Debian stable system default, while openjdk-7 is configured as the default for Jenkins build jobs.

Important: Make sure to change root and user passwords to something secure, as mentioned in debian-stable-amd64-minimal.txt.