Results 1 to 14 of 14
  1. #1
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default maven Application dosen't work , error: Servlet.init() for servlet

    Hallo,

    i wrote yesterday a web application and it works very well, today i tried to make the same appliction but with maven, so every time i run the the project i get the following error:
    XML Code:
    description The server encountered an internal error () that prevented it from fulfilling this request.
    
    exception
    
    javax.servlet.ServletException: Servlet.init() for servlet Jersey Web Application threw exception
    	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    	java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	java.lang.Thread.run(Unknown Source)
    root cause
    
    com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
    	com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99)
    	com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1331)
    	com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:168)
    	com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:774)
    	com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:770)
    	com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193)
    	com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:770)
    	com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:765)
    	com.sun.jersey.spi.container.servlet.ServletContainer.initiate(ServletContainer.java:489)
    	com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:319)
    	com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605)
    	com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:210)
    	com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:374)
    	com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:557)
    	javax.servlet.GenericServlet.init(GenericServlet.java:160)
    	org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:462)
    	org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:100)
    	org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:562)
    	org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:395)
    	org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:250)
    	org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:188)
    	org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:302)
    	java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    	java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    	java.lang.Thread.run(Unknown Source)
    note The full stack trace of the root cause is available in the Apache Tomcat/7.0.12 logs.
    the pom.xml
    Java Code:
      <dependencies>
      	<dependency>
      		<groupId>org.apache.poi</groupId>
      		<artifactId>poi</artifactId>
      		<version>3.9</version>
      	</dependency>
      	      <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
          </dependency>
          <dependency>
    	<groupId>org.json</groupId>
    	<artifactId>json</artifactId>
    	<version>20090211</version>
    </dependency>
    <dependency>
    	<groupId>org.apache.poi</groupId>
    	<artifactId>poi-ooxml</artifactId>
    	<version>3.10-beta1</version>
    </dependency>
    <dependency>
    	<groupId>javax.ws.rs</groupId>
    	<artifactId>jsr311-api</artifactId>
    	<version>1.1-ea</version>
    </dependency>
       <dependency>
                	<groupId>asm</groupId>
                	<artifactId>asm</artifactId>
                	<version>3.1</version>
       </dependency>
       <dependency>
    	<groupId>com.sun.jersey</groupId>
    	<artifactId>jersey-bundle</artifactId>
    	<version>1.17.1</version>
    </dependency>
     <dependency>
    	<groupId>javax.ws.rs</groupId>
    	<artifactId>javax.ws.rs-api</artifactId>
    	<version>2.0-m03</version>
    </dependency>
    <dependency>
    	<groupId>org.apache.axis</groupId>
    	<artifactId>axis</artifactId>
    	<version>1.4</version>
    </dependency>
                <dependency>
    	<groupId>asm</groupId>
    	<artifactId>asm-all</artifactId>
    	<version>2.2</version>
    </dependency>
                <dependency>
    	<groupId>com.sun.jersey</groupId>
    	<artifactId>jersey-core</artifactId>
    	<version>1.17.1</version>
    </dependency>
                <dependency>
    	<groupId>org.glassfish.jersey.containers</groupId>
    	<artifactId>jersey-container-servlet</artifactId>
    	<version>2.0-m04</version>
    </dependency>
                <dependency>
    	<groupId>com.sun.jersey</groupId>
    	<artifactId>jersey-servlet</artifactId>
    	<version>1.17.1</version>
    </dependency>
                
                <dependency>
    	<groupId>com.sun.jersey</groupId>
    	<artifactId>jersey-server</artifactId>
    	<version>1.17.1</version>
    </dependency>
                <dependency>
    	<groupId>org.glassfish.jersey.core</groupId>
    	<artifactId>jersey-common</artifactId>
    	<version>2.0-m01</version>
    </dependency>
                <dependency>
    	<groupId>org.glassfish.jersey.containers</groupId>
    	<artifactId>jersey-container-servlet-core</artifactId>
    	<version>2.0</version>
    </dependency>
                <dependency>
    	<groupId>com.sun.jersey</groupId>
    	<artifactId>jersey-bundle</artifactId>
    	<version>1.17.1</version>
    </dependency>
      <dependency>
    		<groupId>com.sun.jersey</groupId>
    		<artifactId>jersey-json</artifactId>
    		<version>1.8</version>
    	</dependency>
    	<dependency>
          <groupId>junit</groupId>
          <artifactId>junit</artifactId>
          <version>3.8.1</version>
          <scope>test</scope>
        </dependency>
        <dependency>
        <groupId>org.apache.tomcat</groupId>
        <artifactId>tomcat-servlet-api</artifactId>
        <version>7.0.26</version>
        <scope>provided</scope>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-api</artifactId>
        <version>1.6.4</version>
      </dependency>
      <dependency>
        <groupId>log4j</groupId>
        <artifactId>log4j</artifactId>
        <version>1.2.14</version>
      </dependency>
      <dependency>
        <groupId>org.slf4j</groupId>
        <artifactId>slf4j-log4j12</artifactId>
        <version>1.6.4</version>
      </dependency>
      </dependencies>
      <repositories>
    		<repository>
    			<id>maven2-repository.java.net</id>
    			<name>Java.net Repository for Maven</name>
    			<url>http://download.java.net/maven/2/</url>
    			<layout>default</layout>
    		</repository>
    	</repositories>
    	
    	<build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                        <showDeprecation>true</showDeprecation>
                        <showWarnings>true</showWarnings>
                        <executable>${env.JAVA_7_HOME}/bin/javac</executable>
                        <fork>true</fork>
                    </configuration>
                </plugin>
                <plugin>
    			<groupId>org.apache.maven.plugins</groupId>
    			<artifactId>maven-war-plugin</artifactId>
    			<configuration>
    				<webResources>
    					<resource>
    						<directory>${basedir}/src/main/java</directory>
    						<targetPath>WEB-INF/classes</targetPath>
    						<includes>
    							<include>**/*.properties</include>
    							<include>**/*.xml</include>
    							<include>**/*.css</include>
    							<include>**/*.html</include>
    						</includes>
    					</resource>
    				</webResources>
    			</configuration>
    		</plugin>
            </plugins>
        </build>
    web.xml
    Java Code:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
      
      <servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
                
    
            <init-param>
              <param-name>com.sun.jersey.config.property.packages</param-name>
              <param-value>pal.restfulservice</param-value>
            </init-param>
        
        <load-on-startup>1</load-on-startup>
      </servlet>
      
      <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/maven/*</url-pattern>
      </servlet-mapping>
      
      <session-config>
        <session-timeout>30</session-timeout>
      </session-config>
    </web-app>
    i don't have any idea why that happend, but i thing there are some type of conflict in pom.xml in dependencies, but i am not sure

    any idea?

  2. #2
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,100
    Rep Power
    4

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    You get a startup problem from Jersey complaining about the configuration and you blame it on Maven? Poor Maven.

    What that error seems to vaguely want to tell you is that the pal.restfulservice you refer to in your web.xml is not properly deployed to the server. Error research 101: copy paste the error "com.sun.jersey.api.container.ContainerExcepti on: The ResourceConfig instance does not contain any root resource classes." into google and see what you get.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  3. #3
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    ok when it is not problem of the Maven, why the same application, the same code and the same web.xml works perfectly in normal web application?

  4. #4
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,100
    Rep Power
    4

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    because either

    a) you're mistaken and it is not exactly the same

    or

    b) something else is wrong

    For example in the project settings of the IDE you're using. You have to find what it is. Like I said - it LOOKS like a particular class is not deployed to the server, or the web.xml contains a typo.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  5. #5
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    Hi Erik, thank you for your hints.

    any way i tried again and i got another error, this time:
    Java Code:
    java.lang.NoClassDefFoundError: org/apache/poi/hssf/usermodel/HSSFWorkbook
    Although i added all jar of "Poi" in my pom.xml

    i searched later in google and found a strange solution " add poi-3.9.jar as jar in folder lib (scr --> main --> webaap --> WEB-INF --> lib)
    so i did it an i works very well

    but the question right now hot it comes, it is maven, we don't need to add any jar but just in pom.xml

    how can i solve it?

  6. #6
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,100
    Rep Power
    4

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    Look, there are two totally different trajectories here.

    a) BUILDING the application; Maven is helping you there
    b) DEPLOYING the application (to the server). There is a plugin for Maven that also allows it to deploy an application, but I am 99% sure you are not using that

    So the deploying part is entirely your responsibility. Likely you are using an IDE to deploy the stuff for you, but then you have to be sure the IDE is setup correctly to do the deployment properly so it puts all the files in the correct position, including the libraries that Maven collected for you.

    In other words: it is not automatic, you need to know how your tools work.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  7. #7
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    thanks again Erik,

    it is right i don't use extra plugin for Maven that allows it to deploy the application, because that i am totally new with maven and have project already too late.
    can you help me which plugin in this case should i add to pom.xml?

    only plugins that i used are:
    Java Code:
    <build>
            <plugins>
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <configuration>
                        <source>1.7</source>
                        <target>1.7</target>
                        <showDeprecation>true</showDeprecation>
                        <showWarnings>true</showWarnings>
                        <executable>${env.JAVA_7_HOME}/bin/javac</executable>
                        <fork>true</fork>
                    </configuration>
                </plugin>
                <plugin>
    			<groupId>org.apache.maven.plugins</groupId>
    			<artifactId>maven-war-plugin</artifactId>
    			<configuration>
    				<webResources>
    					<resource>
    						<directory>${basedir}/src/main/java</directory>
    						<targetPath>WEB-INF/classes</targetPath>
    						<includes>
    							<include>**/*.properties</include>
    							<include>**/*.xml</include>
    							<include>**/*.css</include>
    							<include>**/*.html</include>
    						</includes>
    					</resource>
    				</webResources>
    			</configuration>
    		</plugin>
            </plugins>
        </build>
    anothers i don't know and i don't know why and how

  8. #8
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,100
    Rep Power
    4

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    No I can't, and making Maven deploy stuff to a server for you is not going to make your problems go away.

    So in stead of going back to Maven time and again, explain this: HOW are you deploying the application? The problem is there, so if you want help tell what you're doing.
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  9. #9
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    I just run the Tomcat 7 server an write the URL in the website, nothing else

  10. #10
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,100
    Rep Power
    4

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    The application does not magically appear in your Tomcat server, how does it get there and in what form? Do you deploy individual files to the webapps folder, or do you put the war that Maven builds there?
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  11. #11
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    I don't understand totally, but at first i create Maven Project then write the code and the web.xml, then difine the dependencies and the Plugins in pom.xml

    At last i run it from Tomcat server, which already installed in my eclipse

    ps: i dont create any war file and didn't use any maven goals like mvn clean oder mvn package

  12. #12
    gimbal2 is online now Just a guy
    Join Date
    Jun 2013
    Location
    Netherlands
    Posts
    3,100
    Rep Power
    4

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    In other words Eclipse does the deployment for you. I return to my earlier statement: somewhere in your Eclipse project setup there is a flaw. Did you even create an Eclipse project with Maven capabilities?

    I can't help you any further like this, because you simply don't know the tools you're using I feel like I'm speaking Chinese to you. I wrote an article with screenshots and everything about how to deploy a JSF based application from Eclipse to Tomcat where the project is Mavenized, perhaps following that you can spot what you missed.

    Java Enterprise Stuff: JSF 2.1 and JPA 2 on Tomcat 7


    And I also wrote an Article about setting up a Mavenized project in Eclipse, although that doesn't cover deployment (since that's server and project specific):

    Java Enterprise Stuff: Using Maven in Eclipse
    "Syntactic sugar causes cancer of the semicolon." -- Alan Perlis

  13. #13
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    19

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    I suspect you are making a common mistake.
    The tools aren't there to do the job for you so you don't have to understand what is going on.
    You need to understand what is involved with a webapp, what the various parts are and what they do, before you should consider letting something like Eclipse (or Maven) do it all for you. That way you know what the thing is doing and, when it goes wrong, what exactly is wrong.

    It's a bit like people jumping into coding in an IDE without the faintest idea of what a classpath is and how it affects Java.
    Please do not ask for code as refusal often offends.

  14. #14
    vector_ever is offline Senior Member
    Join Date
    Jul 2013
    Posts
    106
    Rep Power
    0

    Default Re: maven Application dosen't work , error: Servlet.init() for servlet

    Anyway that is just misunderstanding, i know how to build project with Maven and i did it yesterday an it worked

    I followed your articles (really great work) but i did it exactly as your explanation in the article.

    again Erik, i appreciate your help
    thank you very much

Similar Threads

  1. Replies: 1
    Last Post: 08-23-2011, 11:12 AM
  2. HTTP 404 Error while running Servlet Application
    By shuklajayb in forum Java Servlet
    Replies: 3
    Last Post: 06-24-2009, 05:19 PM
  3. Replies: 1
    Last Post: 12-02-2008, 12:23 AM
  4. Replies: 1
    Last Post: 08-07-2007, 03:47 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •