Get resources from dependency - java

I want to get some resources from dependency that are not in resources directory, but in src/main/dir.
I tried to use maven-remote-resources-plugin, but I don't know how to change resource directory or even if it's possible.
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.7.0</version>
<executions>
<execution>
<id>process-remote-resources</id>
<goals>
<goal>process</goal>
</goals>
<configuration>
<resourceBundles>
<resourceBundle>some:dependency:1.0</resourceBundle>
</resourceBundles>
<outputDirectory>${project.basedir}/src/main/dir</outputDirectory>
<resources>
<resource>
<directory>${project.basedir}/dir</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
I need this resources before generate-sources phase.

Related

Maven <executions> and npm build

I have a hybrid application : Spring Boot and ReactJS.
While running/building/generating WAR, I have set the pom.xml to copy the npm run build generated files from dist folder to template(spring) folder.
But while running mvn clean install, file are copied before the npm run build command and then the npm run build and WAR is generated. That'swhy the frontend files are stale.
My pom.xml example is :
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>prepare-package</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/public</outputDirectory>
<outputDirectory>${basedir}/src/main/resources/templates</outputDirectory>
<resources>
<resource>
<directory>${basedir}/dist</directory>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>prepare-package2</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/main/resources/static</outputDirectory>
<resources>
<resource>
<directory>${basedir}/dist/static</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v11.10.0</nodeVersion>
<npmVersion>6.7.0</npmVersion>
</configuration>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<phase>prepare-package</phase>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
<!-- <execution>
<id>test</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>test</phase>
<configuration>
<arguments>test</arguments>
<environmentVariables>
<CI>true</CI>
</environmentVariables>
</configuration>
</execution> -->
</executions>
</plugin>
</plugins>
</build>
How do I configure so that the files are copied after npm run build ?
For similar task it makes sence to use gradle instead of maven. Tasks are much more flexible.
For example:
task buildFE(type: Exec) {
workingDir '../../FrontEnd'
commandLine 'buildFE.bat'
}
task CopyJava {
copy{
from '../OpenJDK'
into '../../Release/OpenJDK'
}
}

Additional resources directories for images in Maven site

For a Maven site, the standard image directory is src/site/resources/images.
Unfortunately, my asciidoc editor copies images to src/site/asciidoc/images. Can I somehow add this directory to the site resources (as in the Maven resources plugin)?
To copy all resources to an outputDirectory, you can simply specify following in your pom.xml-
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/src/site/resources/images</outputDirectory>
<resources>
<resource>
<directory>src/non-packaged-resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
Sources - Example from the plugin itself.

How to convert snippets to asciidoc html in eclipse

how to convert generated snippets to ASCII-doc html in spring boot.
i have already tried added the ASCII plugin.
i have already created .adoc file in src/main/asciidoc, but after maven build, it does not generate the html
include::{snippets}/test_find_by_id/http-request.adoc[]
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Documentation.java</include>
</includes>
<systemPropertyVariables>
<org.springframework.restdocs.outputDir>
${snippetsDirectory}
</org.springframework.restdocs.outputDir>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>1.5.2</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>prepare-package</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
<attributes>
<snippets>${snippetsDirectory}</snippets>
</attributes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>prepare-package</phase>
<!-- <phase>process-resources</phase>-->
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.outputDirectory}/static/docs
</outputDirectory>
<resources>
<resource>
<directory>
${project.build.directory}/generated-docs
</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
You need to reference the ASCII Doc Maven plugin in your pom.xml. See: https://github.com/asciidoctor/asciidoctor-maven-plugin#installation
mvn prepare-package
is the solution

struts 2 doesn't include file ApplicationResources.properties

I have an application made with struts2.
Since a few days, when I compile it with maven, it doesn't include the file ApplicationResources.properties in .war file.
The configuration in the pom.xml is :
<execution>
<id>native2ascii-utf8</id>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<encoding>UTF8</encoding>
<includes>ApplicationResources_*.properties</includes>
<excludes>ApplicationResources.properties,
ApplicationResources_de*.properties,
ApplicationResources_fr*.properties,
ApplicationResources_nl*.properties,
ApplicationResources_pt*.properties,
ApplicationResources_es*.properties</excludes>
</configuration>
</execution>
<execution>
<id>native2ascii-8859_1</id>
<goals>
<goal>native2ascii</goal>
</goals>
<configuration>
<encoding>8859_1</encoding>
<includes>ApplicationResources.properties,
ApplicationResources_de.properties,
ApplicationResources_fr.properties,
ApplicationResources_nl.properties,
ApplicationResources_pt*.properties,
ApplicationResources_es*.properties</includes>
</configuration>
</execution>
Finally I solved it deleting the exclude tag of this file
<resource>
<directory>src/main/resources</directory>
<!-- <excludes>
<exclude>ApplicationResources*.properties</exclude>
</excludes>-->
<filtering>true</filtering>
</resource>

