0

I am currently working with a specific project structure.

All the jar files inside project\WEB-INF\lib which is prepared to create a WAR in target folder should be copied into project\lib

Can we run such script either using maven-antrun or maven-resource plugin, which will trigger before actual WAR is created?

If Yes, then how to program it? The files should not be moved, it should be copied.

EDIT

Figured out the solution using following xml and working fine, This structure required for openfire plugin

But unfortunately it only happens when second time mvn package is executed

<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>com.hpe.sis</groupId>
  <artifactId>TestCopy</artifactId>
  <packaging>war</packaging>
  <version>0.0.1-SNAPSHOT</version>
  <name>TestCopy Maven Webapp</name>
  <url>http://maven.apache.org</url>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.sun.jersey/jersey-core -->
    <dependency>
        <groupId>com.sun.jersey</groupId>
        <artifactId>jersey-core</artifactId>
        <version>1.19.1</version>
    </dependency>

  </dependencies>
  <build>
    <finalName>TestCopy</finalName>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-resources-plugin</artifactId>
        <version>3.0.1</version>
        <executions>
          <execution>
            <id>copy-resources</id>
            <phase>package</phase>
            <goals>
              <goal>copy-resources</goal>
            </goals>
            <configuration>
              <outputDirectory>${basedir}/target/TestCopy/lib</outputDirectory>
              <resources>
                <resource>
                  <directory>${basedir}/target/TestCopy/WEB-INF/lib</directory>
                  <filtering>false</filtering>
                </resource>
              </resources>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>
Dickens A S
  • 3,824
  • 2
  • 22
  • 45
  • Yes. (your question is a yes no answer?) In all seriousness, check http://maven.apache.org/plugins/maven-war-plugin/ I don't understand why you need to move jar files. – dieend Jun 20 '16 at 07:20
  • 1
    Something is seriously wrong with your set-up. You shouldn't copy JAR, you shouldn't even have JAR in your project. Can you post your POM and what you exactly want to do? Can you give more context? – Tunaki Jun 20 '16 at 08:30
  • I want to create a openfire plugin using `maven-archetype-webapp` archetype – Dickens A S Jun 20 '16 at 10:47

1 Answers1

0

You can use the copy-rename-maven-pluginplugin for that:

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>com.coderplus.maven.plugins</groupId>
        <artifactId>copy-rename-maven-plugin</artifactId>
        <version>1.0</version>
        <executions>
          <execution>
            <id>copy-file</id>
            <phase>prepare-package</phase>
            <goals>
              <goal>copy</goal>
            </goals>
            <configuration>
              <sourceFile>src/someDirectory/test.environment.properties</sourceFile>
              <destinationFile>target/someDir/environment.properties</destinationFile>
            </configuration>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

For more informations see: http://coderplus.github.io/copy-rename-maven-plugin/usage.html

Jens
  • 67,715
  • 15
  • 98
  • 113