Adding gwt project to existing java servlet 3 project - gwt

I have a standalone gwt project with RPC built with Maven. I also have java servlet 3.0 project. Both the servlet and gwt projects have war packaging but I want to have only one war file so I changed the packaging of the gwt project to jar and included it in my servlet project.
Now I have a problem understanding how to wire everything together.
Do I need to migrate gwt project's web.xml into the main project web.xml file ? How do I redirect to my gwt project entry index.html ?
Thanks.

You can use uberwar packaging and cargo-maven2-plugin to merge two *.war
<build>
<plugins>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<version>1.2.4</version>
<extensions>true</extensions>
<configuration>
<descriptor>src/assemble/merge.xml</descriptor>
</configuration>
</plugin>
</plugins>
</build>

Related

How to define in Eclipse Plugin WTP the context name of my app

I am working in Eclipse 4.2 and the WTP Plugin. I deployed my web-app on the integrated tomcat 7 server, but the context name is not as supposed. I want to name it moduleA but the current project name will be used as context name in the tomcat.
I already changed the Context-Root to moduleA in the Properties->Web Web Project Settings and I added
<properties>
<runtime.context>moduleA</runtime.context>
<m2eclipse.wtp.contextRoot>moduleA</m2eclipse.wtp.contextRoot>
</properties>
to my pom.xml
As I start my Tomcat it will always deploy it with the project name. Does someone know what the problem might be?
Thanks
Hello if you are using pom.xml with maven 3.. version.
you can use eclipse plugin like given below
<plugins>
<plugin>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<wtpversion>2.0</wtpversion>
<wtpContextName>moduleA</wtpContextName>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<classpathContainers>
<classpathContainer>org.eclipse.jst.j2ee.internal.web.container</classpathContainer>
<classpathContainer>org.eclipse.jst.j2ee.internal.module.container</classpathContainer>
</classpathContainers>
</configuration>
</plugin>
and give the desired context name in tag.

Tomcat 7 maven plugin additional context on tomcat7:run

When I run my web app inside eclipse using tomcat 7 maven plugin, I want an additional context to be deployed to tomcat. On the production enviroment this context is mapped to a directory outside tomcat dir using a context configuration
<Context path="/userimages" docBase="C:/test/userimages">
</Context>
And by this way is available in
http://wwww.myhost.com/userimages/test.jpg
How I achive the same on the development enviroment of the webapp (eclipse, tomcat7 maven plugin)?
In other words I want the contents of that folder to be accessible through
http://localhost:8080/userimages
or
http://localhost:8080/myapp/userimages
You should configure tomcat7-maven-plugin plugin.
Try this way:
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.0</version>
<configuration>
<path>your_app_context_path</path>
<uriEncoding>utf-8</uriEncoding>
</configuration>
</plugin>
Then all your urls should start with http://wwww.myhost.com/your_app_context_path/...
More optional parameters for tomcat7:run goal can be found at apache tomcat maven plugin document
I found a workaround that doesn't do exactly what I originally wanted (publish another context using the tomcat maven plugin) but it solves my problem in a way. I add a folder "userimages" in the webapp folder of the application and this folder is used when developing. I prevent this folder from getting in the war and thus in the production server by using the "maven-war-plugin" with the following configuration in the pom.xml
<build>
....
<plugins>
....
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.2</version>
<configuration>
<packagingExcludes>userimages/</packagingExcludes>
</configuration>
</plugin>
....
</plugins>
....
</build>
Check also here and here

How to avoid maven WTP enabled project automatically generates web.xml?

I have setup multi-modules environment with Maven, Eclipse, WTP.
The Eclipse Plugins I installed are:
m2e
m2e-extras
m2e-overlay
I have a war module(w2) that depends on another war module(w1), w1 has a web.xml file, and w2 doesn't have it's own, it uses overlay web.xml from w1. Whenever I click maven -> Update project configuration, eclipse automatically generates an empty web.xml for w2 which I really don't want.
How can I disable this?
By default, m2e-wtp specifically asks WTP to not generate a web.xml if none exists and adds the Dynamic Web Facet 2.5 by default (or 3.0 if some JavaEE 6 dependencies are detected in the classpath).
The only reason WTP would create the web.xml would be if we asked to install a facet version <=2.4. But these facets can only be inferred from an existing web.xml. See the irony?
So what you see is most likely a bug and you might want to create a bug report with a sample project attached to https://issues.sonatype.org/browse/MECLIPSEWTP
In the mean time you can try to use a dev build of m2e-wtp 0.14.0, available from http://download.jboss.org/jbosstools/builds/staging/m2eclipse-wtp-e37/all/repo/, as I recently made changes in the way Dynamic Facet version changes are handled.
And as for the overlay exclusion configuration described in the first reply, that wouldn't work for you since you want to specifically use w1's web.xml, not exclude it. I would rather invert the overlay order like :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<overlays>
<overlay>
<groupId>foo.bar</groupId>
<artifactId>w1</artifactId>
</overlay>
<overlay>
<!-- this is the current w2,
it's resources will be overridden by w1
-->
</overlay>
</overlays>
</configuration>
</plugin>
What you can do is - explicitly exclude the dependent module's web.xml and while packaging, it will pick the xml from the parent war:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<overlays>
<!-- Overlay w2 WAR with w1 specific web.xml -->
<overlay>
<groupId>xyz</groupId>
<artifactId>w1</artifactId>
<excludes>
<exclude>WEB-INF/web.xml</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
</plugins>
</build>
Cheers!

what does the wtpversion mean in the Eclipse plugin?

