Using Google Closure Compiler with Maven Web Application


References

Project Structure

.
|-- pom.xml
`-- src
    `-- main
        |-- java
        |-- resources
        |-- webapp
        |   |-- WEB-INF
        |   |   `-- web.xml
        |   |-- index.jsp
        |   `-- my-app
        |       |-- css
        |       |-- image
        |       `-- js
        |           |-- properties.js // filtering
        |           `-- my.js
        `-- webresources
            |-- his-app
            |   `-- his.interface.js
            |-- her-app-production
            |   |-- css
            |   |-- images
            |   `-- js
            `-- her-app-staging
                |-- css
                |-- images
                `-- js

Web Resources

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-war-plugin</artifactId>
  <configuration>
    <webResources combine.children="append"> <!-- wow! -->
      <resource>
        <directory>src/main/webapp</directory>
        <filtering>true</filtering>
      </resource>
      <resource>
        <directory>src/main/webresources/his-app</directory>
        <targetPath>his-app</targetPath>
      </resource>
    </webResources>
  </configuration>
</plugin>

Profiling

<profile>
  <id>staging</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <webResources>
            <resource>
              <directory>src/main/webresources/her-app-staging</directory>
              <targetPath>her-app</targetPath>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>
<profile>
  <id>production</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <configuration>
          <webResources>
            <resource>
              <directory>src/main/webresources/her-app-production</directory>
              <targetPath>her-app</targetPath>
            </resource>
          </webResources>
        </configuration>
      </plugin>
    </plugins>
  </build>
</profile>

Closuring

<profile>
  <id>closure</id>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <executions>
          <execution>
            <id>closure-war</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>war</goal>
            </goals>
            <configuration>
              <webXml>${project.basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
              <warSourceIncludes>my-app/js/**/*.js</warSourceIncludes>
            </configuration>
          </execution>
          <execution>
            <id>default-war</id> <!-- !!! overridden !!! -->
            <phase>package</phase>
            <goals>
              <goal>war</goal>
            </goals>
            <configuration>
              <warSourceExcludes>my-app/js/**/*.js</warSourceExcludes>
            </configuration>
          </execution>
        </executions>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-antrun-plugin</artifactId>
        <version>1.7</version>
        <executions>
          <execution>
            <id>closure-compile</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>run</goal>
            </goals>
            <configuration>
              <target>
                <taskdef resource="net/sf/antcontrib/antlib.xml"/>
                <property name="fileset.dir"
                         value="${project.build.directory}/${project.artifactId}/mh-app/js"/>
                <property name="closure.class"
                          value="com.google.javascript.jscomp.CommandLineRunner" />
                <property name="compilation.level" value="SIMPLE"/>
                <echo message="fileset.dir: ${fileset.dir}"/>
                <echo message="closure.class: ${closure.class}"/>
                <echo message="compilation.level: ${compilation.level}"/>
                <for param="file" parallel="false">
                  <path>
                    <fileset dir="${fileset.dir}">
                      <include name="**/*.js"/>
                    </fileset>
                  </path>
                  <sequential>
                    <property name="source" value="@{file}"/>
                    <property name="target" value="@{file}.closured"/>
                    <java classname="${closure.class}" classpathref="maven.plugin.classpath"
                          fork="true" failonerror="true">
                      <arg value="--compilation_level"/>
                      <arg value="${compilation.level}"/>
                      <arg value="--js"/>
                      <arg value="${source}"/>
                      <arg value="--js_output_file"/>
                      <arg value="${target}"/>
                    </java>
                    <echo message="moving ${target} to ${source}"/>
                    <move file="${target}" toFile="${source}"/>
                  </sequential>
                </for>
              </target>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>ant-contrib</groupId>
            <artifactId>ant-contrib</artifactId>
            <version>1.0b3</version>
            <exclusions>
              <exclusion>
                <groupId>ant</groupId>
                <artifactId>ant</artifactId>
              </exclusion>
            </exclusions>
          </dependency>
          <dependency>
            <groupId>org.apache.ant</groupId>
            <artifactId>ant-nodeps</artifactId>
            <version>1.8.1</version>
         </dependency>
          <dependency>
            <groupId>com.google.javascript</groupId>
            <artifactId>closure-compiler</artifactId>
            <version>v20140814</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
</profile>

Build

$ mvn -Pproduction,closure clean package
...
[INFO] --- maven-war-plugin:2.4:war (closure-war) @ hpp-web-client-flash ---
...
[INFO] --- maven-antrun-plugin:1.7:run (closure-compile) @ hpp-web-client-flash ---
...
[INFO] --- maven-war-plugin:2.4:war (default-war) @ hpp-web-client-flash ---
...
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
$ 

find all jar files and print


I thought I need to print some jar files’ entries in my Java ME SDK’s lib directory.

$ zipinfo -1 cldc_1.8.jar
META-INF/
...
java/util/logging/StreamHandler.class
$

Then I tried to store those output to a text file.

$ zipinfo -1 cldc_1.8.jar > cldc_1.8.jar.txt
$ cat cldc_1.8.jar.txt
META-INF/
...
java/util/logging/StreamHandler.class
$

Then I need to change line delimiters for Windows..

$ unix2dos.exe cldc_1.8.jar.txt
unix2dos: converting file cldc_1.8.jar.txt to DOS format...
$

I realized I can do this in one command.

$ zipinfo -1 cldc_1.8.jar | unix2dos > cldc_1.8.jar.txt
$

And, finally, I can print all jar files entries in a command.

$ for j in *.jar;do zipinfo -1 $j | unix2dos > $j.txt;done
$

Xubuntu 창 크기 조절하기


Xubuntu에서 창 크기 줄이고 늘리는 게 영 불편했다. 보통 오른쪽 아랫부분에 마우스를 가져가면 할 수 있을 거라고 생각했지만 위/아래 혹은 왼/오른쪽이 아닌 대각으로 잡히는 부분이 너무 작았다. 뭔가 설정파일을 수정하면 될 듯 해서 찾던 중 그냥 Alt 키를 누르고 마우스 오른쪽 버튼으로 대충 잡아끌면 되는 듯 하다.

Ask Ubuntu.

Changing Ubuntu Server Apt Source Repository


References

Abstract

Ubuntu Server, unlike the Ubuntu Desktop, has no GUI environment with fresh installation.

Backup

$ pwd
/etc/apt
$ ls -l
...
sources.list
...
$ sudo cp sources.list sources.list.bak
$ ls -l
...
source.list
source.list.bak
...
$ 

Check

Let’s take a look at the file.

$ pwd
/etc/apt
$ cat source.list
...
deb-src http://slower.ubuntu.com/ubuntu/ trusty multiverse
...
$

Update

Change all slower.ubuntu.com to faster.ubuntu.com.

$ pwd
/etc/apt
$ sudo vi source.list
$ cat source.list
...
deb-src http://faster.ubuntu.com/ubuntu/ trusty multiverse
...
$ 

Note

Those domain addresses used in above example aren’t real. In my case I changed kr.archive.ubuntu.com to ftp.daum.net.

Installing VirtualBox Guest Additions in Ubuntu Server


Insert the image by selecting the menu item of Devices / Insert Guest Additions CD Image... (Host+D).

Mount the inserted image.

$ sudo mount -t iso9660 -o ro /dev/cdrom /mnt/cdrom

Execute VBoxLinuxAdditions.run file.

$ cd /mnt/cdrom
$ ls -1F
...
VBoxLinuxAdditions.run
...
$ sudo ./VBoxLinuxAdditions.run
...
$

The script may complain about the absence of gcc and make. Install them and run the script again.

$ sudo apt-get -y install gcc make
...
$ sudo ./VBoxLinuxAdditions.sh
...
$

You can unmount the cdrom.

$ sudo umount /media/cdrom
$

You might want to reboot the guest.

$ sudo /sbin/shutdown -r now
$

One of benefits that guest additions offers is sharing folders between the host and the guest.

$ ls -l /media
drwxr-xr-x 2 root root    ____ MMM dd HH:mm cdrom/
drwxrwx--- 1 root vboxsf _____ MMM dd HH:mm sf_shared/
$

You can add yourself to vboxsf group and use them.

$ sudo adduser <yourself> vboxsf
...

You need to logout and login for making the change effects.

$ logout
$

Now you can read/(write) in the shared directory.

$ cd /media/sf_shared/
$ echo test > test.txt
$ cat test.txt
test
$

Installing Apache Maven in Ubuntu


Installing the latest binary

Copy the link of the latest binary at here.

$ cd /opt
$ sudo wget http://.../.../.../apache-maven-x.y.z-bin.tar.gz
$ ls -1F
apache-maven-x.y.z-bin.tar.gz
$ sudo tar -xzf apache-maven-x.y.z-bin.tar.gz
$ ls -1F
apache-maven-x.y.z/
apache-maven-x.y.z-bin.tar.gz
$ sudo ln -s apache-maven-x.y.z apache-maven-latest
$ ls -1F
apache-maven-x.y.z
apache-maven-x.y.z-bin.tar.gz
apache-mavenlatest@
$

Edit /etc/environment and append :/opt/apache-maven-latest/bin to PATH. Note that : character is a path separator.

$ cat /etc/environment
PATH="/../..:/opt/apache-maven-latest/bin"
$ source /etc/environment
$ which mvn
/opt/apache-maven-latest/bin/mvn
$ mvn --version
Apache Maven x.y.z ...
Maven home: /opt/apache-maven-latest
...

Upgrading to a newer version

When you need to upgrade to a newer version. Just extract the newer binary and change the symbolic link’s target with the -f option.

$ cd /opt
$ sudo wget http://.../.../.../apache-maven-9.9.9-bin.tar.gz
$ ls -1F
apache-maven-9.9.9-bin.tar.gz
$ sudo tar -xzf apache-maven-9.9.9-bin.tar.gz
$ ls -1F
apache-maven-9.9.9/
apache-maven-9.9.9.-bin.tar.gz
$ sudo ln -sf apache-maven-9.9.9 apache-maven-latest
$