Hot questions for Using GlassFish in tomcat

Question:

I am building REST API in Java with Jersey and Maven. I used Tomcat 9 as my server. Everything works fine until I tried to install RestAssured, Hamcrest, and JUnit today. Suddenly all of my endpoints threw out 500 Internal server errors. The root cause of the 500 error is java.lang.NoClassDefFoundError: org/glassfish/jersey/internal/inject/Binder.

What I have done this 2 hours:

  • I have tried to find this class: org/glassfish/jersey/internal/inject/Binder on google, but no avail.
  • I have tried to uninstall RestAssured, Hamcrest, and JUnit but it didn't help.

This problem makes me frustrated. Any idea why this errors happened? Thanks in advance!

Here is the excerpt of the server log:

SEVERE: Allocate exception for servlet Jersey Web Application java.lang.ClassNotFoundException: org.glassfish.jersey.internal.inject.Binder at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1275) at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1109) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:178) at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:370) at javax.servlet.GenericServlet.init(GenericServlet.java:158) at org.apache.catalina.core.StandardWrapper.initServlet(StandardWrapper.java:1183) at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1099) at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:779) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:133) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96) at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:475) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140) at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:80) at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:624) at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:341) at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:498) at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66) at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:796) at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1368) at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49) at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source) at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source) at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) at java.lang.Thread.run(Unknown Source)

Below is my pom.xml file: (with RestAssured, Hamcrest, and JUnit)

<dependencies>
    <dependency>
        <groupId>org.glassfish.jersey.containers</groupId>
        <artifactId>jersey-container-servlet-core</artifactId>
        <!-- use the following artifactId if you don't need servlet 2.x compatibility -->
        <!-- artifactId>jersey-container-servlet</artifactId -->
    </dependency>
    <dependency>
        <groupId>org.glassfish.jersey.media</groupId>
        <artifactId>jersey-media-moxy</artifactId>
    </dependency>
    <dependency>
        <groupId>com.google.code.gson</groupId>
        <artifactId>gson</artifactId>
        <version>2.8.0</version>
    </dependency>
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.6</version>
    </dependency>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>4.12</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.hamcrest</groupId>
        <artifactId>hamcrest-all</artifactId>
        <version>1.3</version>
        <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>com.jayway.restassured</groupId>
        <artifactId>rest-assured</artifactId>
        <version>2.9.0</version>
        <scope>test</scope>
    </dependency>
</dependencies>

