3
votes

Perhaps not a Maven issue then. m2e / wtp issue, maybe?

Just to give a background, I set up an ICEFaces project in Eclipse and deployed it in Tomcat 7.0.30. It appears the Maven POM configuration for servlet-api.jar to be in provided scope is disregarded while deploying to Tomcat. Am I missing anything? How do I get Maven to do it right?

In the project javax.servlet-api.jar is pulled in as a transitive dependency of ICEFaces. Since Tomcat comes with it's own servlet-api.jar I marked it to be excluded and added an explicit dependency (scope:provided).

INFO: Starting Servlet Engine: Apache Tomcat/7.0.30
06-Mar-2013 10:44:05 org.apache.catalina.loader.WebappClassLoader validateJarFile INFO: validateJarFile(D:\workspaces\test-project\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\test-project\WEB-INF\lib\javax.servlet-api-3.0.1.jar) - jar not loaded. See Servlet Spec 2.3, section 9.7.2. Offending class: javax/servlet/Servlet.class
06-Mar-2013 10:44:07 com.sun.faces.config.ConfigureListener contextInitialized

Maven POM

<dependency>
  <groupId>org.icefaces</groupId>
  <artifactId>icefaces-ace</artifactId>
  <version>3.2.0</version>
  <exclusions>
    <exclusion>
      <artifactId>javax.servlet-api</artifactId>
      <groupId>javax.servlet</groupId>
    </exclusion>
  </exclusions>
</dependency>

And added a dependency with provided scope

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>javax.servlet-api</artifactId>
  <version>3.0.1</version>
  <scope>provided</scope>
</dependency>

Setup:
* Eclipse Juno
* Maven webapp project was created.
* JSF and ICEFaces facets were enabled and configured.
* Configured the Eclipse project's Deployment Assembly to deploy Maven dependencies.
* Deploying the project to Tomcat from Eclipse (Right click in servers tab> Add/Remove > add the project > Publsh)

* Update 1 *

mvn dependency:tree -Dverbose

Don't know what to do about these warnings. I'll look up on how to enable debug logging.

[INFO] Scanning for projects...  
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building test-project Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-dependency-plugin:2.1:tree (default-cli) @ test-project ---
[WARNING] The POM for org.codehaus.plexus:plexus-utils:jar:1.0.4 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details  
[WARNING] The POM for classworlds:classworlds:jar:1.1-alpha-2 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.apache.maven:maven-plugin-api:jar:2.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.apache.maven:maven-model:jar:2.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.codehaus.plexus:plexus-container-default:jar:1.0-alpha-8 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[WARNING] The POM for org.apache.maven:maven-settings:jar:2.0 is invalid, transitive dependencies (if any) will not be available, enable debug logging for more details
[INFO] com.mochapenguin:test-project:war:0.0.1-SNAPSHOT
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- org.icefaces:icefaces-ace:jar:3.2.0:compile
[INFO] |  \- org.icefaces:icefaces:jar:3.2.0:compile
[INFO] |     +- org.glassfish:javax.faces:jar:2.1.6:compile
[INFO] |     +- javax.portlet:portlet-api:jar:2.0:compile
[INFO] |     +- org.icepush:icepush:jar:3.2.0:compile
[INFO] |     |  \- javax.mail:mail:jar:1.4.1:compile
[INFO] |     |     \- javax.activation:activation:jar:1.1:compile
[INFO] |     \- com.sun.xml.fastinfoset:FastInfoset:jar:1.2.12:compile
[INFO] +- org.icefaces:icefaces-compat:jar:3.2.0:compile
[INFO] |  +- (org.icefaces:icefaces:jar:3.2.0:compile - omitted for duplicate)
[INFO] |  +- commons-beanutils:commons-beanutils:jar:1.8.0:compile
[INFO] |  +- commons-logging:commons-logging:jar:1.1:compile
[INFO] |  \- javax.servlet:jstl:jar:1.2:compile
[INFO] \- javax.servlet:javax.servlet-api:jar:3.0.1:provided
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2.440s
[INFO] Finished at: Wed Mar 06 13:24:47 GMT 2013
[INFO] Final Memory: 6M/120M
[INFO] ------------------------------------------------------------------------