Copying multiple resource directories to independent target directories with maven

The Maven resources plugin:
This goal requires that you configure the resources to be copied, and specify the outputDirectory.
Copy two (or more) external resource directories within the basedir to the build output directory using maven (see blah and uggh).
${basedir}/
- pom.xml
- blah/
- uggh/
- src/
- main/..
- test/..
- target/
- classes/..
- blah/
- uggh/
For example, given the directory structure above copy blah and uggh to the target directory using maven. It is easy to copy one or the other, however, the plugin only accepts a single outputDirectory. If you specify the target directory and both directories as resources, then the contents of each directory gets copied to target but not the directories themselves.
Additional use of the plugin overwrites the initial. Also, I've tried specifying the entire basedir and only including the desired directories. This does not copy anything.
Here is an example of copying a single directory:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/blah</outputDirectory>
<resources>
<resource>
<directory>blah</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
This is where the file ends up:
<outputDirectory>${basedir}/target/blah</outputDirectory>
This is where it is copied from:
<directory>src/main/otherresources</directory>
There would be an <include> or <includes> tag to tell the file name(s)
Multiples
You need multiple <execution>s with different <id>s for multiple folders:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources-1</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/blah</outputDirectory>
<resources>
<resource>
<directory>blah</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
<execution>
<id>copy-resources-2</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/ughh</outputDirectory>
<resources>
<resource>
<directory>ughh</directory>
<filtering>true</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
For me this one works well in Maven 3:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<id>custom-resources</id>
<phase>process-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<targetPath>${basedir}/target/blah</targetPath>
<directory>blah</directory>
<filtering>true</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/uggh</targetPath>
<directory>uggh</directory>
<filtering>false</filtering>
</resource>
<encoding>UTF-8</encoding>
</configuration>
</execution>
</executions>
</plugin>
This is the simpler solution I've found and it's working...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<configuration>
</configuration>
</plugin>
</plugins>
<resources>
<resource>
<directory>${basedir}/src/main/java/org/mc2/mymusic/gui/main/Menu/resources</directory>
<targetPath>${basedir}/target/classes/org/mc2/mymusic/gui/main/Menu/resources</targetPath>
<filtering>false</filtering>
</resource>
</resources>
</build>
You can use ant-style patterns
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<directory>${basedir}</directory>
<includes>
<include>blah/**</include>
<include>uggh/**</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<resources>
<resource>
<directory>${basedir}/src/scripts</directory>
<includes>
<include>data-octopus.ps1</include>
</includes>
<targetPath>${basedir}/target/data</targetPath>
</resource>
<resource>
<directory>${basedir}/src/scripts</directory>
<includes>
<include>service-octopus.ps1</include>
</includes>
<targetPath>${basedir}/target/service</targetPath>
</resource>
</resources>
</plugins>
...
</plugins>
Reading your example I don't think you have to include&configure the maven-resource-plugin.
Just add those resource-elements to the <build><resources/>-tag. See http://maven.apache.org/ref/3.1.1/maven-model/maven.html#class_resource which other tags you can use.
Maven hides everything to make it easier to code.
There are several ways you can achieve this.
Edit the default execution in Resources plugin. (Easiest)
This also can be written using include tag or different resources
Write different executions in Resources plugin.
Use Antrun plugin. (You might as well write the whole build in ant)
Maven Copy-rename plugin.
And many other ways that I am not mentioning here....
Edit the default plugin--
<resources>
<resource>
<directory>${basedir}<directory>
<includes>
<include>blah</include>
<include>ughh</include>
</includes>
<resource>
<resources>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<outputDirectory>${basedir}/target</outputDirectory>
</configuration>
</plugin>
</plugins>
If you want to copy more directories or files - a better option:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<tasks>
<copy todir="${basedir}/target/blah" overwrite="true">
<fileset dir="blah"/>
</copy>
<copy file="${basedir}/target/blah/somefile"
todir="../target_webapp_eclaims/WEB-INF" overwrite="true"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<targetPath>${basedir}/target</targetPath>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<targetPath>${basedir}/target/classes</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>jks</nonFilteredFileExtension>
</nonFilteredFileExtensions>
<executions>
<execution>
<id>copy-resources-1</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
</execution>
</executions>
</configuration>
</plugin>
</plugins>

Categories

Resources