Eclipse WTP 在 Tomcat 服务器中部署依赖项的奇怪行为

发布于 2024-10-28 03:48:14 字数 3276 浏览 0 评论 0原文

我的 Eclipse WTP 在 Tomcat 部署过程中有一个奇怪的行为。 我正在使用 Eclipse 3.7 (Indigo)、WTP 3.3、 m2eclipse 插件、Java 1.6、Tomcat 5.5。

我的应用程序是一个 Web 应用程序,有一些其他项目作为依赖项,以及一些第三方依赖项。 我的项目由 Maven 管理,当我们使用这个工具构建应用程序时一切正常。

为了使用 Eclipse 处理我的项目,我运行 mvn eclipse:clean eclipse:eclipse,然后在 IDE 中导入我的项目。

当我想在 Tomcat 5.5 服务器(该服务器由 Eclipse 管理)上部署此 Web 应用程序时,就会出现问题。 当我创建一个新的 Tomcat 服务器并在其中部署我的 my-project-portal 应用程序时,它只添加 my-project-xxx 依赖项,以及第三个依赖项- 各方依赖关系(大约定义了数百个中的 9 个)。 在我的一位同事桌面上(他使用的是 Eclipse 3.5),根本没有部署第三方依赖项,只有 my-project-xxx JAR...

但是,当我查看网络时-app 项目属性,在Java 构建路径> 中库,或在“部署程序集”中,依赖项列表正确且完整。

注释

我使用较旧的 Eclipse(3.3,使用 WTP 3.1)进行了一些测试,没有遇到任何部署问题。 然而,这个WTP仍然使用“Java EE模块依赖关系”,这与最新WTP版本的情况不同。

到目前为止,我们在 mvn eclipse:eclipse 之后使用了一个自定义 Maven 插件,它将所有依赖项(包括传递依赖项)复制到 my-webapp-project/WebContent/WEB-INF/lib< /代码>。 这样,Eclipse就会自动部署这些依赖项的内容,这样我们就得到了Tomcat服务器中的所有依赖项。

问题

  • 我的流程出了什么问题?
  • 我真的需要复制 WEB-INF/lib 目录中的所有依赖项吗?
  • 当我们想要使用 Eclipse 在 Tomcat 服务器上部署 Web 应用程序时,正常过程是什么?

以下是运行 mvn eclipse:eclipse 后我的 Eclipse 配置文件的摘录:

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" sourcepath="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar"/>
    <classpathentry kind="var" path="M2_REPO/asm/asm/2.2.2/asm-2.2.2.jar" sourcepath="M2_REPO/asm/asm/2.2.2/asm-2.2.2-sources.jar"/>
    <classpathentry kind="src" path="/my-project-business"/>
    ...
    <classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
</classpath>

.settings/org.eclipse.wst.common.component

<project-modules id="moduleCoreId" project-version="1.5.0">
  <wb-module deploy-name="my-project-portal">
    <property name="context-root" value="my-project-portal"/>
    <wb-resource deploy-path="/" source-path="/WebContent"/>
    <property name="java-output-path" value="/WebContent/WEB-INF/classes"/>
    <dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/var/M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar">
      <dependency-type>uses</dependency-type>
    </dependent-module>
    ...
    <dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/my-project-business/my-project-business">
      <dependency-type>uses</dependency-type>
    </dependent-module>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
  </wb-module>
</project-modules>

I have a strange behavior in the Tomcat deployment process made by my Eclipse WTP.
I am using Eclipse 3.7 (Indigo), WTP 3.3, no m2eclipse plugin, Java 1.6, Tomcat 5.5.

My application is a web application that have some other projects as dependencies, as well as some third-parties dependencies.
My project is managed by Maven, and everything works fine when we build the application using this tool.

To work on my project using Eclipse, I run mvn eclipse:clean eclipse:eclipse and then, I import my projects in the IDE.

My problem occurs when I want to deploy this web application on a Tomcat 5.5 server (this server is managed by Eclipse).
When I create a new Tomcat server, and deploy my my-project-portal application in it, it only adds the my-project-xxx dependencies, as well as few third-parties dependencies (about 9 of the hundreds defined).
On one of my colleagues desktop (he is using Eclipse 3.5), no third-parties dependency are deployed at all, just the my-project-xxx JAR...

However, when I look at the web-app project properties, in Java Build Path > Libraries, or in "Deployment Assembly", the list of dependencies is correct and complete.

