Maven <executions> and npm build - java

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'
}
}

Related

Cannot load static file in tomcat

Firstly, I build the vuejs project in springboot by adding the following plugin:
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
<workingDirectory>src/main/frontend</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and yarn</id>
<goals>
<goal>install-node-and-yarn</goal>
</goals>
<configuration>
<nodeVersion>${nodejs.version}</nodeVersion>
<yarnVersion>v1.22.4</yarnVersion>
</configuration>
</execution>
<execution>
<id>yarn install</id>
<goals>
<goal>yarn</goal>
</goals>
<phase>generate-resources</phase>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>yarn build</id>
<goals>
<goal>yarn</goal>
</goals>
<configuration>
<arguments>build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-frontend</id>
<phase>generate-resources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>target/classes/resources/</outputDirectory>
<overwrite>true</overwrite>
<resources>
<resource>
<directory>src/main/frontend/dist</directory>
<includes>
<include>static/</include>
<include>index.html</include>
<include>favicon.ico</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
I have successfully built and run it when building into a jar file.
But now I want to run it with tomcat so I change the build format to war file but when running it can't load static file.
I think it's due to context path:
When run in tomcat: http://localhost:8080/report_system-1.0/
When run jar file: http://localhost:8080
But I don't know how to fix that.
You need to set publicPath when building the app for different environments. Something like
module.exports = {
publicPath: process.env.NODE_ENV === 'production'
? '/report_system-1.0/'
: '/'
}

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

How to execute a plugin explicitly after a certain phase in maven?

I'm using javafx-maven plugin to create a javafx webstart application. I had some issues signing the jar files with the javafx-maven plugin. what I want to do is, package(jar) the application with javafx-maven plugin and then sign the jar files using maven-jarsigner-plugin .
How do i execute the maven-jarsigner-plugin to sign my files after the application is packaged?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<archiveDirectory>target/jfx/app/</archiveDirectory>
<includes>
<include>**/*.jar</include>
</includes>
<keystore>path tp keystore</keystore>
<alias>alias</alias>
<storepass>password</storepass>
<keypass>password</keypass>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.3.0</version>
<configuration>
<bundler>jnlp</bundler>
<mainClass>com.myorg.myapp.launcher.myappLauncher</mainClass>
<bundleArguments>
<jnlp.allPermisions>true</jnlp.allPermisions>
<jnlp.includeDT>true</jnlp.includeDT>
<jnlp.outfile>myapp</jnlp.outfile>
</bundleArguments>
</configuration>
</plugin>
To workaround this I moved signing to verify phase.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.4</version>
<executions>
<execution>
<id>signing</id>
<goals>
<goal>sign</goal>
<goal>verify</goal>
</goals>
<phase>verify</phase>
<inherited>true</inherited>
<configuration>
...
</configuration>
</execution>
</executions>
</plugin>
Then I invoke maven like this:
mvn verify
Or make verify your default goal
Alternatively you can move javafx-maven plugin to the "prepare-package" phase:
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.0</version>
<configuration>
<bundler>jnlp</bundler>
<mainClass>com.myorg.myapp.launcher.myappLauncher</mainClass>
<bundleArguments>
<jnlp.allPermisions>true</jnlp.allPermisions>
<jnlp.includeDT>true</jnlp.includeDT>
<jnlp.outfile>myapp</jnlp.outfile>
</bundleArguments>
</configuration>
<executions>
<execution>
<id>create-jfxjar</id>
<phase>prepare-package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
</executions>
</plugin>

Why "mvn install" is running my tomcat in Install Phase?

I have configured failsafe together with tomcat7-maven-plugin for making integration-test. It's great and works very well when I type:
mvn clean verify -P integration-test
My pom.xml is like that:
<!-- Runs integration tests -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>2.18</version>
<executions>
<!-- Invokes both the integration-test and the verify goals of the Failsafe Maven plugin -->
<execution>
<id>integration-tests</id>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
<configuration>
<!-- Skips integration tests if the value of skip.integration.tests property is true -->
<skipTests>${skip.integration.tests}</skipTests>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.tomcat.maven</groupId>
<artifactId>tomcat7-maven-plugin</artifactId>
<version>2.2</version>
<configuration>
<path>/onde-vou</path>
</configuration>
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
</plugin>
But I got an unexpected behavior. When I type:
mvn clean install
It starts the tomcat and shutdown at the end of the process.
How do I avoid this behavior? It is useless for me and I lose some secs.
You can try mvn clean install -Dmaven.test.skip=true which skip the test, hence skips the execution pre-integration-test
or remove
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<fork>true</fork>
</configuration>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>

Maven wildfly-maven-plugin custom standalone.xml

How can I use a custom standalone.xml when running wildfly-maven-plugin:start (not just adding datasources, drivers,...)?
Using wildfly-maven-plugin-1.0.2.Final:
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>1.0.2.Final</version>
...
<execution>
<id>pre-integration-phase</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
</execution>
...
I have tried using maven-resources-plugin for copying resources (standalone.xml) in wildfly configuration folder, but it seems that wildfly:start overwrites and deletes every (other) file in Wildfly (configuration) directory.
This task is used for jenkins integration testing, thats why I need jboss running just when testing is in progress.
You can unpack the WildFly installation and then set jbossHome configuration element in wildfly-maven-plugin.
Example configuration:
<version.wildfly>8.2.0.Final</version.wildfly>
<jboss.home>${project.build.directory}/wildfly-${version.wildfly}</jboss.home>
<server.config>standalone.xml</server.config>
<!-- Unpack the distribution -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-wildfly</id>
<phase>generate-sources</phase>
<goals>
<goal>unpack</goal>
</goals>
<inherited>false</inherited>
<configuration>
<artifactItems>
<artifactItem>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-dist</artifactId>
<version>${version.wildfly}</version>
<type>zip</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}</outputDirectory>
</artifactItem>
</artifactItems>
</configuration>
</execution>
</executions>
</plugin>
<!-- Copy server configuration -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>${version.plugin.resources}</version>
<executions>
<execution>
<id>copy-standalone-xml</id>
<phase>generate-test-sources</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${jboss.home}/standalone/configuration</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- WildFly plugin to deploy war -->
<plugin>
<groupId>org.wildfly.plugins</groupId>
<artifactId>wildfly-maven-plugin</artifactId>
<version>${version.wildfly.maven.plugin}</version>
<configuration>
<jbossHome>${jboss.home}</jbossHome>
<serverConfig>${server.config}</serverConfig>
</configuration>
<executions>
<execution>
<id>pre-integration-phase</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>

Categories

Resources