Run appfuse with Maven

I wanted to refresh my skill in Maven. AppFuse is a very popular open source JavaEE framework built based on Maven hence I use AppFuse as the tool to refresh my Maven skill.

Install the following prerequisite:
1. Install JDK 7. I have done this step when I installed Jenkins. How to find out a process PID on Windows
C:\Users\luhuang>java -version
java version “1.7.0_45”
Java(TM) SE Runtime Environment (build 1.7.0_45-b18)
Java HotSpot(TM) 64-Bit Server VM (build 24.45-b08, mixed mode)

C:\Users\luhuang>

2. Install MySQL5.6.
C:\Users\luhuang>mysql –version
mysql Ver 14.14 Distrib 5.6.19, for Win64 (x86_64)

C:\Users\luhuang>

3. Install Maven.
C:\Users\luhuang>mvn –version
Apache Maven 3.2.2 (45f7c06d68e745d05611f7fd14efb6594181933e; 2014-06-17T21:51:4
2+08:00)
Maven home: D:\apache-maven-3.2.2\bin\..
Java version: 1.7.0_45, vendor: Oracle Corporation
Java home: C:\glassfish4\jdk7\jre
Default locale: zh_CN, platform encoding: Cp1252
OS name: “windows 7”, version: “6.1”, arch: “amd64”, family: “windows”
C:\Users\luhuang>

4. Run command to pull down source code for AppFuse:
mvn archetype:generate -B -DarchetypeGroupId=org.appfuse.archetypes -DarchetypeArtifactId=appfuse-basic-spring-archetype -DarchetypeVersion=3.0.0 -DgroupId=com.mycompany -DartifactId=myproject -DarchetypeRepository=http://oss.sonatype.org/content/repositories/appfuse