using maven, what does the wtpversion mean in the Eclipse plugin?
wtp adds web application support to eclipse. If you want to develop Maven based web applications with Eclipse, you should rather use Eclipse m2eclipse plugin.
As for wtpversions, this link has a mapping of wtpversion and eclipse versions.
This is the abbreviation of Eclipse Web Tools Project and you can use in maven > pom.xml under the <build> tag:
<!-- Eclipse project -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.9</version>
<configuration>
<!-- Always download and attach dependencies source code -->
<downloadSources>true</downloadSources>
<downloadJavadocs>false</downloadJavadocs>
<!-- Avoid type mvn eclipse:eclipse -Dwtpversion=2.0 -->
<wtpversion>2.0</wtpversion>
</configuration>
</plugin>
From: How To Create A Web Application Project With Maven

GWT/Eclipse/Jetty issue: Jasper can't resolve tag libraries

I'm trying to get GWT Hosted mode working in Eclipse, à la this HOWTO. Servlets work fine, as does my GWT code, but all my JSPs fail because with errors such as the following:
[WARN] /view/lniExecutiveSummary.htm
org.apache.jasper.JasperException: /WEB-INF/jsp/lni/lniExecutiveSummary.jsp(1,1) The absolute uri: http://java.sun.com/jsp/jstl/fmt cannot be resolved in either web.xml or the jar files deployed with this application
at org.apache.jasper.compiler.DefaultErrorHandler.jspError(DefaultErrorHandler.java:39)
at org.apache.jasper.compiler.ErrorDispatcher.dispatch(ErrorDispatcher.java:409)
[ trimmed ]
This webapp works fine when deployed under Tomcat 5x; I just can't seem to get it to resolve the taglibs when running in Eclipse.
I'm new to Eclipse, and getting it working with all the moving parts required for GWT+Maven has me pulling my hair out.
Update: I'm no longer using Eclipse; I've switched (back!) to Intellij IDEA. So I can't honestly evaluate the answers you kind folks have posted. Once some voting action happens, or someone else reports success with one of these methods, I'll accept the appropriate answer. Thanks.
I feel your pain. I've gone thru the same pain trying to get gwt, maven, and eclipse to work together.
I've been able to get it working with maven using the following pom.xml. This way you can use mvn gwt:run to run in hosted mode, but unfortunately, I could never get the mvn goal mvn gwt:eclipse for generating an eclipse launch run time config to work.
Here's the relevant snippets from my pom.xml. Note that I've found it easier to install gwt in separate location and point maven to use that instead of having mvn download gwt from repo. The "system" level scope in the mvn dependencies are what make this happen.
<properties>
<!-- convenience to define GWT version in one place -->
<gwt.version>1.7.1</gwt.version>
<google.webtoolkit.home>${env.GWT_HOME}</google.webtoolkit.home>
<!-- tell the compiler we can use 1.5 -->
<maven.compiler.source>1.6</maven.compiler.source>
<maven.compiler.target>1.6</maven.compiler.target>
</properties>
<dependencies>
<!-- GWT dependencies (from central repo) -->
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<version>${gwt.version}</version>
<scope>system</scope>
<systemPath>${env.GWT_HOME}/gwt-servlet.jar</systemPath>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwt.version}</version>
<scope>system</scope>
<systemPath>${env.GWT_HOME}/gwt-user.jar</systemPath>
</dependency>
... other dependencies...
</dependencies>
<build>
<outputDirectory>war/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>1.1</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>generateAsync</goal>
<goal>test</goal>
</goals>
</execution>
</executions>
<configuration>
<runTarget>com.gwt.example/Application.html</runTarget>
<extraJvmArgs>-Xmx512m</extraJvmArgs>
</configuration>
</plugin>
<!--
If you want to use the target/web.xml file mergewebxml produces,
tell the war plugin to use it.
Also, exclude what you want from the final artifact here.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webXml>target/web.xml</webXml>
<warSourceExcludes>.gwt-tmp/**</warSourceExcludes>
</configuration>
</plugin>
-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.0.2</version>
<configuration>
<source>${maven.compiler.source}</source>
<target>${maven.compiler.target}</target>
<module>com.gwt.example</module>
</configuration>
</plugin>
</plugins>
...rest of pom.xml...
Another technique I've had success with is to use the eclipse google gwt plugin. Just use the wizard to create a new gwt project, make sure that you can run it from eclipse, then modify with your own code.
This webapp works fine when deployed under Tomcat 5x; I just can't seem to get it to resolve the taglibs when running in Eclipse. I'm new to Eclipse, and getting it working with all the moving parts required for GWT+Maven has me pulling my hair out.
You apparently have the JSTL JAR file(s) in Tomcat/lib instead of WEB-INF/lib. You can fix this in at least three ways:
Move/copy the JSTL JAR file(s) into WEB-INF/lib.
Move/copy the JSTL JAR file(s) into Tomcat/lib of your development machine.
Associate the right Tomcat server containing the JSTL JAR file(s) with web project in Eclipse. If not done yet, add the Tomcat server in Servers view. Then in project properties go to Java Build Path > Libraries > Add Library > Server Runtime > select the server in question.
Add the Jar files in eclipse project classpath. if you already had this file tomcat lib. This option will works for you. Second option is add jar in Web-Inf lib folder if you have eclipse web project.
Did you try to mark the "jsf-api.jar" as "exported" in your Java project ?
(as mentioned in this thread)
1.) Go into the java-project properties and mark the "jsf-api.jar" as exported.
(project>properties>java build path>order and exports)
2.) Go into the advanced global tomcat preferences and add your project to
the tomcat classpath (windows>preferences>tomcat>advanced>add projects to
tomcat classpath)
Then, try again to run your webapp under eclipse.
Here is an article describing the same procedure/setup, not for JSF but Hudson (same problem though)
You can clearly see the two steps I mentioned above:
(source: hudson-ci.org)
(source: hudson-ci.org)