Archive for the ‘HOWTO’ Category

HOWTO: Remove GWT package from url when using gwt-maven

Friday, March 13th, 2009

Seriously, who wants a url like /my.long.package.name.Application/Application.html

To remedy this use the following steps:

  1. Make the webapp directory the same as the output for your gwt code.
    ...
    <plugin>
    	<groupId>org.apache.maven.plugins</groupId>
    	<artifactId>maven-war-plugin</artifactId>
    	<configuration>
    		<webappDirectory>${project.build.directory}/${project.build.finalName}/my.long.package.name.Application	</webappDirectory>
    	</configuration>
    </plugin>
    ...
  2. Ensure that your rpc servlets don’t have the package as a prefix.
    ...
    <plugin>
    	<groupId>com.totsp.gwt</groupId>
    	<artifactId>maven-googlewebtoolkit2-plugin</artifactId>
    	...
    	<configuration>
    		...
    		<webXmlServletPathAsIs>true</webXmlServletPathAsIs>
    	</configuration>
    	...
    </plugin>
    ...
  3. Change your index.html file to point to your app.
    From:

    <meta http-equiv="REFRESH" content="0;url=my.long.package.name.Application/Application.html">

    To:

    <meta http-equiv="REFRESH" content="0;url=Application.html">
  4. Your done.

Additional resources:
http://groups.google.com/group/Google-Web-Toolkit/browse_thread/thread/f8b06676098b8cc6

http://groups.google.com/group/gwt-maven/browse_thread/thread/a46f540ca823e3d3/7d5febf0776958db?lnk=gst&q=rename#7d5febf0776958db

HOWTO: Run your java web app as the root context on Tomcat

Friday, March 13th, 2009

If you have a context XML fragment in your war (META-INF/context.xml) then it’s as easy as renaming your war file to ROOT.war

If you’re using the maven build system then just alter your pom to have:

<build>
	<finalName>ROOT</finalName>
	...
</build>

Simple when you know how…

HOWTO: Setup a shell Java Struts 2 web app using Maven 2 & Eclipse 3.4

Wednesday, November 26th, 2008

The latest project I’m working on is a Java web app using Struts 2. I wanted to use the eclipse IDE since it’s industry standard and the Maven 2 build system for compatibility with other company projects.

I did plenty of reading (Maven: The Definitive Guide is a good place to start), but nowhere did I find an easy step-by-step quickstart for this combination of tools.

So I’ve pieced my reading and research together and here it is:

Prerequisites

Java
maven 2
eclipse 3.4.1

Create a new skeleton project:

1
2
3
4
5
6
cd ~/workspace/</br>
mvn archetype:generate -DgroupId={name of your group e.g. com.austenconstable} \
-DartifactId={name of your app} \
-DarchetypeGroupId=org.apache.struts \
-DarchetypeArtifactId=struts2-archetype-starter \
-DarchetypeVersion=2.0.11.2

If you’re not sure on the latest struts 2 archetype release version check here.

Generate the eclipse project files:

mvn eclipse:eclipse

Configure eclipse:

mvn eclipse:configure-workspace -Declipse.workspace=/path/to/your/workspace/

Import the project into eclipse:

Fire up eclipse and use File>Import…

And now all you need to do is build your app!