简体   繁体   中英

how to build an eclipse dynamic web project in hudson

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!

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM