Maven - How to create a POM that place files in the root - maven

I need to create a pom.xml file that builds a jar with certain files place on its root. The pom.xml I have now creates 3 directories BOOT-INF, META-INF and org. Below is the build section. I want the files to be at the same level as the directories (BOOT-INF, META-INF, org).
sparc-jar.jpg
<plugins>
<plugin>
<groupId>oerg.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>build-info</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.sh</include>
<include>**/*.id</include>
<include>**/*.yaml</include>
<include>**/*.json</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.jar</include>
<include>**/*.js</include>
<include>**/*.map</include>
<include>**/*.html</include>
<include>**/*.hbs</include>
<include>**/*.cer</include>
<include>**/*.p12</include>
</includes>
</resource>
<resource>
<directory>.</directory>
<includes>
<include>**/*.yaml</include>
<include>**/*.json</include>
<include>**/*.properties</include>
<include>**/*.xml</include>
<include>**/*.cer</include>
<include>**/*.p12</include>
</includes>
</resource>
</resources>
</build>

This worked for me... Configure the spring-boot-maven-plugin as follows:
<configuration>
<outputDirectory>${project.basedir}</outputDirectory>
</configuration>

Related

generated file in the wrong place

I'm using the maven resources plugin to generate a plain file via filtering within a war file. I have the template file with variables in a the folder src/main/webapp/app
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>process-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>src/main/webapp/app</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
the problem is that the generated file is in the WEB-INF/classes folder and I need it to be at the app folder at the root of the war.
The war structure should be
*.jsf
app/<generated_file>
WEB-INF/
How can I do it?
You have to add a copy-resources goal if you want to copy something to another structure during your build, with that you can point to a custom output path:
<configuration>
<outputDirectory>${basedir}/target/extra-resources</outputDirectory>
<resources>
<resource>
<directory>src/non-packaged-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
This can be found here in the documentation.
With the comments I could finally get the solution. It was simply to set the outputDirectory parameter to src/main/webapp/app and put the template in another place outside src/main/webapp. In my case, I put it in a folder src/main/jnlp. So finally this was the solution.. hope it helps others
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/webapp/app</outputDirectory>
<resources>
<resource>
<directory>src/main/jnlp</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>

Maven does not copy resource files

I have a maven web application project that follows the maven standard directory layout so I have my resource files placed in src/main/resources/.
As this follows the standard I was expecting maven to automatically add the resource files to /WEB-INF/classes of the web application during the build but no files are copied.
I have to add the following lines to the build section of the pom file to get maven to copy the files:
<resources>
<resource>
<directory>src/main/resources/</directory>
</resource>
</resources>
My question is: is this supposed to be necessary?
I was wondering if any of the build section plugins I use could somehow interfere with the copying of the resources. Are there any plugins that are known to do this?
The build section of my pom file is here:
<build>
<resources>
<resource>
<directory>src/main/resources/</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<includes>
<include>${tests.to.include}</include>
</includes>
<excludes>
<exclude>${tests.to.exclude}</exclude>
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.20.1</version>
<configuration>
<includes>
<include>**/ITSelenium*.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<id>add extra source directories</id>
<phase>generate-sources</phase>
<goals><goal>add-source</goal></goals>
<configuration>
<sources>
<source>${project.basedir}/generated/src/main/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add extra test directories</id>
<phase>generate-test-sources</phase>
<goals><goal>add-test-source</goal></goals>
<configuration>
<sources>
<source>${project.basedir}/generated/src/test/java</source>
</sources>
</configuration>
</execution>
<execution>
<id>add integration test sources</id>
<phase>generate-test-sources</phase>
<goals>
<goal>add-test-source</goal>
</goals>
<configuration>
<sources>
<source>${project.basedir}/src/it/java</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<warName>res</warName>
<webResources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/src/main/webapp</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.sonarsource.scanner.maven</groupId>
<artifactId>sonar-maven-plugin</artifactId>
<version>3.4.0.905</version>
</plugin>
</plugins>
</build>
Any help or information will be much appreciated.

