I use the "maven-remote-resources-plugin" to share the resource
but,right now file in the "web-inf" folder,
I know,"web-inf" can not be accessed.
how can I put the file into src/main/webapp folder?
child parent POM
enter image description here
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<configuration>
<resourceBundles>
<resourceBundle>test:a-resources:${project.version}</resourceBundle>
</resourceBundles>
<outputdirectory>/</outputdirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
child A POM
enter image description here
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<resourcesDirectory>${project.build.outputDirectory}</resourcesDirectory>
<includes>
<include>**/*.json</include>
</includes>
</configuration>
</plugin>
parent (web app)
src/main/webapp
child A (storage html,js,css file)
--page
--index.html
child B (storage java class file)
--java.class
Related
I use Lombok in my library's code and want to use delombok'ed sources when deploying library JAR with sources to maven repository.
How to configure Maven to achieve this?
Update: Most likely, you don't need to deploy delombok'ed sources (check comments below this question for details)
Include following plugins into pom.xml's build/plugins section:
<plugin>
<groupId>org.projectlombok</groupId>
<artifactId>lombok-maven-plugin</artifactId>
<version>1.18.12.0</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>delombok</goal>
</goals>
</execution>
</executions>
<configuration>
<sourceDirectory>src/main/java</sourceDirectory>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
<addOutputDirectory>false</addOutputDirectory>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.1.0</version>
<executions>
<execution>
<id>copy-to-lombok-build</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<resources>
<resource>
<directory>${project.basedir}/src/main/resources</directory>
</resource>
</resources>
<outputDirectory>${project.build.directory}/delombok</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.8</version>
<executions>
<execution>
<id>generate-delomboked-sources-jar</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target>
<jar
destfile="${project.build.directory}/${project.build.finalName}-sources.jar"
basedir="${project.build.directory}/delombok"/>
</target>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>attach-source-jar</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/${project.build.finalName}-sources.jar</file>
<type>jar</type>
<classifier>sources</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
I am trying to use the resources plug-in with the aim of copying the jar in the target directory to another directory (e.g. /target/runtime) once it has been built.
I can see resources are copied at the start of process, before the jar is built, so reading up on it seems I need to run this at validate phase, i.e. after the jar has been built. However this is not working. Other files are copied, but not the jar.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/runtime</outputDirectory>
<resources>
<resource>
<filtering>true</filtering>
<directory>${project.basedir}/target</directory>
<targetPath>${project.build.directory}/target/runtime</targetPath>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
`<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<destFileName>optional-new-name.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</plugin>
</plugins>
</build>
[...]
</project>`
Please refer to this I have used this multiple times , seems to do the job.
The phase in your plugin definition for resource copying is defined as validate. The Jar is not built when this plugin runs. More information about lifecycle is defined here.
If you change the plugin phase as verify then it copies the file successfully as shown below,
I want to copy some files (jar, launch scripts, docs) to some directory, like dist/ in project root.
I am using maven-assembly-plugin and set <configuration><outputDirectory> in pom.xml. It creates files in dist/ but inside <my_project>-<decsriptor_id>/ subdirectory.
Is there any way to output it just in the root of dist/?
Or is there a plugin in Maven that simply copies files?
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>maven-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<outputDirectory>${project.basedir}/dist</outputDirectory>
<descriptors>
<descriptor>${project.basedir}/src/main/maven-assembly/dist.xml</descriptor>
</descriptors>
</configuration>
</plugin>
dist.xml
<assembly xmlns="http://maven.apache.org/ASSEMBLY/2.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/ASSEMBLY/2.0.0 http://maven.apache.org/xsd/assembly-2.0.0.xsd">
<id>dist</id>
<formats>
<format>dir</format>
</formats>
<includeBaseDirectory>false</includeBaseDirectory>
<files>
<file>
<source>path........</source>
<fileMode>0755</fileMode>
<outputDirectory>.</outputDirectory>
</file>
</files>
</assembly>
You may use maven-resources-plugin:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- insert here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/extra-resources</outputDirectory>
<resources>
<resource>
<directory>src/non-packaged-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
I have tow maven projects resources-win and main-exec.I try to copy a dll file from a folder win of resources-win and copy it to target/classes, then i moved to the project number 2 main-exec and i try to copy a file 2 witch is in src/main/shcemas and the dll file of resources-win and paste them into target classes of the project resources-win
Here is the bloc of code whitch helps to copy a file to target of resources-win:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources01</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/src/main/win</directory>
<includes>
<include>**/*.dll</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Here is a part of pom.xml of the project main-exec:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libraries</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<!-- win32 -->
<artifactItem>
<groupId>com.resources-win</groupId>
<artifactId>ressources-win</artifactId>
<version>1.0.0-SNAPSHOT</version>
<type>pom</type>
<destFileName>xdol.dll</destFileName>
<outputDirectory>${project.build.directory}/temp/schemas</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
I did like that by using an xsd file by adding to pom.xml of resources-win:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources-xsd</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.outputDirectory}</outputDirectory>
<encoding>UTF-8</encoding>
<resources>
<resource>
<directory>${basedir}/src/main/schemas</directory>
<includes>
<include>**/*.xsd</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>attach-artifacts</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.outputDirectory}/titi.xsd</file>
<type>xsd</type>
<classifier>titi</classifier>
</artifact>
<artifact>
<file>${project.build.outputDirectory}/toto.xsd</file>
<type>xsd</type>
<classifier>toto</classifier>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
Then into the pom.xml of main-exec i added:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-libraries</id>
<phase>generate-resources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>groupId of resources-win</groupId>
<artifactId>artifactId of resources-win</artifactId>
<version>${resources-win.version}</version>
<type>xsd</type>
<classifier>toto</classifier>
<destFileName>toto.xsd</destFileName>
<outputDirectory>${project.build.directory}/tmp/schemas</outputDirectory>
</artifactItem>
</artifactItems>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
I added also the the pom.xml of main-exec the dependency of resources-win.
I would like to generate a sources jar but without some packages in my project.
Now I have this in my pom.xml
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<executions>
<execution>
<id>sources</id>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
How to exclude specific packages?
similar but with netbeans environment
You can configure the maven-source-plugin with the excludes attribute:
List of files to exclude. Specified as fileset patterns which are relative to the input directory whose contents is being packaged into the JAR.
A sample configuration where you would exclude every class under the package com.my.package would be the following:
<plugin>
<artifactId>maven-source-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<id>sources</id>
<goals>
<goal>jar</goal>
<goal>test-jar</goal>
</goals>
<phase>package</phase>
<configuration>
<excludes>
<exclude>com/my/package/**</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>