Dynamic Web Module 3.0 -- 3.1 - eclipse

I have a mavenized codebased configured Spring 3.2.4 web app.
When I build the app with Maven/pom.xml first I got an error that web.xml is missing.
first I tried to create an empty web.xml. this was the moment when The project facets changed (and I don't know why). It switched from dynamic Web Module 3.0 to 3.1 and this is irreversible.
How can I change it again into Dynamic Web Modules 3.0???
Additionally I can't remove the JAX-RS. Trying this it results in:
Failed while uninstalling JAX-RS (REST Web Services) 1.0.
org.eclipse.jst.javaee.web.internal.impl.WebAppImpl cannot be cast to org.eclipse.jst.j2ee.webapplication.WebApp
Later I found out that I can avoid the Maven compile error by inserting the according plugin into pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
</configuration>
</plugin>

I had similar troubles in eclipse and the only way to fix it for me was to
Remove the web module
Apply
Change the module version
Add the module
Configure (Further configuration available link at the bottom of the dialog)
Apply
Just make sure you configure the web module before applying it as by default it will look for your web files in /WebContent/ and this is not what Maven project structure should be.
EDIT:
Here is a second way in case nothing else helps
Exit eclipse, go to your project in the file system, then to .settings folder.
Open the org.eclipse.wst.common.project.facet.core.xml , make backup, and remove the web module entry.
You can also modify the web module version there, but again, no guarantees.

If you want to use version 3.1 you need to use the following schema:
http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd
Note that 3.0 and 3.1 are different: in 3.1 there's no Sun mentioned, so simply changing 3_0.xsd to 3_1.xsd won't work.
This is how it should look like:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:web="http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee">
</web-app>
Also, make sure you're depending on the latest versions in your pom.xml. That is,
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
...
</configuration>
</plugin>
and
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<scope>provided</scope>
</dependency>
Finally, you should compile with Java 7 or 8:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>

I had the same problem and fixed this by editing org.eclipse.wst.common.project.facet.core.xml.
In this file, I was able to change the following line
<installed facet="jst.web" version="3.1"/>
back to
<installed facet="jst.web" version="3.0"/>
That seemed to fix the problem for me.

I was running on Win7, Tomcat7 with maven-pom setup on Eclipse Mars with maven project enabled.
On a NOT running server I only had to change from 3.1 to 3.0 on this screen:
For me it was important to have Dynamic Web Module disabled! Then change the version and then enable Dynamic Web Module again.

Open Eclipse project properties, in Project Facets unselect "Dynamic Web Module",... Click OK
Maven -> Update project

In a specific case the issue is due to the maven-archetype-webapp which is released for a dynamic webapp, faceted to the ver.2.5 (see the produced web.xml and the related xsd) and it's related to eclipse.
When you try to change the project facet to dynamic webapp > 2.5 the src folder structure will syntactically change (the 2.5 is different from 3.1), but not fisically.
This is why you will face in a null pointer exception if you apply to the changes.
To solve it you have to set from the project facets configuration the Default configuration. Apply the changes, then going into the Java Build Path you have to remove the /src folder and create the /src/main/java folder at least (it's also required /src/main/resources and /src/test/java to be compliant) re-change into the required configuration you desire (3.0, 3.1) and then do apply.

I opened the project org.eclipse.wst.common.project.facet.core.xml and first changed then removed line with web module tag. Cleaned project and launched on Tomcat each time but it still didn't run. Returned line (as was) and cleaned project. Opened Tomcat settings in Eclipse and manually added project to Tomcat startup (Right click + Add and Remove). Clicked on project and selected Run on server....and everything was fine.

1) Go to your project and find ".settings" directory this one
2) Open file xml named:
org.eclipse.wst.common.project.facet.core.xml
3)
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<fixed facet="wst.jsdt.web"/>
<installed facet="java" version="1.5"/>
<installed facet="jst.web" version="2.3"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
Change jst.web version to 3.0 and java version to 1.7 or 1.8 (base on your current using jdk version)
4) Change your web.xml file under WEB-INF directory , please refer to this article:
https://www.mkyong.com/web-development/the-web-xml-deployment-descriptor-examples/
5) Go to pom.xml file and paste these lines:
<build>
<finalName>YOUR_PROJECT_NAME</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source> THIS IS YOUR USING JDK's VERSION
<target>1.8</target> SAME AS ABOVE
</configuration>
</plugin>
</plugins>
</build>

Go to Workspace location
select your project folder
.setting folder
edit "org.eclipse.wst.common.project.facet.core"
change installed facet="jst.web" version="3.0"

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

Eclipse generates my classes three times in wtpwebapps

i had an issue with PrettyFaces framework that a class is found more than once when using eclipse to run application on server (tomcat 6)
what i found is that eclipse generates the class more than once in wtpwebapps:
\WEB-INF\classes\com\myapp\sample\beans\myclass.class
WEB-INF\classes\target\classes\com\myapp\sample\beans\myclass.class
\WEB-INF\classes\target\app-name\WEB-INF\classes\com\myapp\sample\beans\myclass.class
UPDATE:
i am using m2eclipse plugin, and using maven as my build tool, maybe there's a configuration wrong with them, or something needed to be configured.
UPDATE2:
here's the pom file build, maybe i have something wrong with it:
<build>
<finalName>appName</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>install</id>
<phase>install</phase>
<goals>
<goal>sources</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
any ideas how to fix this issue ?
I have you installed the "m2e wtp" connector ? Maven -> Discovery -> Open Catalog (in Indigo) search "wtp".
Consider using:
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
then there may not be any need for setting UTF-8 in the way you do. But maybe you have another encoding at this point, but then it would be strange to have *.java one encoding and resources in another. Best to make the whole project same.
Can you confirm if you are building a WAR and this is what you see in the WAR ? or if are using the launch Tomcat ability from Eclipse and this is what you see in the project.
Also confirm that you have used the Stop Tomcat, Clean, manually check the directory have cleared out (maybe do a workspace refresh, and another Servers -> Clean, manually delete files in Tomcat area). Then do a Full Publish (to tomcat) and then Start/Debug tomcat to launch.
I would guess if the configuration you now have is as above (and presuming no parent pom.xml is affecting the build do badly) that the files you see are a result of not cleaning the wtpwebapps area after messing around with the maven config.
There are multiple places to check gets cleaned:
Temporarly Turn off: Project -> Build Automatically
Stop All Servers instances running like: Tomcat
Run As -> Maven -> clean
Servers -> Clean
Open file browser and validate for yourself outside of Eclipse that the following dirs are empty or non-existant:
workspaceDirectory/projectDirectory/target (the maven output folder)
workspaceDirectory/metadata/.plugins/org.eclipse.wst.server.core/tmpX/wtpwebapps/**
# This one is ok to have the top level contextPath's, provind they are currently active projects you have added to the server.
$CATALINA_HOME/
Perform workspace refresh (to ensure Eclipse resync file system state to workspace state). I do this with clicking on any project in Project Explorer, then Ctrl-Clicking it again to deselect it (so nothing is selected but Project Explorer is in focus) then press F5. Other people use Ctrl-A to select all projects.
Now do a Project -> Build All
Now do a Servers -> Publish (now check the tree you get)
Now re-enable Project -> Build Automatically (if you run that way)

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!

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)