Maven to copy JAR when adding dependencies

随声附和 提交于 2019-12-03 13:14:38

Here's a Maven 2 pom.xml skeleton I picked out of an old RAD project:

<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/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>foo</groupId>
  <artifactId>fooproject</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>
  <properties>
    <project.build.sourceEncoding>US-ASCII</project.build.sourceEncoding>
  </properties>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <finalName>${project.artifactId}-${project.version}</finalName>
    <resources>
      <resource>
        <directory>src</directory>
        <includes><include>**/*.properties</include></includes>
        <filtering>true</filtering>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>2.1</version>
      </plugin>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.1-beta-1</version>
        <configuration>
          <webappDirectory>${project.basedir}/WebContent</webappDirectory>
          <warSourceDirectory>${project.basedir}/WebContent</warSourceDirectory>
          <webXml>${project.basedir}/WebContent/WEB-INF/web.xml</webXml>
          <packagingIncludes>**/*.properties,**/*.jsp,**/*.jar,**/*.class,theme/**/*,images/**/*,**/*.xml,**/*.swf,**/*.tld,**/*.txt</packagingIncludes>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
            </manifest>
          </archive>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencies>
    <!-- compile classpath -->
  </dependencies>
</project>

This was applied to the directory structure as created by RAD (version 7.5, targetting Portal 6.5.x on WAS 7). This isn't the only way to do it and I'm sure the pom could be improved upon, but it served its purpose. Add your dependencies as appropriate.

I had the same question and issues integrating Maven and RAD. I'm using RAD 8 with m2e and trying to automatically deploy/debug portlets for WebSphere Portal 7.

First, as to Gorkem's comment:

I am not sure if this works for IBM RAD but with the Eclipse WTP you can define the deployment assembly pieces from the project properties.

This does work in RAD. I have setup my project's deployment assembly to match the WebSphere build structure and move my Maven Dependencies into the WEB-INF\lib folder (Project -> Properties -> Deployment Assembly -> Add -> Java Build Path Entries -> Maven Dependencies).

This configuration did allow me to build the war successfully and I can export the generated EAR file from RAD and manually deploy it to my local server and it works fine. However, the automatic deploy and 'run on server' options do not work with this alone. For some reason it will deploy all the transitive dependencies (portlet-api, servlet-api, etc) to WebSphere which causes conflicts and explosions.

Therefore, I tried the pom solution proposed by McDowell with limited success - it would not compile nor run my tests correctly, though when I removed the tests it did deploy successfully from RAD. I'm working off of his pom to include testing and will post my results here when I get it working.

I also found this thread which contains a link to a 2010 IBM document on the "offical" way to integrate Maven and RAD. I'm working through it and will see which solution better meets my needs. Again, if/when I have it working I will post more info here.


Update 11/21/2011

IBM has produced an updated document for Maven/RAD integration. You can find it here. I have gone through it and it is pretty well-done. It is step-by-step with screenshots and a little bit of background on Maven, M2eclipse, and WTP. There are still a couple annoyances which Chuck describes in the paper, but in the end, it allowed our team to start using Maven in a WebSphere Portal environment without abandoning Maven conventions. Hopefully others will find it useful.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!