Move resource files to target and exclude from jar

I have a maven project set up like this:
\src
\--main
\--java
\--fu
\--bar
\--AppMain.java
\--resources
\--log4j.xml
With a pom using the maven-resources-plugin to move my resource files to a target directory like this:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>my/target/dir/config</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
And the maven-jar-plugin to create the jar like this:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>fu.bar.AppMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
When I run mvn clean install, my target location includes the compiled jar and the \config\log4j.xml. However, the jar also includes log4j.xml.
How do I exclude log4j.xml from the jar and still move it to \my\target\dir\config?
Adding this to my pom was the trick:
<build>
<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
</build>

How to include particular file from a folder in maven install target directory?

Directory structure is
conf
axis2.aar
com
lib
META-INF
axis2.xml
build.xml
common-logging.properties
log4j.properties
*.class
I want that only axis2.xml should be included in axis2.aar in target folder when doining maven install. I have tried many include and exclude combinations but nothing is
working. After doing maven install, It is taking whole axis2.aar contents. I also tried filtering by setting it to true.Please suggest some solution.
Pom.xml
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>CUDB_HSS</groupId>
<artifactId>CUDB_HSS</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src/main/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>wsdl</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
<resource>
<directory>conf/axis2.aar</directory>
<filtering>true</filtering>
<includes>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>**/*.java</exclude>
<exclude>**/*.properties</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>default-jar</id>
<phase>never</phase>
<configuration>
<finalName>unwanted</finalName>
<classifier>unwanted</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-aar-maven-plugin</artifactId>
<version>1.6.4</version>
<extensions>true</extensions>
<executions>
<execution>
<id>cudb-hss-aar</id>
<phase>package</phase>
<goals>
<goal>aar</goal>
</goals>
<configuration>
<aarDirectory>conf/axis2.aar</aarDirectory>
<aarName>axis2</aarName>
<filesets>
<fileset>
<directory>conf/axis2.aar</directory>
<outputDirectory>target</outputDirectory>
<includes>
<include>**/*.xml</include>
</includes>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
</fileset>
</filesets>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>cudb-hss</id>
<phase>package</phase>
<configuration>
<classifier>client1</classifier>
<finalName>cudb-hss</finalName>
<includes>
<include>com/accenture/**/*.class</include>
<include>macro_CUDB_Accenture_HSS.class</include>
<include>**/com/accenture/il/interfaces/cudb/hss/conf/jaxb/**/*.properties</include>
<include>**/com/accenture/il/interfaces/cudb/hss/error/bean/jaxb/**/*.properties</include>
<include>**/*.properties</include>
</includes>
</configuration>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>cudb-hss-wsdl</id>
<phase>package</phase>
<configuration>
<classifier>client2</classifier>
<finalName>cudb-hss-wsdl</finalName>
<includes>
<include>com/ericsson/**/*.class</include>
<include>**/com/ericsson/**/jaxb.properties</include>
</includes>
</configuration>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
The answer to your question can be:
<fileset>
<directory>conf/axis2.aar</directory>
<outputDirectory>target</outputDirectory>
<includes>
<include>axis2.xml</include>
</includes>
</fileset>

Maven resource plugin expose an image from a different path

I have an immage accessible from /resources/gfx/loading.gif
I would like to have it accessible from /img/immage.gif
I tried with maven-resources-plugin with the following config, but actualy nothing happens.
I'm curretnly building the app from eclipse.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-loading-status</id>
<phase>package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>/src/main/webapp/img</outputDirectory>
<resources>
<resource>
<directory>/src/main/resources/gfx</directory>
<includes>
<include>loading.gif</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Assuming you are building a WAR, you could configure the maven-war-plugin to include additional web resources:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<configuration>
<webResources>
<resource>
<directory>/src/main/resources/gfx</directory>
<includes>
<include>loading.gif</include>
</includes>
<targetPath>img</targetPath>
</resource>
</webResources>
</configuration>
</plugin>

Resources