如何在 Hudson 中构建 Eclipse 动态 Web 项目

发布于 2024-12-11 11:07:27 字数 137 浏览 0 评论 0原文

我在 hudson 中使用 Maven 项目已经相当成功一段时间了。 然而这次我需要构建一个 Eclipse 动态 Web 项目,该项目通常在 Eclipse 中构建,然后将 war 导出到生产环境。我怎样才能在哈德逊建立这个项目?

提前致谢!

I have been using maven projects in hudson quite successfully for some time.
However this time I need to build an eclipse dynamic web project that is usually built within eclipse and then the war is exported to production. How can I build this project in hudson.

Thanks in advance!

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

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

发布评论

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

评论(1

梦一生花开无言 2024-12-18 11:07:27

如果您熟悉 Maven,我建议您使用 m2e-wtp 插件——这样您就可以在您的 Web 应用程序中同时使用 Maven 和 WTP。既然 m2e 已移至 Eclipse Foundation,它应该位于 m2e 目录中的某个位置(Window > Preferences > Maven),请检查 Eclipse Indigo/3.7 中的 Maven/Tomcat 项目 了解更多信息。

  • Hudson/Jenkins 只会将其构建为常规 Maven 项目,无需额外的配置。
  • Eclipse 将主要继续使用自己的工具,中间有一些 Maven,但最重要的是,它将从 Maven 获取任何依赖项并将它们放在构建路径中。

如果您在 Eclipse 中已经有一个动态 Web 项目,您可能需要四处走动一堆文件夹,将它们排列在 Maven 期望的结构中:

src/
    main/
        java/        -- your Java source files (servlets, actions, ...)
        resources/   -- your resource files (struts.xml, log4j.xml, NOT web.xml)
        webapp/      -- your web root (previously WTP's WebContent/)
            WEB-INF/ -- your WEB-INFt (web.xml)
    test/
        java/        -- your Java test cases
        resources/   -- your test resource files
pom.xml

设置为 war,以便 Maven 知道它应该将您的依赖项放入WEB-INF/lib/ 并构建一个 WAR。

至于依赖项,您可能需要 Servlet API:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version><!-- change version as needed -->
  <scope>provided</scope><!-- Mind the scope!-->
</dependency>

注意 provided 范围:Servlet 规范禁止 Web 应用程序在 WEB-INF/lib 中携带自己的 Servlet API JAR在这种情况下,符合标准的 Web 容器将拒绝加载您的 Web 应用程序(它们会以它们支持的版本自行提供 JAR)。

最好首先右键单击 Dynamic Web Project 并转到 Maven > 。转换为 Maven 项目,然后如上所示移动文件夹,然后检查 m2e 和 m2e-wtp 插件向您抛出的所有警告(大多数都提供快速修复)。

If you're familiar with Maven, I suggest you use the m2e-wtp plugin -- that way you can use both Maven and WTP for your web app. It should be somehwhere in the m2e catalogue (Window > Preferences > Maven) now that m2e moved to the Eclipse Foundation, check Maven/Tomcat Projects In Eclipse Indigo/3.7 for more.

  • Hudson/Jenkins will just build it as a regular Maven project, no extra config needed.
  • Eclipse will mostly continue to use its own tools with some Maven inbetween, but most importantly it will get any dependenices from Maven and have them in the build path

If you already have a Dynamic Web Project in Eclipse, you'll probably have to move around a bunch of folders to arrange them in the structure Maven expects:

src/
    main/
        java/        -- your Java source files (servlets, actions, ...)
        resources/   -- your resource files (struts.xml, log4j.xml, NOT web.xml)
        webapp/      -- your web root (previously WTP's WebContent/)
            WEB-INF/ -- your WEB-INFt (web.xml)
    test/
        java/        -- your Java test cases
        resources/   -- your test resource files
pom.xml

Set the <packaging> to war so Maven knows that it should put your dependencies into WEB-INF/lib/ and build a WAR.

As for dependenices, you'll probably need the Servlet API:

<dependency>
  <groupId>javax.servlet</groupId>
  <artifactId>servlet-api</artifactId>
  <version>2.5</version><!-- change version as needed -->
  <scope>provided</scope><!-- Mind the scope!-->
</dependency>

Pay attentation to the provided scope: The Servlet spec prohibits web apps to bring their own Servlet API JAR along in WEB-INF/lib and conforming web containers will refuse to load your web app in that case (they will provide the JAR themselves in the version they support).

It's probably best to start by right-clicking on the Dynamic Web Project and go Maven > Convert to Maven project, then move the folders as shown above and then go through all the warnings the m2e and m2e-wtp plugins throw at you (most offer a quickfix).

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