How to convert snippets to asciidoc html in eclipse - java

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

Related

Replace a constant in JAVA code with Maven without modifying the original code

I have a text in a java constant that I want to be replaced according to a maven variable that is configured when generating the artifacts in the following way:
public class FOO {
public static final String BASE = "/#FOO#";
}
The problem is that if I replace the java code, it is replaced forever and the replacement is no longer performed, so if I change the value of the variable it has no effect:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>${basedir}/src/main/java/com/my/package/Constants.java</include>
</includes>
<replacements>
<replacement>
<token>#FOO#</token>
<value>${my.custom.property}</value>
</replacement>
</replacements>
</configuration>
</plugin>
I have fixed this by doing the process in reverse:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<id>first-execution</id>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<includes>
<include>${basedir}/src/main/java/com/my/package/Constants.java</include>
</includes>
<replacements>
<replacement>
<token>#FOO#</token>
<value>${my.custom.property}</value>
</replacement>
</replacements>
</configuration>
</execution>
<execution>
<id>second-execution</id>
<phase>prepare-package</phase>
<goals>
<goal>replace</goal>
</goals>
<configuration>
<includes>
<include>${basedir}/src/main/java/com/my/package/Constants.java</include>
</includes>
<replacements>
<replacement>
<token>${my.custom.property}</token>
<value>#FOO#</value>
</replacement>
</replacements>
</configuration>
</execution>
</executions>
</plugin>
But this second step can be dangerous, as there can be conflicts and replace something that has the same value in the java code of the class.
Another alternative would be to replace in the .class files as follows:
<plugin>
<groupId>com.google.code.maven-replacer-plugin</groupId>
<artifactId>replacer</artifactId>
<version>1.5.3</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>replace</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>${basedir}/target/my-artifact-directory/WEB-INF/classes/com/my/package//Constants$PATHS.class</include>
</includes>
<replacements>
<replacement>
<token>#FOO#</token>
<value>${my.custom.property}</value>
</replacement>
</replacements>
</configuration>
</plugin>
The replacement works but the application does not start correctly.
Any other ideas on how to perform the replacement without modifying the original code?
I'd create a resource file in src/main/resources that is read in FOO and use the Maven Resources Plugin's Resource Filtering similar to the answer to spring maven profile - set properties file based on compilation profile:
foo.properties
BASE=${propertyName}
pom.xml
<project>
...
<properties>
<propertyName>property value</propertyName>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
...

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 build maven dependencies into jar and pack it into a war file

In my maven project, i wanted to build all java source code into one jar (rtcc.jar) and all maven dependencies into another jar (external-lib.jar) and finally pack both these jars into a war file (rtccClient.war). rtcc.jar gets generated properly but jar with dependencies (external-lib) is not getting generated. .Below is my pom.xml. Please update where i am doing mistake.
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>default-jar</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<archive>
</archive>
<finalName>rtccJar/lib/rtcc</finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<classifier>only-library</classifier>
<excludes>
<exclude&>**/Main*</exclude>
</excludes>
<finalName>rtccJar/lib/external-lib</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.2</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>test</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jarsigner-plugin</artifactId>
<version>1.2</version>
<executions>
<execution>
<id>sign</id>
<phase>test</phase>
<goals>
<goal>sign</goal>
</goals>
</execution>
</executions>
<configuration>
<archiveDirectory>${basedir}/target/rtccJar/lib</archiveDirectory>
<archiveDirectory>${basedir}/target/lib/lib</archiveDirectory>
<includes>
<include>rtcc.jar</include>
<include>vcsireader1-1.1.jar</include>
<include>vcsutil1-1.1.jar</include>
<include>yaml1-1.1.jar</include>
<include>yamldefs1-1.1.jar</include>
</includes>
<keystore>${basedir}/extFiles/jarSigner/jarsignercert2.p12</keystore>
<alias>jarsigner</alias>
<storepass>scarbo</storepass>
<keypass>mykpass</keypass>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.6</version>
<executions>
<execution>
<phase>package</phase>
</execution>
</executions>
<configuration>
<webResources>
<resource>
<directory>${basedir}/target/rtccJar</directory>
</resource>
<resource>
<directory>${basedir}/target/lib/lib</directory>
<includes>
<include>vcsireader1-1.1.jar</include>
<include>vcsutil1-1.1.jar</include>
<include>yaml1-1.1.jar</include>
<include>yamldefs1-1.1.jar</include>
</includes>
<targetPath>lib</targetPath>
</resource>
<resource>
<directory>${basedir}/extFiles/extlib</directory>
</resource>
</webResources>
<packagingExcludes>**/com/**</packagingExcludes>
<failOnMissingWebXml>false</failOnMissingWebXml>
<warName> ${artifactId} </warName>
</configuration>
</plugin>
</plugins>
</build>

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

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>

Categories

Resources