[If you are behind a firefox, you have to set your proxy in settings.xml under apache-maven-3.2.2\conf\settings.xml. E.g,
optional
true
http
xxxx.xxxx.xxx.com
80

[INFO] Downloading: http://repo.maven.apache.org/maven2/org/appfuse/archetypes/a
ppfuse-basic-spring-archetype/3.0.0/appfuse-basic-spring-archetype-3.0.0.pom
[INFO] Downloaded: http://repo.maven.apache.org/maven2/org/appfuse/archetypes/ap
pfuse-basic-spring-archetype/3.0.0/appfuse-basic-spring-archetype-3.0.0.pom (2 K
B at 1.5 KB/sec)
[INFO] ————————————————————————-

[INFO] Using following parameters for creating project from Archetype: appfuse-b
asic-spring-archetype:3.0.0
[INFO] ————————————————————————-

[INFO] Parameter: groupId, Value: com.luohuahuang
[INFO] Parameter: artifactId, Value: releng
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.luohuahuang
[INFO] Parameter: packageInPathFormat, Value: com/luohuahuang
[INFO] Parameter: version, Value: 1.0-SNAPSHOT
[INFO] Parameter: package, Value: com.luohuahuang
[INFO] Parameter: groupId, Value: com.luohuahuang
[INFO] Parameter: artifactId, Value: releng
[INFO] project created from Archetype in dir: D:\Source\releng
[INFO] ————————————————————————
[INFO] BUILD SUCCESS
[INFO] ————————————————————————
[INFO] Total time: 04:08 min
[INFO] Finished at: 2014-06-28T18:11:31+08:00
[INFO] Final Memory: 12M/154M
[INFO] ————————————————————————
D:\Source>

5. Run the application, mvn jetty:run.

Jetty is using 8080 by default however Jenkins has already used 8080 as its server port. To avoid conflicting, update it to 8088 in the pom.xml before running mvn jetty:run. AppFuse uses root user to connect MySQL without password, update the password accordingly,


<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>jetty-maven-plugin</artifactId>
<version>8.1.14.v20131031</version>
<configuration>
<webApp>
<contextPath>/</contextPath>
</webApp>
<connectors>
<connector implementation="org.eclipse.jetty.server.nio.SelectChannelConnector">
<port>8088</port>
</connector>
</connectors>
</configuration>
</plugin>

...

<!-- Database settings -->
<dbunit.dataTypeFactoryName>org.dbunit.ext.mysql.MySqlDataTypeFactory</dbunit.dataTypeFactoryName>
<dbunit.operation.type>CLEAN_INSERT</dbunit.operation.type>
<hibernate.dialect>org.hibernate.dialect.MySQL5InnoDBDialect</hibernate.dialect>
<jdbc.groupId>mysql</jdbc.groupId>
<jdbc.artifactId>mysql-connector-java</jdbc.artifactId>
<jdbc.version>5.1.27</jdbc.version>
<jdbc.driverClassName>com.mysql.jdbc.Driver</jdbc.driverClassName>
<jdbc.url>jdbc:mysql://localhost/${db.name}?createDatabaseIfNotExist=true&amp;amp;useUnicode=true&amp;amp;characterEncoding=utf-8&amp;amp;autoReconnect=true</jdbc.url>
<jdbc.username>root</jdbc.username>
<jdbc.password>root</jdbc.password>
<jdbc.validationQuery>SELECT 1 + 1</jdbc.validationQuery>

6. While you run mvn jetty:run, it might fail with error,

[ERROR] Failed to execute goal org.codehaus.mojo:hibernate3-maven-plugin:2.2:hbm
2ddl (default) on project : Execution default of goal org.codehaus.mojo:hi
bernate3-maven-plugin:2.2:hbm2ddl failed

: Could not parse configuration: file:/D
:/Source/releng/src/main/resources/hibernate.cfg.xml: Connection timed out: conn
ect Nested exception: Connection timed out: connect -> [Help 1]

Go to releng\src\main\resources, edit hibernate.cfg.xml,

</pre>
<!-- NOTE: If you're working offline, you might have to change the DOCTYPE to the following:-->
<!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://hibernate.sourceforge.net/hibernate-configuration-3.0.dtd">
<!--!DOCTYPE hibernate-configuration PUBLIC "-//Hibernate/Hibernate Configuration DTD 3.0//EN"
"http://www.hibernate.org/dtd/hibernate-configuration-3.0.dtd"-->

<hibernate-configuration>
<session-factory>
<mapping class="org.appfuse.model.User"/>
<mapping class="org.appfuse.model.Role"/>
</session-factory>
</hibernate-configuration>

 

7. Run mvn jetty:run again,

Downloaded: http://repo.maven.apache.org/maven2/org/eclipse/jetty/orbit/org.ecli
pse.jdt.core/3.7.1/org.eclipse.jdt.core-3.7.1.jar (1708 KB at 72.3 KB/sec)
[INFO] Configuring Jetty for project: AppFuse Spring MVC Application
[INFO] webAppSourceDirectory not set. Defaulting to D:\Source\releng\src\main\we
bapp
[INFO] Reload Mechanic: automatic
[INFO] Classes = D:\Source\releng\target\classes
[INFO] Context path = /
[INFO] Tmp directory = D:\Source\releng\target\tmp
[INFO] Web defaults = org/eclipse/jetty/webapp/webdefault.xml
[INFO] Web overrides = none
[INFO] web.xml file = file:/D:/Source/releng/src/main/webapp/WEB-INF/web.xml
[INFO] Webapp directory = D:\Source\releng\src\main\webapp
2014-06-28 18:50:53.083:INFO:oejs.Server:jetty-8.1.14.v20131031
2014-06-28 18:50:55.977:INFO:oejpw.PlusConfiguration:No Transaction manager foun
d – if your webapp requires one, please configure one.
2014-06-28 18:51:04.607:INFO:/:No Spring WebApplicationInitializer types detecte
d on classpath
2014-06-28 18:51:05.761:INFO:/:Initializing Spring root WebApplicationContext
WARN [main] DTDEntityResolver.resolveEntity(74) | HHH000223: Recognized obsolete
hibernate namespace http://hibernate.sourceforge.net/. Use namespace http://www
.hibernate.org/dtd/ instead. Refer to Hibernate 3.6 Migration Guide!
WARN [main] DirectoryProviderHelper.makeSanityCheckedDirectory(258) | HSEARCH000
041: Index directory not found, creating: ‘D:\Source\releng\target\index’
WARN [main] DirectoryProviderHelper.makeSanityCheckedDirectory(258) | HSEARCH000
041: Index directory not found, creating: ‘D:\Source\releng\target\index\org.app
fuse.model.User’
DEBUG [main] LookupDaoHibernate.getRoles(39) | Retrieving all role names…
WARN [main] StartupListener.contextInitialized(96) | META-INF/MANIFEST.MF not fo
und.
2014-06-28 18:51:18.509:INFO:/:Initializing Spring FrameworkServlet ‘dispatcher’

2014-06-28 18:51:20.037:WARN:oejsh.RequestLogHandler:!RequestLog
2014-06-28 18:51:20.218:INFO:oejs.AbstractConnector:Started SelectChannelConnect
or@0.0.0.0:8088
[INFO] Started Jetty Server

appfuse1