Below is my web.xml file:

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
        <param-name>jersey.config.server.provider.packages</param-name>
        <param-value>com.accelbyte.vincent.emailist.resources</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/webapi/*</url-pattern>
</servlet-mapping>

Below is my project structure:

Email list project structure


Answer:

Very likely there is a version mismatch between core Jersey and one of the Jersey extension libraries that imports that Binder class. Make sure all Jersey-related modules have explicit versions (and they match each other). Or even better, fix your versions by importing the jersey-bom. E.g.:

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.glassfish.jersey</groupId>
            <artifactId>jersey-bom</artifactId>
            <version>2.26-b03</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

After which your main <dependencies> section may omit the versions.

Question:

I am working on a very simple setup of tomcat and jersey servlet. I just noticed that servlet class constructed for every request. What I have read about servlets is that they are init() once, service() multiple times and destroy() once. Why is it not the case for my setup.

Below is my web.xml

<!DOCTYPE web-app PUBLIC
        "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
        "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <servlet>
        <servlet-name>contact-dropbox-servlet</servlet-name>
        <servlet-class>
            org.glassfish.jersey.servlet.ServletContainer
        </servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.inbhiwadi.services</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>contact-dropbox-servlet</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

And my servlet entry class looks like below:

@Path("/contact")
@Slf4j
public class ContactDropboxService {

    private ContactDAO contactDAO;

    private NotificationPublisher notificationPublisher;

    public ContactDropboxService() {
        ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
        this.contactDAO = (ContactDAO) context.getBean("contactDAO");
        this.notificationPublisher = (NotificationPublisher) context.getBean("notificationPublisher");
        log.debug("ContactDropboxService constructed one more time");
    }

    @GET
    public String greet() {
        log.info("Welcome to InBhiwadi contact services!");
        return "Welcome to InBhiwadi contact services";
    }

    @POST
    @Path("/drop")
    public Response create(Contact contact) {

        log.debug("Received contact is : [{}]", contact.toString());
        contactDAO.create(contact);
        notificationPublisher.publish(contact.toString());
        return Response.accepted("Contact dropped in box").build();
    }
}

What should I do to have single instance of ContactDropboxService serving multiple requests?


Answer:

By default Jersey will instantiate resource class per request. If you want to have just one instance of resource class you should annotate it with @Singleton. For more details you can check out this SO question

Question:

I am getting this error when i run my web application on tomcat server.

Could anyone tell me whats the issue here ?

This is my code

@Path("/robot")
public class Robot {
@POST
//@Path("/add")
@Consumes(MediaType.APPLICATION_JSON)
//@Produces(MediaType.APPLICATION_JSON)
public Response displayTemperature(ProcessModel tempData){
    System.out.println(" \n\n ");

    System.out.println( "|The temp is : "+ tempData.getTemperature() +"     "+ " Robot deployment time is " + "  "+tempData.getTime() +"  |");

    Client client = Client.create();
    WebResource webResource2 = client.resource("http://localhost:8080/RESTServer/rest/hello/run");
    ClientResponse response2 = webResource2.get(ClientResponse.class);
    if (response2.getStatus() != 200) {
        throw new RuntimeException("Failed : HTTP error code : " + response2.getStatus());
    }

    String output2 = response2.getEntity(String.class);
    System.out.println("\n<<<============  POSTING command to Robot Info Model  ============>>>");
    System.out.println(output2);
    return Response.ok(200).header("Access-Control-Allow-Origin", "*").header("Access-Control-Allow-Methods", "POST, GET, PUT, DELETE, OPTIONS").entity("POSTED").build();
} 
}

Answer:

Use maven and build your project within the required dependencies.

AS already said, add the jersey client dependency depending on the used version :

http://mvnrepository.com/artifact/com.sun.jersey/jersey-client

Example with the 1.19 version :

<dependency>
     <groupId>com.sun.jersey</groupId>
     <artifactId>jersey-client</artifactId>
     <version>1.19</version>
</dependency>

Add the previous XML code in your pom.xml file

For classpath resolution, and only if you use maven, check out this link : https://maven.apache.org/guides/introduction/introduction-to-dependency-mechanism.html

Tip : When you don't know what classpath scope to use with maven, use the compile one. But i suggest you to understand this fundamental notion

Question:

This might seem repititive but i swear i've gone through every answer on Stack overflow and nothing seems to be working for me. I'm making a file upload web service using Jersey in Eclipse Neon.

Server: I have Tomcat 8.5 on my PC (It is in C, i can put WAR files in webapps and run it) and I have GlassFish Server 4 on my eclipse.

When i run my app on any of the servers, it gives the error 404 not found:

My Package Explorer looks like this:

Earlier, i was putting org.glassfish servlet container name in web.xml, so sometimes it would end up giving the error as error 500, which was Classnot Found and i understand it is because glassfish reference works when you have jersey 2.x

I don't understand what I'm doing wrong honestly. I will literally pull out my hair now. I have been trying to this for one week. Somebody please save me from a nervous breakdown. I'm probably a Java noob but I have a submission in a few days and my graduation is on stake. HELP!

web.xml

<?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"  
   xsi:schemaLocation="http://java.sun.com/xml/ns/javaee  
   http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"  
   id = "WebApp_ID" version = "3.0"> 
   <display-name>File Upload</display-name> 
   <servlet> 
      <servlet-name>Jersey RESTful 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>com.tutorialspoint</param-value> 
      </init-param> 
   </servlet> 
   <servlet-mapping> 
      <servlet-name>Jersey RESTful Application</servlet-name> 
      <url-pattern>/rest/*</url-pattern> 
   </servlet-mapping>   
</web-app>

Answer:

Looks like you have jersey version mismatch in your project. i would recommend to go as below steps

Remove all manually added referenced libraries. We will use maven to manage the dependencies.

Use below pom.xml (Add other dependencies as per your need)

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">

  <modelVersion>4.0.0</modelVersion>

  <groupId>com.tutorialspoint</groupId>
  <artifactId>assignment</artifactId>
  <packaging>war</packaging>
  <version>1.0-SNAPSHOT</version>
  <name>assignment</name>

  <build>
    <finalName>assignment</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.5.1</version>
        <inherited>true</inherited>
        <configuration>
          <source>1.7</source>
          <target>1.7</target>
        </configuration>
      </plugin>
    </plugins>
  </build>

  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.glassfish.jersey</groupId>
        <artifactId>jersey-bom</artifactId>
        <version>${jersey.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <dependency>
      <groupId>org.glassfish.jersey.containers</groupId>
      <artifactId>jersey-container-servlet</artifactId>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.inject</groupId>
      <artifactId>jersey-hk2</artifactId>
    </dependency>
    <!-- uncomment this to get JSON support
    <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-json-binding</artifactId>
    </dependency>
    -->
    <dependency>
      <groupId>org.glassfish.jersey.media</groupId>
      <artifactId>jersey-media-multipart</artifactId>
    </dependency>
  </dependencies>
  <properties>
    <jersey.version>2.26-b09</jersey.version>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
</project>

Update the web.xml as below

<?xml version="1.0" encoding="UTF-8"?>
<!-- This web.xml file is not required when using Servlet 3.0 
container, see implementation details 
http://jersey.java.net/nonav/documentation/latest/jax-rs.html -->
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" 
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
     xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
     http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <servlet>
    <servlet-name>Jersey Web Application</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>com.quratulaind.us3<param-value>
    </init-param>
    <init-param>
      <param-name>jersey.config.server.provider.classnames</param-name>
      <param-value>org.glassfish.jersey.filter.LoggingFilter;org.glassfish.jersey.media.multipart.MultiPartFeature</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey Web Application</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>
</web-app>

Remove your resource file and add below one

package com.quratulaind.us3;

import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces; 
import javax.ws.rs.core.MediaType;

import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;

/**
 * Root resource (exposed at "myresource" path)
 */
