SSH To Box with .PEM

ssh-keygen -t rsa -b 2048 -v

Enter a file name for example “work” and accept other defaults. Two files will get generated, work and work.pub.

rename work to work.pem and put in

copy work.pub to the server you want to ssh to and append it to the file ~/.ssh/authorized_keys (create if needed)

edit your local ~/.ssh/config and add the following inserting the ip address and user name appropriately.

Host work
HostName <host ip address>
IdentityFile ~/.ssh/work.pem
User <user name>

Then to connect simply

ssh work

Maven and Android

If you find yourself with a Maven Android project which builds fine from mvn command line but gives errors in eclipse the problem may be this:

After a Maven / Update Project, your Eclipse build compliance is updated to what is found in the pom. Without need for “maven-compiler-plugin”, it uses the oldest level.

In my case, Eclipse wasn’t happy with @Override annotations. This was because it was updating to Java compliance to 1.5 which doesn’t support annotations. The problem was more confusing because it didn’t give the correct error. (It said that my methods were not overriding anything – removing them then gave the error that I needed to override two methods.)

The solution is to put

<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.0</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>

in your plugins section. This will then determine what the “Maven / Update Project” will use to set Eclipse compliance. You will notice both an apk and jar will be build when using the command line mvn.

Maven, Eclipse and Android

To use maven and eclipse with android projects:

You need the Maven Android Plugin (https://code.google.com/p/maven-android-plugin/) for your maven builds.

And the m2e-android plugin (http://rgladwell.github.io/m2e-android/) for eclipse – otherwise you will get a pom error (“Plugin execution not covered by lifecycle configuration”).

Follow the usual steps to convert a project to maven after m2e-androud plug-in is installed (rt click on project / configure / convert to maven). One thing, when following instructions on the m2e-android plugin page for installing the plugin, you will get multiple hits when searching in the marketplace, the one you want is “Android Configurator for M2E”.

Eclipse puts apk in bin/, mvn puts apk in target/

Obviously this could all change and is only correct at time of writing.

Emma reporting in Maven build

How to produce html Emma report automatically with Maven build. Useful for continuous build environments.
First, produce the report using the Emma Maven plugin like so (see http://mojo.codehaus.org/emma-maven-plugin/usage.html):

<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>emma-maven-plugin</artifactId>
	<version>1.0-alpha-3</version>
	<inherited>true</inherited>
	<executions>
		<execution>
			<phase>process-classes</phase>
			<goals>
				<goal>instrument</goal>
			</goals>
		</execution>
	</executions>
</plugin>
<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-surefire-plugin</artifactId>
	<inherited>true</inherited>
	<configuration>
		<forkMode>once</forkMode>
		<reportFormat>txt</reportFormat>
		<classesDirectory>${project.build.directory}/generated-classes/emma/classes</classesDirectory>
		<argLine>-XX:-UseSplitVerifier</argLine>
	</configuration>
</plugin>

Next, use the exec-maven-plugin to process the Emma output into the format you want. This example shows html and txt.

<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>exec-maven-plugin</artifactId>
	<version>1.2.1</version>
	<executions>
		<execution>
			<phase>package</phase>
			<goals>
				<goal>exec</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<executable>java</executable>
		<arguments>
			<argument>-cp</argument>
			<argument>${project.build.directory}/lib/*</argument>
			<argument>emma</argument>
			<argument>report</argument>
			<argument>-r</argument>
			<argument>html,txt</argument>
			<argument>-in</argument>
			<argument>${project.build.directory}/coverage.em,${basedir}/coverage.ec</argument>
		</arguments>
	</configuration>
</plugin>

Note, the phase for this step is set to “package”, which comes after “process-classes” (see http://maven.apache.org/guides/introduction/introduction-to-the-lifecycle.html). Also, this example relies on the fact that I have configured maven-dependency-plugin to include my dependencies in the …/lib directory. Example:

<plugin>
	<groupId>org.apache.maven.plugins</groupId>
	<artifactId>maven-dependency-plugin</artifactId>
	<version>2.6</version>
	<executions>
		<execution>
			<id>copy-dependencies</id>
			<phase>package</phase>
			<goals>
				<goal>copy-dependencies</goal>
			</goals>
			<configuration>
				<outputDirectory>${project.build.directory}/lib</outputDirectory>
				<overWriteReleases>false</overWriteReleases>
				<overWriteSnapshots>false</overWriteSnapshots>
				<overWriteIfNewer>true</overWriteIfNewer>
			</configuration>
		</execution>
	</executions>
</plugin>

With this example, I get my html file in ${project.build.directory}/converage/index.html which I can then specify as a artifact in my continuous build environment (such as Team City) and easily access on any historical build.

Specifying logback configuration when using maven exec:exec

If you don’t want your logback configuration stored in your jar, but you want to be able to execute your java program with the exec-maven-plugin (using mvn exec:exec), you can specify the default logback configuration as follows. More details on logback configuration can be found here: http://logback.qos.ch/manual/configuration.html

<plugin>
	<groupId>org.codehaus.mojo</groupId>
	<artifactId>exec-maven-plugin</artifactId>
	<version>1.2.1</version>
	<executions>
		<execution>
			<goals>
				<goal>exec</goal>
			</goals>
		</execution>
	</executions>
	<configuration>
		<executable>java</executable>
		<arguments>
			<argument>-cp</argument>
			<classpath/>
			<argument>-Dlogback.configurationFile=${basedir}/src/main/resources/logback.xml</argument>
			<argument>com.possemeeg.test.experiment.Program</argument>
		</arguments>
	</configuration>
</plugin>