While compiling a maven webapp using GWT on Hudson, I’ve got the following issue :
[ERROR] Exception in thread "main" java.lang.NoClassDefFoundError: com/google/gwt/dev/Compiler
[ERROR] Caused by: java.lang.ClassNotFoundException: com.google.gwt.dev.Compiler
[ERROR] at java.net.URLClassLoader$1.run(URLClassLoader.java:200)
[ERROR] at java.security.AccessController.doPrivileged(Native Method)
[ERROR] at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
[ERROR] at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
[ERROR] at java.lang.ClassLoader.loadClass(ClassLoader.java:252)
[ERROR] at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:320)
This can be solved by telling gwt-maven-plugin to use a localWorker. Here is the config for pom.xml :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.3-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>mypage.html</runTarget>
<extraJvmArgs>-Xmx512m</extraJvmArgs>
<generateDirectory>src/main/java</generateDirectory>
<localWorkers>1</localWorkers>
</configuration>
</plugin>
Then, you will happily see :
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
Simply add those dependencies to use Apache CXF with Maven.
<properties>
<cxf.version>2.2.3</cxf.version>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-frontend-jaxws</artifactId>
<version>${cxf.version}</version>
</dependency>
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http</artifactId>
<version>${cxf.version}</version>
</dependency>
<!-- Jetty is needed if you're are not using the CXFServlet -->
<dependency>
<groupId>org.apache.cxf</groupId>
<artifactId>cxf-rt-transports-http-jetty</artifactId>
<version>${cxf.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<webResources>
<resource>
<directory>${basedir}/src/main/webapp/WEB-INF</directory>
<filtering>true</filtering>
<targetPath>WEB-INF</targetPath>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
It can be very helpful to dispose of a library of pre-configured projects. Here, we want to create a multi-module project composed of a core (Hibenate Dao) and a web (SpringMVC webapp) module.
<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">
<modelVersion>4.0.0</modelVersion>
<groupId>net.stephou</groupId>
<artifactId>parent</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<name>parent</name>
<url>http://maven.apache.org</url>
<modules>
<module>core</module>
<module>web</module>
</modules>
...
Use a mvn archetype:create-from-project to create the archetype project.
and in target/generated-sources/archetype/ use a mvn install.
In the end, into a new directory, the mvn archetype:generate -DarchetypeCatalog=local will allow you to use the project as a ready-to-code project
D:\documents\NetBeansProjects>%M2_HOME%\bin\mvn archetype:generate -DarchetypeCa
talog=local
[INFO] Scanning for projects...
[INFO] Searching repository for plugin with prefix: 'archetype'.
[INFO] org.apache.maven.plugins: checking for updates from central
[INFO] org.codehaus.mojo: checking for updates from central
[INFO] artifact org.apache.maven.plugins:maven-archetype-plugin: checking for up
dates from central
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO] task-segment: [archetype:generate] (aggregator-style)
[INFO] ------------------------------------------------------------------------
[INFO] Preparing archetype:generate
[INFO] No goals needed for project - skipping
[INFO] Setting property: classpath.resource.loader.class => 'org.codehaus.plexus
.velocity.ContextClassLoaderResourceLoader'.
[INFO] Setting property: velocimacro.messages.on => 'false'.
[INFO] Setting property: resource.loader => 'classpath'.
[INFO] Setting property: resource.manager.logwhenfound => 'false'.
[INFO] [archetype:generate {execution: default-cli}]
[INFO] Generating project in Interactive mode
[INFO] No archetype defined. Using maven-archetype-quickstart (org.apache.maven.
archetypes:maven-archetype-quickstart:1.0)
Choose archetype:
1: local -> parent-archetype (parent-archetype)
Choose a number: (1): 1
Define value for groupId: : net.stephou
Define value for artifactId: : springmvc-mvn-webapp
Define value for version: 1.0-SNAPSHOT: :
Define value for package: net.stephou: :
Confirm properties configuration:
groupId: net.stephou
artifactId: springmvc-mvn-webapp
version: 1.0-SNAPSHOT
package: net.stephou
Y: : Y
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1 minute 15 seconds
[INFO] Finished at: Sun Feb 28 22:11:56 CET 2010
[INFO] Final Memory: 8M/14M
[INFO] ------------------------------------------------------------------------
A new folder named springmvc-mvn-webapp will appear in the selected folder. Just open it in your favourite IDE.
See also : http://maven.apache.org/plugins/maven-archetype-plugin/advanced-usage.html
“Eclipse is running in a JRE, but a JDK is required. Some Maven plugins may not work when importing projects or updating source folders.”
To suppress the message that shows up ine the console when you launch Eclipse, you can simply add in your eclipse.ini the following :
-vm
path\to\your\jdk\bin\javaw.exe
I’ve already succeeded to create classes and mapping from tables of a DB, but creating a new one from the annotated classes themselves can be very useful for a freshly created project
As a Maven addicted, I’ve used the hibernate3-maven-plugin to generate such a DB (and this way, avoiding the Ant scripting …).
In the pom.xml of your project you will have to add the following configuration of the plugin :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>hibernate3-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<components>
<component>
<name>hbm2ddl</name>
<implementation>annotationconfiguration</implementation>
</component>
</components>
<componentProperties>
<drop>true</drop>
<configurationfile>/src/main/resources/hibernate.cfg.xml</configurationfile>
</componentProperties>
</configuration>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.8</version>
</dependency>
</dependencies>
</plugin>
The important point here, is the annotationconfiguration used. While using annotated classes, this has to be used for creating a new DB instead of a jdbcconfiguration for an existing one.The configuration file which refers to hibernate.cfg.xml is not necessary here because, by default, it refers to that file (it’s just easier for you to change something for a reason or an other ^^ ).
Choose your driver to access your DB and add it in the dependencies of the plugin (here MySQL 5.1.8).
Once all is configured, run a mvn hibernate3:hbm2ddl.
First, a mvn archetype:create-from-project and a mvn install on the created archetype in target/generated-sources/archetype directory.
A directory, named ${groupId}/${artifactId}-archetype, containing a jar and pom.xml is generated into the repository.
A mvn archetype:crawl -Drepository=/path/to/.m2 is then used to generate the archetypes catalog. The archetype-catalog.xml file is by default generated in .m2/repository (this can be changed while using the parameter -Ddirectory=/path/for/xml)
Finally, in Eclipse, go to Window > Prefences > Maven > Archetypes > Add local catalog, enter the name and directory of this catalog.
When you create a new Maven project on Eclipse, you can select your ${groupId}/${artifactId}-archetype in your catalog freshly named.
More on :
http://maven.apache.org/plugins/maven-archetype-plugin/advanced-usage.html
I finally did it !!!!!!!!!!!!
I manage to configure a Maven webapp to run on a Tomcat Server to test the JSPs on Eclipse.
.: To Complete :.
1. Create a library for Tomcat JARs
Window > Preferences > Java > Build Path > User Libraries
2. Add this library to classpath with maven-eclipse-plugin
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.3</version>
<configuration>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.USER_LIBRARY/Tomcat-6.0.20</classpathContainer>
</classpathContainers>
…
</plugin>
A big thank to that site
http://www.devx.com/Java/Article/36785/1763/page/3
Let’s code then