Pages

Wednesday, April 23, 2014

Building Hello World with Maven

Good evening America, it has recently come to my attention [pop culture ref] that Maven is a popular software project management and comprehension tool for Java-based projects. (Where have I been the last few years?) Maven is based on the concept of a Project Object Model (POM), an XML representation of the project. To get started with Maven, we’ll use our old friend, Hello World, previously covered it in the post Java, Apache Ant and Hello World. In that post, we used Apache Ant, a Java library and command-line tool that can build Java files. The Wikipedia page for Maven describes one of key differences between Maven and Ant as this:
Using Maven, the user provides only configuration for the project, while the configurable plug-ins do the actual work of compiling the project, cleaning target directories, running unit tests, generating API documentation and so on. In general, users should not have to write plugins themselves. Contrast this with Ant and make, in which one writes imperative procedures for doing the aforementioned tasks.
In this post, we'll cover the following:

Task 1: Quick Install of the Java SDK on Different Linux Flavors

(top)

Since Maven depends on the Java SDK being installed, we’ll show examples of quickly getting the Java SDK on three different Linux flavors. We’ll focus on Linux systems, though Maven works for Windows and Mac OS/X as well.

We tried these instructions on the big three cloud providers, with different Linux flavors. We tried Amazon Web Services (AWS) EC2 Instances, Google Compute Instances (GCE), and Azure Linux-Basic Virtual Instances. The cloud providers aren't that interesting for what we are doing here, other than to show that you can do follow this steps  here using any of the providers. But, for completeness, we show the combination of provider and Linux flavor we tried.

GCE, Azure withCen CentOS

sudo yum install java-1.7.0-openjdk java-1.7.0-openjdk-devel
ls -l /usr/lib/jvm/
export JAVA_HOME=/usr/lib/jvm/jre-1.7.0-openjdk.x86_64
java -version

GCE with Debian

sudo apt-get update
sudo apt-get install default-jdk
java -version

AWS, Azure with Ubuntu

sudo add-apt-repository ppa:webupd8team/java
sudo apt-get update
sudo apt-get install oracle-java7-installer
sudo apt-get install oracle-java7-set-default
java -version

Azure with SUSE

These instructions follow the route of downloading the Java JDK as an .rpm (e.g., jdk-8u5-linux-x64.rpm), transferring the .rpm to the SUSE instance, and then installing. You can find the latest version of the Java JDK to use at Java Downloads.

scp jdk-8u5-linux-x64.rpm susu-instance:.      # copy .rpm to the instance
ssh suse-instance                              # log on to the instance
sudo rpm -ivh jdk-8u5-linux-x64.rpm
java -version

Example of Azure Portal and Three Different Linux Instances



Task 2: Quick Install of Maven

(top)

On any of the Linux-based systems we installed the Java SDK on in Task 1, we can now install Maven. Here we'll just give the relevant commands. You should review http://maven.apache.org/download.cgi for details, in particular to change the download URL and determine the latest version.

You must have the Java SDK installed. You can check by running $java –version. If you try to run Maven without Java, you will get an message like "Error: JAVA_HOME is not defined correctly."

curl http://apache.spinellicreations.com/maven/maven-3/3.2.5/binaries/apache-maven-3.2.5-bin.tar.gz | tar xvz -C "$HOME"
export M2_HOME="$HOME"/apache-maven-3.2.5
export M2=$M2_HOME/bin
export PATH=$M2:$PATH
mvn --version


Task 3: Build Hello World with No Dependencies

(top)

  1. Create a directory called hello-world.
    $ mkdir hello-world

  2. In the hello-world directory create subdirectories src/main/java.
    cd hello-world
    mkdir -p src/main/java
    cd src/main/java

  3. In the java directory, create a HelloWorld.java file with this code:
    package com.travelmarx.demos; 
    public class HelloWorld { 
        public static void main(String[] args) { 
            System.out.println("Hello World");
        } 
    }

    You can use the cat command to paste content into a file.

    cat > HelloWorld.java
    ...paste content...
    CTRL + C

  4. In the root directory (hello-world), create a file called pom.xml and put in the following contents:
    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.travelmarx.demos</groupId>
      <artifactId>hello-world</artifactId>
      <version>1</version>
       <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
              <execution>
                <goals>
                  <goal>java</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <mainClass>com.travelmarx.demos.HelloWorld</mainClass>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>

  5. Run the example.
    mvn install
    mvn exec:java
    # or
    mvn -q exec:java
    Note that a target directory was created. It contains the output of the build, including the JAR used to when executing the program.

