Loading the Project Into Eclipse

The first step is to ask Maven to generate the Eclipse control files (.classpath and .project) for us:

$ mvn eclipse:eclipse -DdownloadSources=true
[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-war-plugin/2.1.1/maven-war-plugin-2.1.1.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-war-plugin/2.1.1/maven-war-plugin-2.1.1.pom (7 KB at 7.1 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-war-plugin/2.1.1/maven-war-plugin-2.1.1.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-war-plugin/2.1.1/maven-war-plugin-2.1.1.jar (76 KB at 83.4 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/maven-metadata.xml
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/maven-metadata.xml (680 B at 1.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/2.8/maven-eclipse-plugin-2.8.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/2.8/maven-eclipse-plugin-2.8.pom (12 KB at 22.9 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugins/17/maven-plugins-17.pom
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugins/17/maven-plugins-17.pom (13 KB at 25.6 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/2.8/maven-eclipse-plugin-2.8.jar
Downloaded: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-eclipse-plugin/2.8/maven-eclipse-plugin-2.8.jar (202 KB at 237.8 KB/sec)
[INFO] ------------------------------------------------------------------------
[INFO] Building tutorial1 Tapestry 5 Application 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] >>> maven-eclipse-plugin:2.8:eclipse (default-cli) @ tutorial1 >>>
[INFO] <<< maven-eclipse-plugin:2.8:eclipse (default-cli) @ tutorial1 <<<
[INFO] --- maven-eclipse-plugin:2.8:eclipse (default-cli) @ tutorial1 ---
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-7/plexus-archiver-1.0-alpha-7.pom
Downloaded: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-archiver/1.0-alpha-7/plexus-archiver-1.0-alpha-7.pom (2 KB at 2.3 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-components/1.1.6/plexus-components-1.1.6.pom
Downloaded: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-components/1.1.6/plexus-components-1.1.6.pom (2 KB at 3.7 KB/sec)
Downloading: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/1.2/plexus-utils-1.2.pom
Downloaded: http://repo1.maven.org/maven2/org/codehaus/plexus/plexus-utils/1.2/plexus-utils-1.2.pom (767 B at 1.5 KB/sec)

(...hundreds of lines omitted here...)

Downloading: https://repository.apache.org/content/groups/staging/com/google/inject/guice/2.0/guice-2.0-sources.jar
Downloading: http://repo1.maven.org/maven2/com/google/inject/guice/2.0/guice-2.0-sources.jar
Downloading: https://repository.apache.org/content/groups/staging/org/apache/tapestry/tapestry-yuicompressor/5.3/tapestry-yuicompressor-5.3-sources.jar
Downloaded: https://repository.apache.org/content/groups/staging/org/apache/tapestry/tapestry-yuicompressor/5.3/tapestry-yuicompressor-5.3-sources.jar (7 KB at 25.8 KB/sec)
Downloading: https://repository.apache.org/content/groups/staging/rhino/js/1.6R7/js-1.6R7-sources.jar
Downloading: http://repo1.maven.org/maven2/rhino/js/1.6R7/js-1.6R7-sources.jar
[INFO] Wrote settings to /Users/hlship/Documents/workspace/tutorial1/.settings/org.eclipse.jdt.core.prefs
[INFO] Wrote Eclipse project for "tutorial1" to /Users/hlship/Documents/workspace/tutorial1.
       Sources for some artifacts are not available.
       List of artifacts without a source archive:
         o org.beanshell:bsh:2.0b4
         o xalan:serializer:2.7.1
         o org.apache.tomcat:catalina:6.0.30
         o org.apache.tomcat:servlet-api:6.0.30
         o org.apache.tomcat:juli:6.0.30
         o org.apache.tomcat:annotations-api:6.0.30
         o org.apache.tomcat:coyote:6.0.30
         o org.apache.tomcat:dbcp:6.0.30

[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 39.526s
[INFO] Finished at: Fri Mar 1 11:52:57 PST 2013
[INFO] Final Memory: 9M/81M
[INFO] ------------------------------------------------------------------------

At this point, Maven has created the Eclipse .project and .classpath files, and we can import the project. In addition, since we specified -DdownloadSources=true, Maven has also downloaded the sources of each library and linked to the source JAR (where available); that means we can see the sources for any Tapestry classes right inside Eclipse, which is very useful when debugging or exploring.

At this point, we are ready to import the project created by Maven into Eclipse so we can start working with it. Launch Eclipse and switch over to the Java Perspective.

Right click inside the Package Explorer view and select Import ...

Choose the "existing projects" option:

Now select the folder created by Maven:

When you click the Finish button, the project will be imported into the Eclipse workspace.

However; there are many errors. Maven expects that you will configure a classpath variable, M2_REPO, that points at your local repository; a directory in your home directory that stores all those downloaded JARs and other files. Open Eclipse's preferences panel and navigate to Java > Build Path > Classpath Variables:

Click the New button, and enter the new variable (you'll have to adjust this for your operating system and local paths):

Eclipse will ask to perform a clean build, and the errors will be gone once it has done so.

Running the Application inside Eclipse

The task is to set up Jetty to run our application directly out of our Eclipse workspace. This is a great way to develop web applications, since we don't want to have to use Maven to compile and run the application ... or worse yet, use Maven to package and deploy the application. That's for later, when we want to put the application into production. For development, we want a fast, agile environment that can keep up with our changes, and that means we can't wait for redeploys and restarts.

Choose the Run ... item from the Eclipse Run menu to get the launch configuration dialog:

Select Jetty Webapp and click the New button, then fill in a few values:

You will need to click the "Show advanced Options" checkbox, then uncheck "SSL" and "Enable Scanner".

Tapestry runs best with a couple of additional options; click the "Arguments" tab and enter the following VM Arguments: -XX:MaxPermSize=256M -Xmx600m -Dtapestry.execution-mode=development

Tapestry uses more PermGen space (the part of Java memory used for loading classes) than a typical application, and uses more heap memory than the default; the above settings are good for a medium-to-large size Tapestry application, and will keep Java from running the Garbage Collector too often. The setting of tapestry.execution mode tells Tapestry to run in development mode, where runtime exceptions are reported more exhaustively.

With those settings in place, you can then click Run and Jetty will launch (it takes only a few seconds):

Once you click Run, Jetty will start up and launch (it should take a second or two).

You may now start the application with the URL http://localhost:8080/tutorial1/