Eclipse:无法将jar加载到Tomcat WEB-INF / Lib文件夹中? [英] Eclipse : Unable to load jar's into the Tomcat WEB-INF/Lib folder ?

查看:141
本文介绍了Eclipse:无法将jar加载到Tomcat WEB-INF / Lib文件夹中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用eclipse运行Tomcat时,我得到这个tomcat错误java.lang.ClassNotFoundException:org.glassfish.jersey.servlet.ServletContainer:



I看到eclipse不包括jar()的WEB-INF / Lib文件夹,尽管我试过这个:


  1. 在项目属性下的Web部署程序集中包含Maven依赖项。 (Maven下载了POM.xml中的依赖关系,但是这些jar没有被eclipse接收)



    POM.xml如下所示:


 < project xmlns =http://maven.apache.org/POM/4.0.0xmlns :xsi =http://www.w3.org/2001/XMLSchema-instancexsi:schemaLocation =http://maven.apache.org/POM/4.0.0 http://maven.apache.org/ XSD /行家-4.0.0.xsd> < modelVersion> 4.0.0< / modelVersion> <&的groupId GT; com.dcr.javacode.rest.jersey< /&的groupId GT; < artifactId的> JAXRS-HelloJerseyExample< / artifactId的> <版本> 0.0.1-快照LT; /版本> <库> <库> < ID> maven2-repository.java.net< / ID> < name>用于Maven的Java.net Repository< / name> < URL> HTTP://download.java.net/maven/2/< / URL> <布局>默认< /布局> < /储存库> < /储存库> <依赖性> <依赖性> <&的groupId GT; org.glassfish.jersey.core< /&的groupId GT; < artifactId的> Jersey的服务器16; / artifactId的> <版本> 2.17< /版本> < /依赖性> < / dependencies>< / project>  



web.xml如下:



 <?xml version =1.0encoding =UTF-8?>< web-app xmlns: xsi =http://www.w3.org/2001/XMLSchema-instancexmlns =http://java.sun.com/xml/ns/javaeexmlns:web =http://java.sun .com / xml / ns / javaee / web-app_2_5.xsdxsi:schemaLocation =http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee /web-app_3_0.xsdid =WebApp_IDversion =3.0> <显示-名称> JAXRS-HelloJerseyExample< /显示名称> < servlet的> < servlet的名称>&JerseyRESTService LT; / servlet的名称> < servlet的类> org.glassfish.jersey.servlet.ServletContainer< / servlet的类> < INIT-PARAM> < PARAM-名称>&jersey.config.server.provider.packages LT; / PARAM-名称> < PARAM值> com.dcr.javacode.rest.jersey< / PARAM值> < / INIT-PARAM> <负载上启动→1< /负载上启动> < / servlet的> < servlet的映射> < servlet的名称>&JerseyRESTService LT; / servlet的名称> < URL模式> /休息/ * LT; / url-pattern的> < / servlet的映射> < / web-app>  

解决方案


  1. 你缺少< packaging> 元素在pom文件。如果要部署到servlet容器,那么包应该是 war 。默认值为 jar

  2. 您正在使用 jersey-server t有 ServletContainer 。而是使用 jersey-container-servlet

但是...



开始使用泽西的最简单的方法是使用Maven原型。



在Eclipse中:


  1. [ code>]→ []→ [其他]

  2. [ Maven ]→ [ Maven Project ]→ Next

  3. 保留默认值(确保创建一个简单的项目未选中)→ 下一页 / li>
  4. 在下一个对话框中的过滤器字段中,键入 jersey-quickstart-webapp 。可能需要一些时间才能加载所有原型,您可以在IDE右下角的一个进度条中看到原型加载的进度,如果没有看到进度条,没有搜索结果,那么很可能你不会具有原型,在这种情况下,请按照此答案第一部分中的说明

  5. 选择 org.glassfish.jersey.archetypes 版本,它应该默认为最新版本(此时为2.17)→ 下一页

  6. 输入您的groupId,artifactId和package→ 完成


$ b $这应该会让你运行一个运行的泽西启动程序,这将运行在Tomcat上


I'm getting this tomcat error " java.lang.ClassNotFoundException:org.glassfish.jersey.servlet.ServletContainer" when I run Tomcat using eclipse :

I see that eclipse does not include the jars into the (tomcat 7.0) WEB-INF/Lib folder, though I tried this :

  1. Included the Maven dependencies in "Web Deployment Assembly" under Project properties. ( Maven downloaded the dependencies in the POM.xml , but these jars are not getting picked up by eclipse )

    The POM.xml as follows:

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.dcr.javacode.rest.jersey</groupId>
  <artifactId>JAXRS-HelloJerseyExample</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  
  <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>
  
  <dependencies>
    	<dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>2.17</version>
        </dependency>        
  </dependencies>
</project>

web.xml as follows :

<?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_3_0.xsd" id="WebApp_ID" version="3.0">
  <display-name>JAXRS-HelloJerseyExample</display-name>
 	<servlet>
    	<servlet-name>JerseyRESTService</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.dcr.javacode.rest.jersey</param-value>
    	</init-param>
    	
    	<load-on-startup>1</load-on-startup>
  	</servlet>
  	<servlet-mapping>
    	<servlet-name>JerseyRESTService</servlet-name>
    	<url-pattern>/rest/*</url-pattern>
  	</servlet-mapping> 	
</web-app>

解决方案

Couple things I see wrong.

  1. You are missing the <packaging> element in the pom file. If this is to be deployed to a servlet container, then the package should be war. The default is jar
  2. You are using jersey-server which doesn't have the ServletContainer. Instead use jersey-container-servlet

But...

The easiest way to get started with Jersey is to use a Maven archetype.

In Eclipse:

  1. [File] → [New] → [Other]
  2. [Maven] → [Maven Project] → Next
  3. Keep defaults (make sure "Create a simple project is unchecked) → Next
  4. In the next dialog, in the "Filter" field, type jersey-quickstart-webapp. It might take a few moments to load all the archetypes. You can see the progress of the archetypes loading in a little progress bar at the very bottom right of the IDE. If you don't see the progress bar and there are no search results, then most likely you don't have the archetypes. In that case, follow the instructions in the first part of this answer
  5. Select the org.glassfish.jersey.archetypes version. It should default to the latest version (at this time it's 2.17) → Next
  6. Type in your groupId, artifactId, and package → Finish

That should get you a running Jersey starter app, that will run on Tomcat

这篇关于Eclipse:无法将jar加载到Tomcat WEB-INF / Lib文件夹中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