The Power of Central Banks

In Europe, the transformation in the sovereign debt market since Mario Draghi’s “whatever it takes” promise in July 2012 has been remarkable.  Ireland, which just exited an IMF bailout program in December, can now issue 5-year debt at yields well below 5-year Treasuries.

PIMCO Secular Outlook, May 2014 – The New Neutral

Put all Maven dependency versions in properties

Because security vulnerabilities in third-party software are so common, it is important to manage the versions of your dependencies and to be prepared to upgrade them quickly. For Maven projects, I recommend putting the versions of all your dependencies in the properties section of your pom.xml. Furthermore, for libraries which require multiple dependency entries in pom.xml, this allows you to ensure you use the same version for all of those dependencies.

For example:

<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">
  <properties>
    <spring.version>3.2.6.RELEASE</spring.version>
    <jackson.version>2.2.3</jackson.version>
  </properties>
  <dependencies>
    <!-- spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-core</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- Jackson -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-core</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-annotations</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>
  </dependencies>
</project>

Publishing a Java Servlet to Azure Website Using Maven

Azurelogo

This blog post shows how to publish a Java Servlet, encapsulated in a WAR file, to an Azure Web Site using FTP via Maven.

The first step will be to generate a simple servlet using Maven:

mvn archetype:generate -DgroupId=info.deez -DartifactId=hello-world -DarchetypeArtifactId=maven-archetype-webapp

This creates a simple, Hello World application in the hello-world directory. We can verify it works by running it in a local servlet container using the instructions found in Supporting mvn jetty:run in Maven applications. Add the Jetty maven plugin to pom.xml under the build section:

<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">
  <build>
    <plugins>
      <plugin>
        <groupId>org.eclipse.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>9.2.0.M0</version>
      </plugin>
    </plugins>
  </build>
</project>

You can now run the application in Jetty using mvn jetty:run and visit http://localhost:8080 to ensure it works. Next, you can use mvn package to generate the WAR file target/hello-world.war.

Now let’s switch to the Microsoft Azure Portal to create a Web Site and configure it to run Java applications:

  1. Click New: Website.
  2. Give the website a name (I’ll use hello-world) and then click Create.
  3. Open the website and click Site settings (in the lower left-hand corner).
  4. For Java version, change the setting from OFF to 1.7.0_51.
  5. In Web Container, choose your preferred servlet container (I use Tomcat).
  6. Click Save.

Your Java website is now running at http://hello-world.azurewebsites.net. You can upload WAR files via FTP to the directory /site/wwwroot/webapps and they will become available as part of your site.

Next, set up your website for deployment:

  1. Open the website in the Azure Portal.
  2. Click Set deployment credentials.
  3. Create a deployment username (I’ll use deployme) and password and click Save. Write down the username and password
  4. Click Properties
  5. Write down the FTP host name. Mine is ftp://waws-prod-blu-011.ftp.azurewebsites.windows.net. Also note that the FTP/Deployment User has a hello-world prefix (i.e. it is hello-world\deployme)

We’ll now configure Maven to deploy the website by uploading the WAR file when the user uses mvn install.

  1. Set up the deployment username and password for Maven by editing ~/.m2/settings.xml and add the following section:
    <settings xmlns="http://maven.apache.org/SETTINGS/1.0.0"
              xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
              xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.0.0                               http://maven.apache.org/xsd/settings-1.0.0.xsd">
      <servers>
        <server>
          <id>azure-hello-world</id>
          <username>hello-world\deployme</username>
          <password>password</password>
        </server>
      </servers>
    </settings>
    
  2. Add wagon-ftp as a build extension to your pom.xml so we can upload files via FTP:
    <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">
      <build>
        <extensions>
          <extension>
            <groupId>org.apache.maven.wagon</groupId>
            <artifactId>wagon-ftp</artifactId>
            <version>1.0-beta-3</version>
          </extension>
        </extensions>
      </build>
    </project>
    
  3. Add wagon-maven-plugin as a build plugin in your pom.xml and instruct it to upload the WAR via FTP when the user runs mvn install:
    <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">
      <build>
        <plugins>
          <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>wagon-maven-plugin</artifactId>
            <version>1.0-beta-3</version>
            <executions>
              <execution>
                <id>upload-war</id>
                <phase>install</phase>
                <goals>
                  <goal>upload</goal>
                </goals>
                <configuration>
                  <fromDir>${basedir}/target</fromDir>
                  <includes>${project.build.finalName}.war</includes>
                  <url>ftp://waws-prod-blu-011.ftp.azurewebsites.windows.net</url>
                  <toDir>/site/wwwroot/webapps</toDir>
                  <serverId>azure-hello-world</serverId>
                </configuration>
              </execution>
            </executions>
          </plugin>
        </plugins>
      </build>
    </project>
    

