Showing posts with label maven. Show all posts
Showing posts with label maven. Show all posts

Sunday, April 7, 2013

ClassStalker......hot reload for any java maven app without Jrebel! Yes (save refresh like Play framework or Grails now in vanilla Java)

Credit goes to spring source and vmware. I just wrote some utility code to let any maven app have save refresh changes without full recompiles and incremental builds. And no need for Jrebel! This is much the benefit of Play! and Grails..and of course the other dynamic languages. Here is the link. Read the readme or just dump all files under bin in the root of your project and run the run.sh file https://github.com/asharif/classstalker

Wednesday, October 27, 2010

Continuous integration server with Hudson for Java, .NET and beyond.


Continuous Integration and Automated Build Environment...

We all know it's super awesome and we need to have this practice. The point of this post is simple. How to get hudson (very simple continuous integration server) up and running to checkout (from svn, git, etc) and build your java (maven, ant) or .net (nant) projects at light speed.

First download the hudson.war from http://hudson-ci.org/. You will need jre 1.5+ and ........that's it! No DB no configuration no nothing!!!! Hudson stores your setup under ~/.hudson in xml files but for all practical intents and purposes you don't need to worry about it.

start the embedded jetty by typing the following in your terminal:

java -jar hudson.war

This will start jetty at http://localhost:8080

Go to that URL in your browser. You should see something like this



Now if your using git you need to install the git plugin. Go to the nav bar on the left and then to manage hudson->manage plugins. Here you can install the git plugin (as well as the nant plugin if your working in .net).

Lastly, you create a new job. When you create a new job you can go to configure and fill out the easy to follow GUI form.

That's it!

Tuesday, September 14, 2010

Creating a "Fat Jar" using Maven

UPDATED 11/28/11 to use latest assembly plugin!

A while ago, before I really started playing with maven, I wanted to create a jar that would package up all the libraries it used and be a single entity that I could invoke. So some searches yielded the eclipse plugin "Fat Jar." This was all nice and great but how could one do this without eclipse? Well maven let's you do this rather easily. Check out the pom.xml file below


<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>org.orphanware.mv</groupId>
    <artifactId>mv-session-mgr</artifactId>
    <packaging>jar</packaging>
    <version>1.1</version>
    <name>mv-session-mgr</name>
    <url>http://maven.apache.org</url>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>2.3.2</version>
                <configuration>
                    <fork>true</fork>
                    <executable>/usr/lib/jvm/java-7-openjdk-amd64/bin/javac</executable>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.3.1</version>
                <configuration>
                    <source>1.6</source>
                    <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                  
                </configuration>
                <executions>
                    <execution>
                        <id>assemble-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>            
        </plugins>
    </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.tiger</groupId>
            <artifactId>mvapi</artifactId>
            <version>1.4</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-api</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>org.slf4j</groupId>
            <artifactId>slf4j-log4j12</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
        </dependency>

    </dependencies>
    
    
</project>



Of course the code above is for a project I was working on so don't pay too much attention to the specifics. The part we care about is the:

<plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.2.1</version>
                <configuration>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                  
                </configuration>
                <executions>
                    <execution>
                        <id>assemble-all</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>


That is how it will package it into a jar with what you named the artifact and it will append the descriptorRef to it.

Now you can build it with

mvn package

Thats it!