I need to copy some resources from an artifact to a particular place.
I need to change the location without flatting it.
For example:
my-res-artifact
\
someroot/subdir1/
+ myres1.dat
+ myres2.dat
\
subdir12
+ myres3.dat
I want to copy this into subdir1 directory, but remove the someroot root directory. This doesn't work with the following:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-additional-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.example</includeGroupIds>
<includeArtifactIds>my-res-artifact</includeArtifactIds>
<includes>someroot/subdir1/**</includes>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
The directory structure someroot/subdir1/ is preserved.
The file names can be changed by a File Mapper.
The trick works for whole locations, too:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-additional-resources</id>
<phase>prepare-package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>com.example</includeGroupIds>
<includeArtifactIds>my-res-artifact</includeArtifactIds>
<includes>someroot/subdir1/**</includes>
<outputDirectory>${project.build.directory}</outputDirectory>
<fileMappers>
<fileMapper implementation="org.codehaus.plexus.components.io.filemappers.RegExpFileMapper">
<pattern>someroot/subdir1</pattern>
<replacement>subdir1</replacement>
</fileMapper>
</fileMappers>
</configuration>
</execution>
</executions>
</plugin>
Related
Is there any way to have META-INF folder inside BOOT-INF in spring boot packaging jar?
This might be a trivial question, but not sure how to do it. Below is the way i am packaging right now which created three folders BOOT_INF, META_INF, ORG. The reason of asking this is because runnable jar is not able to locate a folder which is inside META-INF.
<build>
<finalName>XYZ</finalName>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>XYZ</version>
<executions>
<execution>
<id>default-jar</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<excludes>
<exclude>XYZ</exclude>
<exclude>XYZ</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<mainClass>XYZ</mainClass>
<addResources>true</addResources>
<wait>1000</wait>
<maxAttempts>250</maxAttempts>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>XYZ</version>
<configuration>
<tarLongFileMode>XYZ</tarLongFileMode>
<tarLongFileMode>XYZ</tarLongFileMode>
<descriptors>
<descriptor>XYZ</descriptor>
</descriptors>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>XYZ</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Any help which plugin i can use in order to do that?
Similar issue resolved in my case after adding META-INF folder under resources.
The pom-code at the bottom below creates a classpath file containing all jar files relative to the .m2 maven cache:
${M2_REPO}\org\slf4j\slf4j-api\1.7.25\slf4j-api-1.7.25.jar;${M2_REPO}\com\github\jnr\jnr-ffi\2.1.7\jnr-ffi-2.1.7.jar;...
Al dependencies are neatly copied to target/lib
${project.build.directory}/lib
I wonder how I can get maven to create the classpath using the path of my target/lib directory rather than the maven cache:
target/libslf4j-api-1.7.25.jar:target/lib/jnr-ffi-2.1.7.jar:...
Iam using the following maven code:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
<execution>
<id>build-classpath</id>
<phase>package</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<attach>true</attach>
<outputFile>${project.build.directory}/classpath</outputFile>
</configuration>
</execution>
</executions>
</plugin>
The following does the job for me:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}${file.separator}lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
<execution>
<id>build-classpath</id>
<phase>package</phase>
<goals>
<goal>build-classpath</goal>
</goals>
<configuration>
<attach>true</attach>
<outputFile>${project.build.directory}${file.separator}classpath</outputFile>
<prefix>target${file.separator}lib</prefix>
</configuration>
</execution>
</executions>
</plugin>
I was trying to move a file to an existing one with a variable (cache busted) part:
file.js should be copied over an existing file-0123456789abcdef.js (of which the last part 16 hex digits is variable)
The copy-rename-maven-plugin results in an extra file: file-*.js:
<plugin>
<groupId>com.coderplus.maven.plugins</groupId>
<artifactId>copy-rename-maven-plugin</artifactId>
<executions>
<execution>
<id>move-file</id>
<phase>prepare-package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<sourceFile>${project.build.directory}/unpacked/file.js</sourceFile>
<destinationFile>${project.build.directory}/unpacked/file-*.js</destinationFile>
</configuration>
</execution>
</executions>
</plugin>
I would like to end up with one file: file-0123456789abcdef.js with the content of file.js.
A simple terminal command can easily do what I want but I would like to avoid using the ant plugin.
Help will be much appreciated!
I found out that the exec-maven-plugin could do the trick in combination with a find -exec:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>move-configuration</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>find</executable>
<arguments>
<argument>${project.build.directory}/unpacked/>
<argument>-name</argument>
<argument>file-*.js</argument>
<argument>-exec</argument>
<argument>mv</argument>
<argument>${project.build.directory}/unpacked/file.js</argument>
<argument>{}</argument>
<argument>;</argument>
</arguments>
</configuration>
</plugin>
Is it possible to work with multiple xsd schemas with castor-maven-plugin simultaneously?
I use it in rotation (schema1 and schema2) in POM and it works:
<build>
...
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
<configuration>
<schema>src/main/castor/schema1.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema1.beans</packaging>
</configuration>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
...
with a little problem: mvn:install collects all classes to target except chema2.crd (or schema1 if I use schema2). I have to copy file manually.
Can I fix it? Are there any ways to configure castor-maven-plugin ?
Try using multiple executions like this:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>castor-maven-plugin</artifactId>
<version>2.1</version>
<executions>
<execution>
<id>firstSchema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schema>src/main/castor/schema1.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema1.beans</packaging>
</configuration>
</execution>
<execution>
<id>secondSchema</id>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<schema>src/main/castor/schema2.xsd</schema>
<dest>src/main/java</dest>
<packaging>com.path.to.schema2.beans</packaging>
</configuration>
</execution>
</executions>
</plugin>
The following snippet creates 2 JARS:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>build-dependency</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>dependency</classifier>
<classesDirectory>${project.build.directory}\dependency</classesDirectory>
<includes>
<include>${dependancyInclude}</include>
</includes>
</configuration>
</execution>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>module</classifier>
<classesDirectory>${project.build.directory}\classes</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
I would like to combine these two JARs into one using the assembly plugin, currently I have the following:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<executions>
<!-- Combine all the JARs in the /target folder into one JAR -->
<execution>
<id>make-assembly</id>
<phase>compile</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
Currently only one of the two JARS in included in the final JAR that is created by the assembly plugin.
If I understand you correctly, you actually want to merge the jar files into one big jar file. This can be achieved using the maven-shade-plugin (instead of the maven-assembly-plugin).
For example:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<configuration>
<!-- Put your configuration here, if you need any extra settings.
(You should be okay with the defaults). -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>