Sunday, April 28, 2024
HomeJavaThe best way to repair java.lang.ClassNotFoundException: com.solar.jersey.spi.container.servlet.ServletContainer?

The best way to repair java.lang.ClassNotFoundException: com.solar.jersey.spi.container.servlet.ServletContainer? [Solution]


The error message clearly says that the Java runtime shouldn’t be capable of finding a category known as ServletContainer for the Jersey library. That is the Servlet class you have got specified within the deployment descriptor of your software. It is much like DispatcherServlet of Spring MVC and this error is much like the error you get when DisplayServlet was not within the classpath.
Anyway, java.lang.ClassNotFoundException: com.solar.jersey.spi.container.servlet.ServletContainer comes when you find yourself attempting to make use of Jersey however haven’t added required dependency in your classpath e.g. these JAR information which include the category “com.solar.jersey.spi.container.servlet.ServletContainer”.

Btw, in case you are new to Servlet and JSP then I additionally recommend you undergo a complete course to be taught Servlet and JSP in depth. Should you want a advice then I recommend you take a look at these
Servlet and JSP on-line programs, it would assist you to to be taught Servlet and JSP from your own home or workplace. 

What’s ClassNotFoundException: com.solar.jersey.spi.container.servlet.ServletContainer? Evaluation 

Jersey is an open-source Java library, which lets you write RESTful Internet Providers in Java. Jersey 2.x implements JAX-RS 2.0 API and Jersey 2.17 is the newest launch of Jersey, however “java.lang.ClassNotFoundException: com.solar.jersey.spi.container.servlet.ServletContainer” is said to Jersey 1.x as a result of in Jersey 2.x this class is moved into one other bundle org.glassfish.jersey. So when you have configured your internet.xml like proven right here

<?xml model="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.solar.com/xml/ns/javaee" 
xmlns:internet="http://java.solar.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.solar.com/xml/ns/javaee 
http://java.solar.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" model="2.5">
<display-name>JerseyServer</display-name>
<servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.solar.jersey.spi.container.servlet.ServletContainer
    </servlet-class>
    <init-param>
        <param-name>com.solar.jersey.config.property.packages
        </param-name>
        <param-value>com.pattern.jerseydemo</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/relaxation/*</url-pattern>
</servlet-mapping>
</web-app>

however does not have Jersey 1.x dependency then you’re going to get this error.

Reason for com.solar.jersey.spi.container.servlet.ServletContainer

The error message says “com.solar.jersey.spi.container.servlet.ServletContainer” class shouldn’t be accessible within the classpath.  Now it’s good to perceive two issues, first on which JAR file this class is current and second what’s your classpath.

In case you are dealing with this drawback in a Java internet software e.g. in Tomcat, you need to do not forget that dependency JARs are loaded by the WebappClassLoader from the WEB-INF/lib listing.

So to resolve this error, you merely obtain Jersey 1.19 JAR bundle and put that in your Java internet software’s WEB-INF listing. Jersey 1.19 JAR bundle is a single-JAR Jersey bundle to keep away from the dependency administration of a number of Jersey module JARs and might be downloaded from https://jersey.java.web/obtain.html.

In case you are utilizing Maven you possibly can resolve this error by together with the next dependency in your pom.xml file. While you construct a WAR file utilizing Maven it would routinely copy all dependencies within the WEB-INF/lib folder.

One other reason for this drawback is that incorrect dependency (JAR information) in ClassPath. Some developer contains Jersey 2 JAR information and puzzled why Java continues to be complaining about “com.solar.jersey.spi.container.servlet.ServletContainer”, effectively there’s a important distinction between Jersey 1x and Jersey 2.x when it comes to this class. In Jersey 2 this class is moved from “com.solar.jersey” bundle to “org.glassfish.jersey” bundle. So even when you have downloaded Jersey 2 JAR file you’ll nonetheless get this error.

In case you are undecided tips on how to discover which JAR a selected class belongs to, you possibly can all the time use the search sort shortcut Ctrl + T to search out the JAR file offered you’re utilizing Eclipse. I’m certain different IDE like Netbeans and IntelliJ additionally has an identical shortcut, any Netbeans or IDEA lover right here to assist?

In case you are undecided the place to obtain a JAR file, go to the Maven http://repo1.maven.org/maven2/com/solar/jersey/jersey-bundle/1.17.1/jersey-bundle-1.17.1.jar

I’m utilizing Jersey 1.17 and it seems that way back to 1.12, the Servlet module is refactored into its personal jar (exterior jersey-server.jar). This new jar known as jersey-servlet.jar.

com.solar.jersey.spi.container.servlet.ServletContainer Answer

As you’re utilizing com.solar.jersey.spi.container.servlet.ServletContainer in your internet.xml as your servlet, it’s good to embrace jersey-servlet.jar in your dependencies. This may be within the type of Maven dependencies to it would get packaged contained in the struggle file.

Eclipse and Tomcat

In case you are attempting to make a Internet software to supply internet service utilizing Jersey library in Tomcat and Eclipse and nonetheless getting an issue after including jersey-server.jar within the classpath. You’ll be able to comply with these steps so as to add a dependency on deployment meeting


Undertaking -> properties -> growth meeting -> add -> java construct path entries -> maven dependency

How to fix java.lang.ClassNotFoundException: com.sun.jersey.spi.container.servlet.ServletContainer Jersey

That is all about what causes the com.solar.jersey.spi.container.servlet.ServletContainer error and tips on how to resolve com.solar.jersey.spi.container.servlet.ServletContainererror in Java internet software. As I defined, there might be two causes, incorrect classpath, the place you haven’t added jersey-servlet.jar within the classpath, or you’re utilizing jersey 2.x JAR information however have configured internet.xml for Jersey 1.x

Associated Java troubleshooting guides on your reference:

  • How to hook up with MySQL database from Java Program [steps]
  • Basic Information to resolve java.lang.ClassNotFoundException in Java [guide]
  • The best way to resolve java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver in Java? [solution]
  • The best way to resolve java.lang.UnsatisfiedLinkError: no ocijdbc11 in Java [solution]
  • The best way to repair java.lang.ClassNotFoundException: org.postgresql.Driver error in Java? [solution]
  • The best way to resolve 
  • java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory? [solution]
  • The best way to resolve java.lang.classnotfoundexception solar.jdbc.odbc.jdbcodbcdriver [solution]
  • java.web.SocketException: Too many information open java.io.IOException [solution]
  • java.web.SocketException: Did not learn from SocketChannel: Connection reset by peer [fix]
  • Exception in thread “primary” java.lang.ExceptionInInitializerError in Java Program [fix]
  • 2 methods to resolve Unsupported main.minor model 51.0 error in Java [solutions]
  • Fixing Unsupported main.minor model 52.0 Error in Java [solution]
  • java.lang.ClassNotFoundException: com.microsoft.sqlserver.jdbc.SQLServerDriver [solution
  • java.io.IOException: Map failed and java.lang.OutOfMemoryError: Map failed  [fix]
  • java.web.BindException: Can’t assign requested tackle: JVM_Bind [fix]
  • org.hibernate.MappingException: Unknown entity Exception in Java [solution]
  • Exception in thread “primary” java.lang.ArrayIndexOutOfBoundsException: 1 [solution]
  • java.lang.ClassNotFoundException:org.Springframework.Internet.Context.ContextLoaderListener [solution]
  • The best way to resolve java.lang.ClassNotFoundException: com.mysql.jdbc.Driver in Java MySQL? [solution]

Thanks for studying this text up to now. Should you discover my answer helpful, please share this text with your pals and colleagues. 



RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments