Tuesday, July 7, 2015

Maven-style continuous delivery

Let's say you have a java program.
Also you have a continuous integration server,
that builds java jar file (artifact) and deploys it to artifactory
(or you just use mvn clean compile deploy to upload latest version to artifactory).

Let's say you also have a bunch of hosts that suppose to run the artifact.
How do you deploy (deliver) the artifact to all the hosts?

We'll use maven for that - exec:java goal and dependency management would help a lot.

On target hosts:

1. create file pom.xml (a bit of xml)

    <modelVersion>4.0.0</modelVersion>

    <groupId>my.cool.sw</groupId>
    <artifactId>cool-program</artifactId>
    <version>1.0-SNAPSHOT</version>

    <dependencies>
        <dependency>
            <groupId>my.cool.sw</groupId>
            <artifactId>my-cool-deployed-jar</artifactId>
            <version>1.0-SNAPSHOT</version>
        </dependency>
    </dependencies>
</project>

2. exec 
mvn exec:java -Dexec.mainClass="my.cool.sw.MainClass"


That's it.
  • No need to copy jar file to hosts each time sw is updated and uploaded to artifactory.
  • All the hosts would run latest possible version from artifactory.
  • Easy to automate and to maintain.

Thursday, June 11, 2015

Maven single jar with dependencies

just add the following to pom.xml file

<build>
    <plugins>
      <plugin>
        <artifactId>maven-assembly-plugin</artifactId>
        <configuration>
          <archive>
            <manifest>
              <mainClass>fully.qualified.MainClass</mainClass>
            </manifest>
          </archive>
          <descriptorRefs>
            <descriptorRef>jar-with-dependencies</descriptorRef>
          </descriptorRefs>
        </configuration>
      </plugin>
    </plugins>

  </build>

and you run it with
mvn clean compile assembly:single
Compile goal should be added before assembly:single or otherwise the code on your own project is not included.
See more details in comments.

Commonly this goal is tied to a build phase to execute automatically. This ensures the JAR is built when executing mvn install or performing a deployment/release.

<plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
      <archive>
        <manifest>
          <mainClass>fully.qualified.MainClass</mainClass>
        </manifest>
      </archive>
      <descriptorRefs>
        <descriptorRef>jar-with-dependencies</descriptorRef>
      </descriptorRefs>
    </configuration>
    <executions>
      <execution>
        <id>make-assembly</id>
 <!-- this is used for inheritance merges -->
        <phase>package</phase>
 <!-- bind to the packaging phase -->
        <goals>
          <goal>single</goal>
        </goals>
      </execution>
    </executions>
  </plugin>


src: StackOverflow :-)

Wednesday, June 10, 2015

TextArea scrollbar width in Firefox

To get scroll bar width of text area - use

element.offsetWidth - element.clientWidth

spent an hour fighting with scroll bar....

Friday, April 10, 2015

Java Mission Control - profiling at your hands

Just add this to your java arg line

-XX:+UnlockCommercialFeatures
-XX:+UnlockExperimentalVMOptions
-XX:-UseFastUnorderedTimeStamps
-XX:+FlightRecorder
-XX:StartFlightRecording=duration=120m,filename=recording1.jfr


when java app exits, file recording1.jfr will be available for viewing with Java Mission Control
since JDK 1.7.40