@Path("cv")
public class MyResource {

    /**
     * Method handling HTTP GET requests. The returned object will be sent
     * to the client as "text/plain" media type.
     *
     * @return String that will be returned as a text/plain response.
     */
     @GET
     @Produces(MediaType.TEXT_PLAIN)
     public String getIt() {
         return "Got it!";
     }

     @POST
     @Path("/upload")
     @Consumes(MediaType.MULTIPART_FORM_DATA)
     public String uploadCV(
         @FormDataParam("file") InputStream uploadedInputStream,
         @FormDataParam("file") FormDataContentDisposition fileDetail) 
     {
         //saving the file object to the local disk
         saveToDisk(uploadedInputStream, fileDetail);
         return "File Uploaded Successfully";
     }//function uploadcv ends

     //Fuction to save uploaded file to disk
     private void saveToDisk(InputStream uploadedInputStream, 
         FormDataContentDisposition fileDetail) {
         String uploadedFileLocation = "D:\\University Study Stuff\\FYP\\Uploaded CVs For Project"+fileDetail.getFileName();
         try{
             OutputStream out= new FileOutputStream(new File( uploadedFileLocation));
             int read=0;
             byte[] bytes= new byte[1024];
             out=new FileOutputStream( new File(uploadedFileLocation));
             while((read=uploadedInputStream.read(bytes))!= -1){
                 out.write(bytes,0,read);
             }
             out.flush();
             out.close();

          }//try ends
          catch(IOException e)
          {e.printStackTrace();}
      }
  }

