Tech Blogging‎ > ‎

Developing and Debugging Shopizer in Eclipse with Maven and Jetty

posted Sep 24, 2014, 9:09 PM by Haris Hashim   [ updated Feb 10, 2015, 11:45 PM ]
!!! NOTE 1: This is still a work in progress with lots of sharp edges that cuts and bleed ;) !!!

Note 2: Prerequisite to follow shopizer documentation Build The Application.


Starting Up

This steps are done using Eclipse Luna.

Good to make sure that latest m2e plugin is installed in eclipse.

Git clone of the project give you sm-core and sm-shop folder.

Install AspectJ Development tool (credit to Arjan reply in StackOverflow here). Use the Menu, Help->Install New Software.

Install AspectJ Development Tools


Then install AspectJ Maven connector. Use the Menu, Windows->Preferences. On the preferences windows expand Maven and select Discovery in the tree list on left hand side. After that click Open Catalog button, find AspectJ and put a check mark on it. Click finish to start installation.

Using same step as installing AspectJ Maven connector, but this time install m2e-apt.

The code base actually have 2 sub project. sm-core mentioned above is actually the library part. While sm-shop is web app part that going to be run by jetty.

SM CORE

Import into eclipse as maven project.There is an error in the sm-core pom.xml file for maven-apt-plugin. Modifying maven-apt-plugin version to 1.0.4 make this error go away.

<plugin>
<groupId>com.mysema.maven</groupId>
<artifactId>maven-apt-plugin</artifactId>
<version>1.0.4</version>
        ...
</plugin>

Also add maven-source-plugin to sm-core pom file.

        <plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>

This plugin is for debugging. Without it browsing sm-core sources from sm-shop using eclipse will result to source not found.

Only do the following step if bellow error is encountered in sm-core.pom.

You need to run build with JDK or have tools.jar on the classpath.
If this occures during eclipse build make sure you run eclipse under  JDK as well 
(com.mysema.maven:apt-maven-plugin:1.0.6:process:default:generate-sources)

This StackOverflow page discus the issue. Solution that work for me is by eis that suggest setting -vm option in eclipse.ini to a specific jdk which is described in this StackOverflow page or even better this wiki page.

SM SHOP

Modify sm-shop pom to include jetty-maven-plugin. This is the magic that will allow us to run and debug Shopizer using jetty.

<plugin>
<groupId>org.mortbay.jetty</groupId>
        <artifactId>jetty-maven-plugin</artifactId>
        <version>8.1.15.v20140411</version>
        <configuration>
<scanIntervalSeconds>5</scanIntervalSeconds>
        </configuration>
</plugin>

The scanIntervalSeconds configuration above is for debugging later. This allow java code to be change and debugged without restarting jetty. Functionality called hot swapping.

Test this using mvn jety:run in a terminal/console which result to following errors:

Error:

  • java.lang.NoClassDefFoundError: org/apache/el/ExpressionFactoryImpl
            Adding the following to pom.xml solve the problem as per this link.
   
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper-el</artifactId>
<version>7.0.27</version>
</dependency>
  • Java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE

DEBUG com.mchange.v2.resourcepool.BasicResourcePool: Preparing to destroy resource: com.mchange.v2.c3p0.impl.NewPooledConnection@26e866ca
DEBUG com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool: Preparing to destroy PooledConnection: com.mchange.v2.c3p0.impl.NewPooledConnecti
on@26e866ca
DEBUG com.mchange.v2.c3p0.impl.NewPooledConnection: com.mchange.v2.c3p0.impl.NewPooledConnection@26e866ca closed by a client.
java.lang.Exception: DEBUG -- CLOSE BY CLIENT STACK TRACE

Apparently this is just a log message and are harmless/not a problem and can be ignored. Refer to link.

Navigate to localhost:8080 or localhost:8080/admin and the web app should come up, alive and kicking.

Cleaning Up

This looks cool. Adding properties like variable declaration in script. Conveniently put version definition at beginning of pom.xml file.

        <properties>
                ...
                <tomcat-jasper-el.version>7.0.27</tomcat-jasper-el.version>
<jetty-maven-plugin.version>8.1.15.v20140411</jetty-maven-plugin.version>
</properties>

And changing the version to reflect above properties


        <dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-jasper-el</artifactId>
<version>${tomcat-jasper-el.version}</version>
</dependency>

        ...

        <plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>${jetty-maven-plugin.version}</version>
</plugin>

Run and Debugging

With mvn in system path variable, running the web app in terminal or command prompt is just the matter of executing 

    mvn jetty:run

Running this in eclipse without just a bit of configuration is simplified with the use of m2e and jetty-maven-plugin.

Click on Run Configurations to configure a new run named start.

Run config button

As bellow configuration in the Run Configurations window. Simply add jetty:run as the goal.

Run Configurations

And don't forget to check Debug Output as we need this in debugging step later.

Click Apply and then the Run button to run it.

Or use the Start shortcut automatically added as bellow:

Start shortcut button automatically added

To debug, set a break point 

Set Breakpoint


And use the Start shortcut in Debug as bellow:

Start Debug Shortcut

Navigate to admin page, enter username/password and click Login.

Admin Page


Check the IDE, If everything is OK, program execution will be paused at the set breakpoint. 

Breakpoint Stop



Disqus for Google Sites

The gadget spec URL could not be found






ą
Haris Hashim,
Sep 24, 2014, 9:19 PM
ą
Haris Hashim,
Sep 24, 2014, 9:19 PM
ą
Haris Hashim,
Sep 24, 2014, 9:19 PM
ą
Haris Hashim,
Sep 24, 2014, 9:19 PM
ą
Haris Hashim,
Sep 24, 2014, 9:19 PM
ą
Haris Hashim,
Sep 24, 2014, 9:19 PM
ą
Haris Hashim,
Sep 24, 2014, 9:19 PM
ą
Haris Hashim,
Sep 24, 2014, 9:19 PM
Comments