Task 4: Build Hello World with a Dependency and an Input Argument

(top)

Let's create use a version of HelloWorld.java that has a dependency on log4j, a common logging and tracing API. Also, let make the Java program take an input argument.
All we have to really do for the dependency is declare the right dependency coordinate in the pom.xml file and then we are set to go. You can find coordinates from Maven Repository.
  1. Clean up the previous install (i.e., remove the /target directory). Run this in the root of hello-world.
    mvn clean
  2. Create a new version of the HelloWorld.java file with the following content:
    package com.travelmarx.demos;
    import org.apache.log4j.BasicConfigurator;
    import org.apache.log4j.Logger;
     
    public class HelloWorld {
     public static Logger log = Logger.getLogger(HelloWorld.class);
     public static void main(String[] args) {
      BasicConfigurator.configure();     
          log.debug("hi there from the logger");
          System.out.println("hello world " + args[0]);
     }
    }
  3. Modify the pom.xml file and add the <dependencies> XML node.
    <project>
      <modelVersion>4.0.0</modelVersion>
      <groupId>com.travelmarx.demos</groupId>
      <artifactId>hello-world</artifactId>
      <version>1</version>
      <dependencies>
      <dependency>
            <groupId>log4j</groupId>
            <artifactId>log4j</artifactId>
            <version>1.2.16</version>
      </dependency>
      </dependencies>
       <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>exec-maven-plugin</artifactId>
            <version>1.2.1</version>
            <executions>
              <execution>
                <goals>
                  <goal>java</goal>
                </goals>
              </execution>
            </executions>
            <configuration>
              <mainClass>com.travelmarx.demos.HelloWorld</mainClass>
            </configuration>
          </plugin>
        </plugins>
      </build>
    </project>
  4. Compile the project as before but run it slightly differently to take in the the argument.
    mvn install
    mvn exec:java -Dexec.args="test"
    
    You should see something like this in the output:
    [com.travelmarx.demos.HelloWorld.main()] 
    DEBUG com.travelmarx.demos.HelloWorld  - hi there from the logger
    hello world test
    
back to the top

Sunday, April 20, 2014

The Vain Graffiti Wall

The Vain Graffiti WallThe Vain Graffiti WallThe Vain Graffiti Wall
Location
: Vain Salon, 2018 1st Avenue
By: DVS graffiti crew (currently)
Description: This wall has a long history in Seattle. The Vain Salon was formerly the Vogue nightclub. The wall was done by the DVS graffiti crew. Read more here on the Vain blog: The Vain Graffiti Wall: A Brief History. This commentary on graffiti, Seattle's secretive graffiti world steps out of the shadows, describes the wall thusly:

The DVS pieces evoke the early styles of New York City’s subway artists (circa 1980s). Intricate lettering styles connect, overlap, flow into each other. Flourishes like arrows, spikes and cartoonish characters are common. This classic, old-school style is the foundation for every thing graffiti has become today.

The Vain Graffiti WallThe Vain Graffiti WallThe Vain Graffiti WallThe Vain Graffiti Wall

Saturday, April 19, 2014

Mountain View – Snails and Rapeseed

Left: Snail Crossing Vista Slope Trail; Center: Deborah Butterfield Horse with Rapeseed; Right: Milk Snail Shell
Snail Crossing Vista Slope TrailDeborah Butterfield Horse with RapeseedMilk Snail Shell
When in Mountain View, I look forward to my early-morning ride on a bright yellow G-Bike. My normal route takes me heading east along Amphitheatre Pkwy, skirting the south edge of Vista Slope. Before 8:00 am, the tech world is asleep, but not the numerous Otala lactea (milk snail) crossing the trail. They seem to be hurrying to take cover for the day, after a night of slimy adventures. I try to swerve out the way, but every now and then there is “crunch” signaling that another snail just passed on to the big gastropod in the sky.