You can now deploy your website using mvn install, and visit it at http://hello-world.azurewebsites.net/hello-world.

Supporting mvn jetty:run in Maven applications

jetty-header-logo

When I’m writing a Java servlet using Maven, I find it convenient to be able to run the Java servlet in a local servlet container for testing purposes.  This is very easy to do using the Jetty Maven plugin.

To add the Jetty Maven plugin to your project, modify pom.xml as follows:

<build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.2.0.M0</version>
    </plugin>
  ...
  </plugins>
</build>

You can then run your project in Jetty using the following command:

mvn jetty:run

If you want to run the website from the compiled WAR rather than from the source code, then use the following configuration:

<build>
  <plugins>
    <plugin>
      <groupId>org.eclipse.jetty</groupId>
      <artifactId>jetty-maven-plugin</artifactId>
      <version>9.2.0.M0</version>
      <configuration>
        <war>${basedir}/target/${project.build.finalName}.war</war>
      </configuration>
    </plugin>
  ...
  </plugins>
</build>

Then execute:

mvn jetty:run-war

Using Handbrake to Encode Blu-Rays for the Roku

roku_logo_lThis post is a sibling of my earlier post Using Handbrake to Encode DVDs for the Roku and contains the settings I use for Blu-Ray movies.  The instructions apply to Handbrake 0.9.9.

Once again, start with the High Profile preset and then make the following changes:

  1. In Output Settings:
    1. Set Container = Mp4
    2. Ensure Large File Size is checked
    3. Ensure Web Optimized is checked
    4. Ensure iPod 5G Support is unchecked
  2. In Picture:
    1. Set Anamorphic = Strict (all Blu-Rays I’ve seen are 1920×1080)
    2. Set Cropping = Automatic.
  3. In Filters:
    1. Set Detelecine = Off
    2. Set Decomb = Fast
    3. Set Deinterlace = Off
    4. Set Denoise = Off
    5. Set Deblock = Off
    6. Ensure Grayscale is unchecked
  4. In Video:
    1. Set Video Codec = H.264 (x264)
    2. Set Framerate (FPS) = Same as source
    3. Set Constant Framerate
    4. Set Quality = Constant Quality of RF:20
    5. Set Optimise Video = Use Advanced Tab instead
  5. In Audio:
    1. Create two audio tracks.  The first audio track will have:
      1. Source = AC3 5.1 (which is what you should have ripped from your DVD)
      2. Codec = AAC (faac)
      3. Bitrate = 160
      4. Samplerate = Auto
      5. Mixdown = Stereo
      6. DRC = 1.5
      7. Gain = 0
    2. The second audio track will have:
      1. Source = AC3 5.1
      2. Codec = AC3 Passthru
  6. In Subtitles, keep everything empty.  I do not handle subtitles.
  7. In Chapters:
    1. Ensure Create chapter markers is checked
  8. In Advanced:
    1. In Encoding:
      1. Set Reference Frames = 3 (Default)
      2. Set Maximum B-Frames = 3 (Default)
      3. Ensure CABAC is checked
      4. Ensure 8×8 Transform is checked
      5. Ensure Weighted P-Frames is checked
      6. Set Pyramidal B-Frames = Normal (Default)

    2. In Analysis:
      1. Set Adaptive B-Frames = Optimal
      2. Set Adaptive Direct Mode = Automatic
      3. Set Motion Est Method = Hexagon (Default)
      4. Set Subpixel Motion Est = 7: RD in all frames
      5. Set Motion Est Range to 16
      6. Set Partition Type = Most (Default)
      7. Set Trellis = Encode Only (Default)

    3. In Psychovisual:
      1. Set Adaptive Quant Strength = Middle
      2. Set Rate Distortion = Middle
      3. Set Psychovisual Trellis = Leftmost Setting
      4. Ensure No DCT-Decimate is unchecked
      5. Set Deblocking = 0 (Default), 0 (Default)
    4. In x264 Encoder Options, set it to b-adapt=2:rc-lookahead=50:direct=auto