Notes

I did some tests with an older Eclipse (3.3, with WTP 3.1) and I do not encounter any deployment issue.
However, this WTP was still using the "Java EE Modules Dependencies", which is not the case of the latest WTP version.

Until now, we used a custom Maven plugin after the mvn eclipse:eclipse that copies all the dependencies (including transitives ones) into my-webapp-project/WebContent/WEB-INF/lib.
Doing that, Eclipse automatically deployed the content of these dependencies, and thus, we got all the dependencies in the Tomcat server.

Questions

  • What is wrong with my process?
  • Do I really need to copy all the dependencies in the WEB-INF/lib directory?
  • What is the normal procedure when we want to deploy a web application on a Tomcat server, using Eclipse?

Here is an extract of my Eclipse configuration files after running mvn eclipse:eclipse:

.classpath

<?xml version="1.0" encoding="UTF-8"?>
<classpath>
    <classpathentry kind="src" path="src/main/java"/>
    <classpathentry excluding="**/*.java" kind="src" path="src/main/resources"/>
    <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER"/>
    <classpathentry kind="var" path="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar" sourcepath="M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0-sources.jar"/>
    <classpathentry kind="var" path="M2_REPO/asm/asm/2.2.2/asm-2.2.2.jar" sourcepath="M2_REPO/asm/asm/2.2.2/asm-2.2.2-sources.jar"/>
    <classpathentry kind="src" path="/my-project-business"/>
    ...
    <classpathentry kind="output" path="WebContent/WEB-INF/classes"/>
</classpath>

.settings/org.eclipse.wst.common.component

<project-modules id="moduleCoreId" project-version="1.5.0">
  <wb-module deploy-name="my-project-portal">
    <property name="context-root" value="my-project-portal"/>
    <wb-resource deploy-path="/" source-path="/WebContent"/>
    <property name="java-output-path" value="/WebContent/WEB-INF/classes"/>
    <dependent-module deploy-path="/WEB-INF/lib" handle="module:/classpath/var/M2_REPO/aopalliance/aopalliance/1.0/aopalliance-1.0.jar">
      <dependency-type>uses</dependency-type>
    </dependent-module>
    ...
    <dependent-module deploy-path="/WEB-INF/lib" handle="module:/resource/my-project-business/my-project-business">
      <dependency-type>uses</dependency-type>
    </dependent-module>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/java"/>
    <wb-resource deploy-path="/WEB-INF/classes" source-path="src/main/resources"/>
  </wb-module>
</project-modules>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

谷夏 2024-11-04 03:48:14

我认为你有一个配置错误的问题,因为:

  • 如果你的项目是由 Maven 管理的,你将永远不需要使用该工具所需的依赖项设置“.classpath”,例如,如果你需要一个不同的库或更改一个库的版本,您将需要更新 eclipse 项目中的配置等。同上,您的 'org.eclipse.wst.common.component' 文件。

我认为您需要像 @stivlo 所说的那样安装 m2eclipse 的 WTP 支持,当然安装 m2eclipse 并检查您的项目配置,因为您需要删除这些文件中定义的所有依赖项。

现在,我从不复制 /WEB-INF/lib 目录中的所有依赖项,因为我不想密切关注这些目录。例如,当我需要启动Tomcat时,m2eclipse插件会自动部署Eclipse内部相关目录中的所有库和差异(即静态文件,类,资源文件等),仅此而已,服务器以上下文启动,以及所需的所有文件。为了方便起见,我总是使用 Eclipse 中的相关插件。

I think you have a misconfiguration problem because:

  • If your project is managed by maven, you will never need to set your '.classpath' with the dependencies needed by this tool, for example if you need one different library or change the version of one, you will need to update the configuration in your eclipse project, etc. Idem for your 'org.eclipse.wst.common.component' file.

I think you will need to install the WTP support for m2eclipse like @stivlo says, of course install the m2eclipse and review your project configuration, because you need to remove all the dependencies defined in those files.

Right now, I never copy all the dependencies in the /WEB-INF/lib directory, because I don't want to have to keep an eye on those directory. For example, when I need to start Tomcat, the m2eclipse plug-in deploys automatically all the libraries and differences (i.e static files, classes, resource files, etc) in the internal Eclipse directory related and that's it, the server starts with the context, with all the files needed. I'm always using the plugins related in Eclipse for convenience.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文