Once, these changes are done create a war package using mvn package and deploy/copy to ${TOMCAT_HOME\webapps.

Check the Sample resource is working or nor

http://localhost:8080/{CONTEXT_PATH}/rest/cv

If above is working fine, then please try your upload resource method.

P.S. I have not tested your upload code, this is your assignment and you should complete it.

Question:

Info:   WELD-000411: Observer method [BackedAnnotatedMethod] private org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider.processAnnotatedType(@Observes ProcessAnnotatedType) receives events for all annotated types. Consider restricting events using @WithAnnotations or a generic type with bounds.
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.servlet.internal.CdiExternalRequestScope is deprecated from CDI 1.1!
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionHolder is deprecated from CDI 1.1!
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.WebAppExceptionInterceptor is deprecated from CDI 1.1!
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.transaction.internal.TransactionalExceptionMapper is deprecated from CDI 1.1!
            WARN:   WELD-000146: BeforeBeanDiscovery.addAnnotatedType(AnnotatedType<?>) used for class org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider$JaxRsParamProducer is deprecated from CDI 1.1!
            Severe:   Error invoking ServletContainerInitializer org.jboss.weld.environment.servlet.EnhancedListener
            java.lang.NoClassDefFoundError: org/apache/tomcat/InstanceManager
                at java.lang.ClassLoader.defineClass1(Native Method)
                at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
                at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
                at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:1093)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1624)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1505)
                at java.lang.ClassLoader.defineClass1(Native Method)
                at java.lang.ClassLoader.defineClass(ClassLoader.java:763)
                at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
                at org.glassfish.web.loader.WebappClassLoader.findClass(WebappClassLoader.java:1093)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1624)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1505)
                at org.jboss.weld.environment.tomcat.TomcatContainer.initialize(TomcatContainer.java:43)
                at org.jboss.weld.environment.servlet.WeldServletLifecycle.initialize(WeldServletLifecycle.java:213)
                at org.jboss.weld.environment.servlet.EnhancedListener.onStartup(EnhancedListener.java:62)
                at org.apache.catalina.core.StandardContext.callServletContainerInitializers(StandardContext.java:5825)
                at com.sun.enterprise.web.WebModule.callServletContainerInitializers(WebModule.java:737)
                at org.apache.catalina.core.StandardContext.start(StandardContext.java:5722)
                at com.sun.enterprise.web.WebModule.start(WebModule.java:618)
                at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:956)
                at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:939)
                at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:684)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:2105)
                at com.sun.enterprise.web.WebContainer.loadWebModule(WebContainer.java:1750)
                at com.sun.enterprise.web.WebApplication.start(WebApplication.java:107)
                at org.glassfish.internal.data.EngineRef.start(EngineRef.java:123)
                at org.glassfish.internal.data.ModuleInfo.start(ModuleInfo.java:294)
                at org.glassfish.internal.data.ApplicationInfo.start(ApplicationInfo.java:357)
                at com.sun.enterprise.v3.server.ApplicationLifecycle.initialize(ApplicationLifecycle.java:541)
                at org.glassfish.deployment.admin.DeployCommand.execute(DeployCommand.java:542)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:549)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$2$1.run(CommandRunnerImpl.java:545)
                at java.security.AccessController.doPrivileged(Native Method)
                at javax.security.auth.Subject.doAs(Subject.java:360)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$2.execute(CommandRunnerImpl.java:544)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:575)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$3.run(CommandRunnerImpl.java:567)
                at java.security.AccessController.doPrivileged(Native Method)
                at javax.security.auth.Subject.doAs(Subject.java:360)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:566)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.doCommand(CommandRunnerImpl.java:1475)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl.access$1300(CommandRunnerImpl.java:111)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1857)
                at com.sun.enterprise.v3.admin.CommandRunnerImpl$ExecutionContext.execute(CommandRunnerImpl.java:1733)
                at com.sun.enterprise.v3.admin.AdminAdapter.doCommand(AdminAdapter.java:564)
                at com.sun.enterprise.v3.admin.AdminAdapter.onMissingResource(AdminAdapter.java:251)
                at org.glassfish.grizzly.http.server.StaticHttpHandlerBase.service(StaticHttpHandlerBase.java:166)
                at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:516)
                at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:213)
                at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:182)
                at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:156)
                at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:218)
                at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:95)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:260)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:177)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:109)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:88)
                at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:53)
                at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:524)
                at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:89)
                at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:94)
                at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:33)
                at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:114)
                at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:569)
                at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:549)
                at java.lang.Thread.run(Thread.java:748)
            Caused by: java.lang.ClassNotFoundException: org.apache.tomcat.InstanceManager
    I'm
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1659)
                at org.glassfish.web.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1505)
                ... 66 more

            Severe:   Startup of context /nrd failed due to previous errors
            Severe:   Exception during cleanup after start failed

I'm trying to deploy a war on payara5/glassfish web server. The application run with tomcat but it throws the above error when I try to deploy the war file. Clean Build project doesn't help. Why should I include a jar containing Tomcat Instance Manager class in the project when I'm deploying it on Glassfish? Which jar should I include in the project? Thanks


Answer:

Well from the StackTrace , you are using Weld with Tomcat. Using Weld in the Tomcat requires configuration in order to integrate Weld and Tomcat. However , such integration is no longer required when switching to GlassFish/Payara as they already support Weld out of the box.

So , I think you have to remove all configuration about integrating Tomcat and Weld first. I suggest you make sure to remove all the configurations mentioned here first.

Question:


Answer:

You have a mismatch in Java version on your local machine and your Ubuntu server. I think you have Java 8 on your local machine that you used to generate your war file. You should either update Java on your server or compile with a JDK 7 to generate your war file. You can use your IDE to compile with a different version.

Question:

I use xampp to open mysql and stop other services. But when I run my servlet project in netbeans it opens glassfish server, at that time in xampp, tomcat status is running. What is the reason?


Answer:

Go to xampp setings and stop the tomcat server or change its default port from 8080 to anything else. once you will change the port no. your problem will be solve.