Maven to copy JAR when adding dependencies

不想你离开。 提交于 2019-12-09 09:44:31

问题


I'm currently using IBM Rational Application Development (IBM Eclipse distro) for Portlet development and having a small issue with Maven integration.

Here's the situation:

1) IBM RAD has the ability to deploy a Portlet directly from within itself (RUN/DEBUG)

In this case, I'm not using Maven generated WAR at all because IBM RAD seems to create the WAR themselves automagically and push it to IBM WebSphere Portal. Which isn't a big deal so far.

2) Maven dependencies are not copied to WebContent/WEB-INF/lib directory

IBM has its own directory structure: WebContent/WEB-INF and WebContent/META-INF. If I updated pom.xml to include new dependencies, those JARS will not be copied to the WebContent/WEB-INF/lib directory hence when I wanted to RUN/DEBUG the portlet, those libraries will not be included.

Question:

Is there a way to copy the new JARs automatically to the WebContent/WEB-INF/lib folder as soon as I update the pom.xml? (if so, which lifecycle this should be in?)

If there's no perfect solution for question #1, I don't mind if this step is included in the "mvn install" compile/goal.

Prefer not to use ant-task but instead maven own copy utility if exist.

If anyone has suggestions how to integrate Maven and IBM RAD for WebSphere Portlet development, feel free to add more answers.

Thanks


回答1:


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.




回答2:


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.



来源:https://stackoverflow.com/questions/4831831/maven-to-copy-jar-when-adding-dependencies

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