Archive for the ‘Java’ Category

Using a Maven profile to run a test program

Tuesday, August 25th, 2009

This is a new (to me) trick for my programming toolbox. I discovered (copied) it from the Apache CXF project. (I don’t know if they originated it or not.) Basically, you can use a Maven profile configuration in your pom.xml to easily run a test program in your project that has a public static void main(String[] args) method. I discovered this technique reading the README.txt of the Apache CXF sample “java_first_jaxws“. Here is what the Maven command looks like:

mvn -Pserver

Here is what the profile configuration in the pom.xml looks like:

...
<profiles>
  <profile>
    <id>server</id>
    <build>
      <defaultGoal>test</defaultGoal>
      <plugins>
        <plugin>
          <groupId>org.codehaus.mojo</groupId>
          <artifactId>exec-maven-plugin</artifactId>
          <executions>
            <execution>
              <phase>test</phase>
              <goals>
                <goal>java</goal>
              </goals>
              <configuration>
                <mainClass>demo.hw.server.Server</mainClass>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </build>
  </profile>
...
</profiles>
...

When the “mvn -Pserver” command is executed, the exec-maven-plugin will run the demo.hw.server.Server class. The id identifies the profile id used in the mvn command after the “-p“. The mainClass element defines the class with the main method to execute. The exec-maven-plugin does all of the hard work. One of the benefits of this technique is the standard Maven classpath for the project defined in the pom to build and unit test your software is used to run the mainClass. This comes in quite handy if your program uses many jar files. I used to use a Windows batch file (copied from the Tomcat startup script catalina.bat) to run little test programs. This Maven profile technique is much easier to use for me, since I use Maven for most all of my Java development.

Hello, Android

Sunday, July 13th, 2008

So, July 11, 2008, came and went. What happened on July 11? The iPhone 3G came out.

But I don’t have an iPhone. The other big thing is that the Apple iPhone App Store opened. But I don’t have a Mac, so I can’t run the emulator or create my own apps for the emulator.

So, I celebrated by creating my first Android app.

Hello, Android

This is the “Hello, World” version of an Android app running in the emulator. It was very easy to make. What made it easier for me is that Android apps are written in Java. (I am a Java developer by day.) The “Getting Started” tutorial even shows you how to use Eclipse.

I have only created the sample app so far, but it looks pretty easy for a Java developer to write an “Activity“. But, of coarse, the apps currently can only run in the emulator. But the emulator can be integrated very easily into Eclipse.

Though, it is not like having real hardware like the Apple iPhone. 🙂

X10 API source code

Tuesday, May 29th, 2007

Many years ago, I created an API for interacting with the home automation technology called X10. The API interfaced with power line modules via a serial interface. I haven’t done anything with the X10 home automation API that I created a couple years ago. I have gotten a bit sidetracked by fatherhood. 🙂

You can find the source code here. If you do try to compile this, you may get an error about a missing class. This isn’t important; you can whack away the reference and compile again. (Not very helpful, I know, but if I get more time, I may update this with some more information.)