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

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)

Related

Lombok does not generate Methods

I'm trying to use Lombok in a Maven project with Java 8, but Lombok doesn't generate any Getters and Setters when I apply the #Data Annotation. I tried to use Maven Compiler Plugin Version 3.5 as mentioned here, but it didn't help. Does anybody have I clue, which versions I need to use?
pom.xml
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.14</version>
<scope>provided</scope>
</dependency>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
The answer is described in this thread.
Download Lombok JAR from here.
Doubleclick the JAR and install it in your Eclipse installation directory
Restart Eclipse and check whether you can find this text: Help > About Eclipse > "Lombok vX.XX.XX is installed. https://projectlombok.org/". It should be found somewhere in the about text.
Open eclipse.ini in your Eclipse installation directory and add following lines at the end. (if they do not already exist)
-javaagent:lombok.jar
-Xbootclasspath/a:lombok.jar

Dynamic Web Module 3.0 -- 3.1

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"

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!

Question Regarding External Jars and MAVEN

I have two GWT projects Project A and Project B.The dependencies of these projects are taken care by MAVEN.Project B depends on Project A ,and this part is already taken care of.
Now i need to add an external Jar into Project A.I do not want to use Maven for this .I just want to add the external jar file into Project A and update my ProjectA.gwt.xml to inherit the jar.
So i included the jar file in Project A.But Project B was not recognizing the classes in the jar.So i went ahead and followed the following steps
1) Right Clicked on Project A and selected Build Path
2) Click on Configure Build Path
3) Order and Export the jar file
Then after doing so ,my Project B could compile the classes used from the JAR file.But at Runtime its crashing.Its not able to recognize the classes from the JAR file.
Can anyone provide me what to do on this?
Please provide me solution with/without using MAVEN.I would prefer without using MAVEN.
Thanks
I think you should keep all the dependency management in Maven.
The Eclipse Maven plugin manage the Build Path Configuration of your Eclipse project, it should be not modified manually.
You could use this configuration to add external librairies to the repository :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>deploy-on-local-repo1</id>
<phase>generate-sources</phase>
<goals>
<goal>install-file</goal>
</goals>
<inherited>false</inherited>
<configuration>
<file>src/your-librairie.jar</file>
<groupId>com.yourlibrairiegroupID</groupId>
<artifactId>librairie-name</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
</execution>
</executions>
</plugin>
Hope it will fix your problem.