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

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

问题描述

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

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

我看到 eclipse 没有将 jars 包含到 (tomcat 7.0) WEB-INF/Lib 文件夹中,尽管我试过这个:

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

  1. 在项目属性下的Web 部署程序集"中包含 Maven 依赖项.(Maven 下载了 POM.xml 中的依赖项,但这些 jars 没有被 eclipse 获取)

  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 )

POM.xml 如下:

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>

<?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>

推荐答案

我看错了几件事.

  1. 您在 pom 文件中缺少 元素.如果要将其部署到 servlet 容器,则该包应为 war.默认为 jar
  2. 您正在使用没有 ServletContainerjersey-server.而是使用 jersey-container-servlet
  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

但是...

开始使用 Jersey 的最简单方法是使用 Maven 原型.

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

在 Eclipse 中:

In Eclipse:

  1. [文件] →[] →[其他]
  2. [Maven] →[Maven 项目] →下一步
  3. 保持默认值(确保创建一个简单的项目未选中)→下一步
  4. 在下一个对话框的过滤器"字段中,输入 jersey-quickstart-webapp.加载所有原型可能需要一些时间.您可以在 IDE 右下角的小进度条中看到原型加载的进度.如果您没有看到进度条并且没有搜索结果,那么很可能您没有原型.在这种情况下,请按照此答案
  5. 第一部分中的说明进行操作
  6. 选择org.glassfish.jersey.archetypes 版本.它应该默认为最新版本(此时是 2.17) →下一步
  7. 输入您的 groupId、artifactId 和包 →完成
  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

这应该会给你一个正在运行的 Jersey 启动应用程序,它将在 Tomcat 上运行

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

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

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