Toward the end of the route, I pass by the Deborah Butterfield horse on Crittenden Lane. During a week in mid-April when I'm there, there are drifts of yellow Brassica napus (rapeseed, rape), echoing the color of the bike I ride. The Rape of Crittenden [ref]?

Left: Rapeseed Flowers and Leaf; Center: Deborah Butterfield Horse with Rapeseed; Right: Snail Hanging on to Rapeseed Flower Stalk
Rapeseed Flowers and LeafDeborah Butterfield Horse with RapeseedSnail Hanging on to Rapeseed Flower Stalk

Left: The Famous Google GBikes in Front of Building 1900/2000; Right: Close-up of Blue GBike Chain
The Famous Google GBikes in Front of Building 1900/2000Close-up of GBike Chain and it’s Blue

Shapes: Deborah Butterfield Cast Bronze Horse (left); Black-Tailed Jack Rabbit (Lepus californicus) and the Twin Peaks of the Shoreline Ampitheatre (center); Twin Milk Snail Shells (right)
Deborah Butterfield Cast Bronze HorseBlack-Tailed Jack Rabbit and the Twin Peaks of the Shoreline Ampitheatre Twin Milk Snail Shells

Milk Snail Research: The Snail I Barely Missed and the “Killing Machine” (GBike) (left and center) and the Vista Slope Snail Dodge in the Early Morning (right)
The Snail I Barely MissedThe Snail I Barely Missed and the “Killing Machine” (GBike)Vista Slope Snail Dodge

Panorama View from Knoll on Crittenden Lane. Far left is approximately due north.Panorama View from Knoll on Crittenden Lane. Far left is approximately due north.

Panorama View from Vista Slope. Far left is approximately due east.
Panorama View from Vista Slope. Far left is approximately due east.

Monday, April 14, 2014

Fremont Sunday Murals

We went down to the Fremont Sunday Market intent on having some fish and chips from the nosh food truck. (And, we weren’t disappointed.) After noshing, we strolled around the neighborhood, specifically between N Canal Street and N 36th Street (east-west) between 1st Ave NW and Phinney Ave N (north-south). We found the following murals, graffiti, and art:

Location: Alley between N 35th and N 36 th Street. Behind Cast Architecture.
By: Unknown.
Description: Spruced up garage door (“612”) and garage wall. Likely the same artist. These are two nearby garages.
Garage - MuralGarage - MuralGarage - MuralGarage - Mural

Location: Alley between N 35th and N 36 th Street. Behind Woodsky’s.
By: Unknown.
Description: What or who is Lalloo?
Lalloo

Location: Fremont Distillery, 132 North Canal Street, above stage.
By: Jill Carter
Description
: Above stage area, a view of Seattle, with couple in a boat with wings. Entrance gate, old timey lettering and girl in the moon.
Fremont Distillery MuralFremont Distillery MuralFremont Distillery Mural

Location: The Indoor Sun Shoppe, 160 North Canal Street
By: Unknown
Description: A native stares out from the wall.
The Indoor Sun Shoppe MuralThe Indoor Sun Shoppe MuralThe Indoor Sun Shoppe MuralThe Indoor Sun Shoppe Mural

Mural Van?
Mural Van

Sunday, April 6, 2014

Fire Hydrant and Wicker Rocker

Wicker Rocker - Yellow Fire Hydrant
Must be spring cleaning. This time in the outdoor furniture category, a wicker rocker by a yellow fire hydrant. Good luck wicker rocker in finding a new home.

Writing this, I started to wonder why yellow for this fire hydrant and red and green for others - at least I thought those were colors I saw in the past. Some color standards have been proposed (for example, see Designing Water and Hydrant Systems) so that the color of the different parts of a fire hydrant (body, bonnet, and caps) can help firefighters quickly tell what kind of water it is (e.g., municipal or private) and the type of flow (gallons per minute) they can expect if they hook up. In this case, it's not clear if the bright yellow here is just a easily identifiable color or part of a standard.  And, I have no idea what wicker by a fire hydrant means.

Thursday, April 3, 2014

Curbside Couch

abandoned couch fremontAnother piece of discarded furniture, waiting by the curb in Fremont. Perhaps a thought bubble above it would read: “what did I do wrong?” Meanwhile, a new PB couch sits sits smugly where the discarded couch once did.