Using Handbrake to Encode DVDs for the Roku

Update 2014-04-27 10:00 PM: See also Using Handbrake to Encode Blu-Rays for the Roku

In a previous post, I noted that I use ffmpeg to convert DVDs to MP4s which will play on my Roku.  I recently encountered two problems with this approach.  First, the resulting MP4s only include a stereo audio track, so are highly sub-optimal for surround sound systems.  Second, for a yet-undetermined reason, Plex (my current preferred media client) will transcode the videos rather than play them directly.

To solve both problems, I have changed from ffmpeg to Handbrake and I am following the encoding guidance of Rokoding.  Specifically, since most of my source material is DVDs, I use the 480p Original settings.

Just in case the Rokoding site disappears, I have reproduced the 480p DVD Settings below in a slightly modified form.  These instructions apply to Handbrake 0.9.9.

In Handbrake, start with the High Profile preset and then make the following changes:

  1. In Output Settings:
    1. Set Container = Mp4
    2. Ensure Web Optimized is checked
    3. Ensure Large File Size and iPod 5G Support are unchecked
  2. In Picture:
    1. If the movie is widescreen or hard letterboxed, set Anamorphic = Strict.  If the movie is 4:3, set Anamorphic = None and ensure Keep Aspect Ratio is checked.
    2. Set Cropping = Automatic.
  3. In Filters:
    1. Set Detelecine = Off
    2. Set Decomb = Fast
    3. Set Deinterlace = Off
    4. Set Denoise = Off
    5. Set Deblock = Off
    6. Ensure Grayscale is unchecked
  4. In Video:
    1. Set Video Codec = H.264 (x264)
    2. Set Framerate (FPS) = Same as source
    3. Set Constant Framerate
    4. Set Quality = Constant Quality of RF:19
    5. Set Optimise Video = Use Advanced Tab instead
  5. In Audio:
    1. Create two audio tracks.  The first audio track will have:
      1. Source = AC3 5.1 (which is what you should have ripped from your DVD)
      2. Codec = AAC (faac)
      3. Bitrate = 160
      4. Samplerate = Auto
      5. Mixdown = Stereo
      6. DRC = 1.5
      7. Gain = 0
    2. The second audio track will have:
      1. Source = AC3 5.1
      2. Codec = AC3 Passthru
  6. In Subtitles, keep everything empty.  I do not handle subtitles.
  7. In Chapters:
    1. Ensure Create chapter markers is checked
  8. In Advanced:
    1. Set Adaptive B-Frames = Optimal
    2. Set Adaptive Direct Mode = Automatic
    3. In x264 Encoder Options, set it to b-adapt=2:rc-lookahead=50:direct=auto
    4. The rest are as default:
      1. Set Reference Frames = 3 (Default)
      2. Set Maximum B-Frames = 3 (Default)
      3. Ensure CABAC is checked
      4. Ensure 8×8 Transform is checked
      5. Ensure Weighted P-Frames is checked
      6. Set Pyramidal B-Frames = Normal (Default)
      7. Set Motion Est Method = Hexagon (Default)
      8. Set Subpixel Motion Est = 7: RD in all frames
      9. Set Motion Est Range to 16
      10. Set Partition Type = Most (Default)
      11. Set Trellis = Encode Only (Default)
      12. Set Adaptive Quant Strength = Middle
      13. Set Rate Distortion = Middle
      14. Set Psychovisual Trellis = Leftmost Setting
      15. Ensure No DCT-Decimate is unchecked
      16. Set Deblocking = 0 (Default), 0 (Default)