* Update 2 *

I had the following version installed in Juno:

m2e - Maven Integration for Eclipse 1.3.0.**20130129-0926** org.eclipse.m2e.feature.feature.group   Eclipse.org - m2e

Added the link in the answer on the post pointed to by @eis Did a Check for updates. Eclipse showed there was a minor update available (1.3.1.20130219-1424). But the update failed with the following error:

An error occurred while collecting items to be installed
session context was:(profile=epp.package.jee, phase=org.eclipse.equinox.internal.p2.engine.phases.Collect, operand=, action=).
No repository found containing: osgi.bundle,com.ning.async-http-client,1.6.5.20130219-0923
No repository found containing: osgi.bundle,org.eclipse.m2e.archetype.common,1.3.1.20130219-0923
No repository found containing: osgi.bundle,org.eclipse.m2e.core,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.core.ui,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.discovery,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.editor,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.editor.xml,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.jdt,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.launching,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.lifecyclemapping.defaults,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.maven.indexer,1.3.1.20130219-0923
No repository found containing: osgi.bundle,org.eclipse.m2e.maven.runtime,1.3.1.20130219-0923
No repository found containing: osgi.bundle,org.eclipse.m2e.model.edit,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.refactoring,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.eclipse.m2e.scm,1.3.1.20130219-1424
No repository found containing: osgi.bundle,org.jboss.netty,3.2.5.Final-20130219-0923
No repository found containing: org.eclipse.update.feature,org.eclipse.m2e.feature,1.3.1.20130219-1424

So, I uninstalled the existing m2e and reinstalled it. This worked. Also included

m2e - slf4j over logback logging (Optional) 1.3.1.20130219-1424 org.eclipse.m2e.logback.feature.feature.group   Eclipse.org - m2e

But the issue remains. Juno is still deploying javax.servlet-api3.0.1.jar :(


Solved

(Disclaimer first: This is my understanding. Happy to be corrected)

It appears m2e + m2e extras (not sure if they are separate entities still, or just m2e) was already installed with Juno. I had to install m2e - wtp connector for things to work properly. Maven scopes are now honoured.

Install m2e-wtp connector: In Juno - Window > Preferences > Maven > Discovery > Open Catalog > Select the check box against m2e-wtp connector to install it. This adds the following to the installed software

m2e-wtp - Maven Integration for WTP (Incubation)    0.17.0.20130212-1821    org.eclipse.m2e.wtp.feature.feature.group   Eclipse.org - m2e-wtp
3
how you are building war file?NPKR
I am not building a war file. I have a Tomcat 7.0.30 server configured in Eclipse. I right click on the Tomcat server entry in the Servers tab > Add / Remove add the project, publish and start Tomcat. The jar file gets deployed with other dependencies although in this case it is marked as provided.JetStream
Could you show your mvn dependency:tree -Dverbose?carlspring
Added to the original post above (Update 1)JetStream

3 Answers

0
votes

To me, this is not a Maven issue. Maven gets that servlet-api is provided, but you're not deploying or building a package through maven, you're only compiling with maven (and doing that through m2e perhaps) and deploying through Eclipse. m2e/eclipse should handle this issue but isn't.

According to this similar thread, installing m2e + m2e-extras should fix it. Also see the other answers for more details on Eclipse behavior.

0
votes

Your <artifactId/> is wrong in both places.

  • The tag ordering convention (which, of course is not enforced strictly) is to define artifacts' and exclusions' tags in the following ordering groupId, artifactId, version, type, classifier, scope. Yours is artifactId, groupId. I suggest you correct this and follow the convention for readability's sake.

  • Change your exclusion as follows:

    <dependency>
        <groupId>org.icefaces</groupId>
        <artifactId>icefaces-ace</artifactId>
        <version>3.2.0</version>
        <exclusions>
            <exclusion>
                <groupId>javax.servlet</groupId>
                <artifactId>servlet-api</artifactId>
            </exclusion>
        </exclusions>
    </dependency>
    
  • Change your dependency to:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>
    
0
votes

I am using Eclipse Juno and installing "m2e - wtp" plugin solved my problem too.