Publish spring-restdocs html documentation with application - spring-mvc

I have spring-boot application with spring-restdocs and I want to create endpoint in that application for generated documentation. What is the best approach to expose endpoint with generated html documentation(by asciidoctor)?
I can include index.html to jar-file but don't really know how to create endpoint that will consume that html and expose outside.This html generated after test-stage and before build-jar-stage.
From official documentation:
You could publish the HTML documentation you created to a static website, or package it up and serve it from the application itself.
e.g. I have index.html in 'build/asctiidoctor/html5' folder and want to create controller that will return that index.html.

According to documentation you can configure your build system (Maven, Gradle) to package HTML into spring-boot jar as static content so that it will be served by Spring Boot 'automagically'
In case of Gradle 4.6 and Spring Boot 2.0.0.RELEASE:
bootJar {
dependsOn asciidoctor
from ("${asciidoctor.outputDir}/html5") {
into 'static/docs'
}
}
Then it can be verified locally via 'localhost:<your-port>/<your-context-path/docs/index.html

To access the api guide locally using spring boot using the url http://localhost:8081/docs/api-guide.html , add the following plugins:
<plugin>
<groupId>org.asciidoctor</groupId>
<artifactId>asciidoctor-maven-plugin</artifactId>
<version>${asciidoctor-maven-plugin.version}</version>
<executions>
<execution>
<id>generate-docs</id>
<phase>post-integration-test</phase>
<goals>
<goal>process-asciidoc</goal>
</goals>
<configuration>
<backend>html</backend>
<doctype>book</doctype>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-asciidoctor</artifactId>
<version>${spring-restdocs.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>${maven-resources-plugin.version}</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>post-integration-test</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>
</plugin>`

After generating html out of the AsciiDoc just copy the html files into target/generated-docs (see https://spring.io/guides/gs/testing-restdocs/). Spring-Boot then will take and host the documentation within the endpoint <...>/docs/index.html.
You could use maven-resources-plugin for this job.

Related

Copy Maven dependency files and runtime in jpackage

I have a JavaFX project with dependencies on SQLite and POI, so I used maven-dependency-plugin to copy all dependencies in target\lib folder. That folder contains about 21 dependencies common-codecs, curvesapi, javafx-base, javafx-fxml... etc.
To create a jpackage I'm using jpackage-maven-plugin to create an installer. I have jmods folder copied to java.home. The POM is as follows:
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19</version>
</dependency>
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.39.3.0</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>5.2.3</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>5.2.3</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib/</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<launcher>App</launcher>
<mainClass>com.example.App</mainClass>
</configuration>
<executions>
<execution>
<id>default-cli</id>
<configuration>
<mainClass>com.example.App</mainClass>
</configuration>
</execution>
<execution>
<id>debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=localhost:8000</option>
</options>
</configuration>
</execution>
<execution>
<id>ide-debug</id>
<configuration>
<options>
<option>-agentlib:jdwp=transport=dt_socket,server=n,address=${jpda.address}</option>
</options>
</configuration>
</execution>
<execution>
<id>ide-profile</id>
<configuration>
<options>
<option>${profiler.jvmargs.arg1}</option>
<option>${profiler.jvmargs.arg2}</option>
<option>${profiler.jvmargs.arg3}</option>
<option>${profiler.jvmargs.arg4}</option>
<option>${profiler.jvmargs.arg5}</option>
</options>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.panteleyev</groupId>
<artifactId>jpackage-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<name>ExampleFX</name>
<appVersion>${project.version}</appVersion>
<icon>${basedir}/icon.ico</icon>
<vendor>Myself</vendor>
<destination>Runtime</destination>
<modulePaths>
<modulePath>C:\Program Files\Java\jmods</modulePath>
<modulePath>${project.build.directory}/classes</modulePath>
</modulePaths>
<module>com.example/com.example.App</module>
<runtimeImage>${java.home}/lib</runtimeImage>
<winDirChooser>true</winDirChooser>
<winShortcut>true</winShortcut>
<winConsole>true</winConsole>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<release>19</release>
</configuration>
</plugin>
</plugins>
</build>
</project>
This command neither packages the lib folder in the installer, nor does it properly copies JVM, as on running the program, it gives Failed to find JVM in "C:\Program Files\Example\runtime" directory. error. Any help appreciated.
EDIT
Changed some parameters:
from<runtimeImage>${java.home}/lib</runtimeImage> to <runtimeImage>${java.home}</runtimeImage>,
added module path <modulePath>${project.build.directory}/lib</modulePath>
Now the app fails to find modules (dependencies) which are present in ${INSTALLDIR}/app/mods. Trying to add these modules require I remove runtimeImage parameter. If I do so:
<addModules>javafx.fxml,javafx.controls,
org.apache.poi.ooxml,org.apache.poi.poi,org.xerial.sqlitejdbc,SparseBitSet,
org.apache.commons.compress,org.apache.commons.codec,org.apache.commons.collections4,
org.apache.commons.io,com.github.virtuald.curvesapi,commons.math3,
org.apache.commons.collections4,org.apache.xmlbeans</addModules>
I always get error regarding any module randomly:
jlink failed with: Error: automatic module cannot be used with jlink: commons.math3 from file:///C:/Users/MY/Documents/NetBeansProjects/Example/target/lib/commons-math3-3.6.1.jar
module-info
module com.example{
requires javafx.controls;
requires javafx.fxml;
requires javafx.base;
requires javafx.graphics;
requires java.logging;
requires java.base;
requires java.sql;
requires org.apache.poi.poi;
requires org.apache.poi.ooxml;
requires org.apache.commons.codec;
requires org.apache.commons.collections4;
requires org.apache.commons.compress;
requires org.apache.commons.io;
requires commons.math3;
requires com.github.virtuald.curvesapi;
requires org.apache.logging.log4j;
requires SparseBitSet;
requires org.xerial.sqlitejdbc;
requires org.apache.xmlbeans;
opens com.example to javafx.fxml;
exports com.example;
}
Use JPackageScriptFX. Here's how to use it:
(I'll refer to JPackageScriptFX as JPS and your project as Example)
Copy your Example project folder inside JPS's folder.
Open JPS's POM, and go to <modules> section. Remove all existing module entries (jpackagefx-main,jpackagefx-module1,jpackagefx-module2). Write <module>Example</module> instead.
Change groupId to Example's groupId.artifactId.
Open Example's POM. Write <packaging>jar</packaging> beneath <version> tag.
Copy jpackagefx-main's maven-dependency-plugin from its POM and copy it to Example's POM.
Write <configuration><mainClass>com.example.App</mainClass></configuration> in javafx-maven-plugin if it isn't there already.
Copy whole of the <profiles> section from jpackagefx-main and copy it to Example's POM.
Rename ${client.version} to ${project.version} in <APP_VERSION> and <PROJECT_VERSION> (This is required especially in the case of Linux, otherwise the jpackage will fail in final stages (dpkg-deb returns with error code 2)).
Create a new class file named AppLauncher, and write following code in it:
package com.example
public class AppLauncher{
public static void main(String[] args){
App.main(args);
}
}
Depending on your platform (Windows, Linux, Mac) copy the build_app_linux.sh, build_app_mac.sh or build_app_windows.bat file inside Example's project folder. I'll refer to the linux version in the next steps, you can find appropriate lines in other platform files.
Line 13, Change MAIN_JAR="main-ui-... to MAIN_JAR="Example-... or whatever the name of your Jar file is (You can find Jar filename by building the project and simply looking its name in target folder).
Line 47, change class path to target/classes/com/Example/App.class
Line 63, append modules you want in your project (in your case, ,java.sql).
Line 92, Change to whatever name you want to give. You can also use quotes " to give space in the name.
Line 93, set --main-class to com.example.AppLauncher.
Line 97, optinally, set your own icon by modifying this line.
For Windows, additionally change line 40 to --print-module-deps target\classes\com\example\App.class > temp.txt.
Open pom.xml[parent] using Whatever IDE. I'm using netbeans, so I can clean and build the project by pressing SHIFT+F11.
If there's no error, then your installer will be present in target\installer

Alfresco, embed a binary inside the amp

I have an alfresco community amp module, which also need a client msi to be installed on the client PC.
To solve the distribution problem I tought about embedding the installer inside the amp to give the user the possibility to download it and install it when needed.
It is a correct approach? and which is the best correct to put the biniry file in?
The file should be downloaded from a link inside alfresco share, displayed when the user permorm some actions on a document
I have resolved my problem with maven-resoures-plugin configured as followed. Maybe this is not the best options, but it worked.
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<nonFilteredFileExtensions>
<nonFilteredFileExtension>msi</nonFilteredFileExtension>
</nonFilteredFileExtensions>
<resources>
<resource>
<directory>/src/main/myLib</directory>
<filtering>false</filtering>
</resource>
</resources>
<outputDirectory>${basedir}/target/amp/web/myShare/js/myLib/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>

Javafx application doesnt work after install

I'm creating new JavaFX application. I have done it, now i need to build exe file. After build I have installed it, then i launch the program and nothing. There is no application window, it was showing only in task manager...
Project have no errors, just some warrnings. I'am using http connections in it, maybe i need to declare permissions or something? Where can i do it if it's a problem?
I've tried to generate new build.xml, include newest sdk/jre, installed new version of java in my computer.
Java cannot build an exe file by itself. Every client who needs to run the application needs an appropriate JRE installed to run the application. Therefore you would need some software that packages the jar and the JRE into an exe file to install it or packages the jar and JRE into one single exe file which executes your program.
It has nothing to do with your http connections or build.xml.
However your app will run when you call it via the command line java -jar YOUR_APP.jar
If you just want to run your program by double clicking the jar file (and not build an exe), you can take a look at the following paragraphs.
For Maven
If you are building your project with Maven you can try the following POM settings to have your program be executable from the jar file (double click the jar file to start the JavaFX application):
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.1.4</version>
<configuration>
<mainClass>PATH TO YOUR MAIN CLASS (e.g. com.foo.Main)</mainClass>
<allPermissions>true</allPermissions>
</configuration>
<executions>
<execution>
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>PATH TO YOUR MAIN CLASS (e.g. com.foo.Main)</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
I recommend you exporting it as an jar file because it can be excecuted on linux, too and it fixes your problem because it can contain all the data you need just like fxmls!
Just export your project as an runnable jar and this window will appear!
Click here! I don't have enough reputation (but it works ;) )
And now you are finished!

Disable auto compilation of LESS

I am in Eclipse environment. I want LESS to compile only when explicitly invoked via mvn package. At the moment, as soon as I make any changes in my less file it propagates the change to CSS. What should I do to avoid this behaviour?
<plugin>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<version>1.7.0.1.1</version>
<configuration>
<watch>false</watch>
<sourceDirectory>src/main/webapp/css</sourceDirectory>
<outputDirectory>src/main/webapp/css</outputDirectory>
<compress>true</compress>
<force>true</force>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
<phase>package</phase>
</execution>
</executions>
</plugin>
also posted this issue here
As a workaround I have encapsulated LESS plugin inside a profile. On server side I invoke that profile to do LESS compilation
mvn package -pless_compile
M2Eclipse is an Eclipse plugin which provides tight integration for Maven. It determines who and when plugins should be executed. Each plugin can store lifecycle mapping metadata with data on which it based its decision (see M2E compatible maven plugins). By default this plugin is called on incremental builds:
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
<runOnConfiguration>false</runOnConfiguration>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
If you want to disable automatic compilation, then you need to add the following entry to your pom.xml:
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.lesscss</groupId>
<artifactId>lesscss-maven-plugin</artifactId>
<versionRange>[0,)</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore />
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
You need to define in which maven phase you want to execute your plugin, basically adding the phase tag under the execution tag. Take look to the following examples: http://maven.apache.org/guides/mini/guide-configuring-plugins.html#Using_the_executions_Tag.

How to set custom icon for javafx native package icon on Windows

I am trying to chance the icon of the exe file while creating native bundling of javafx packaging.
I tried adding icon into pom.xml but till it wont work out for me as it gives default icon
Using Intellij IDEA IDE which contain an Pom.xml creating an package by command = mvn jfx:build-native
Here is my pom.xml:
<build>
<plugins>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>1.5</version>
<configuration>
<mainClass>com.demoApp.testapp.testApplication</mainClass>
<!-- only required if signing the jar file -->
<keyStoreAlias>example-user</keyStoreAlias>
<keyStorePassword>example-password</keyStorePassword>
<permissions>
<permission>all-permissions</permission>
</permissions>
<icon>${basedir}/src/main/resources/images/logoIcon.ico</icon>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
I have added an icon path into pom.xml ${basedir}/src/main/resources/images/logoIcon.ico
that will run while native package execute but it wont work out for me
Is any other way to do it ?
Please suggest.
i tried fx tags in pom.xml using ant,here is my changes in pom.xml
<properties>
<javafx.tools.ant.jar>${env.JAVA_HOME}\lib\ant-javafx.jar</javafx.tools.ant.jar> </properties>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>create-launcher-jar</id>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target xmlns:fx="javafx:com.sun.javafx.tools.ant">
<taskdef
uri="javafx:com.sun.javafx.tools.ant"
resource="com/sun/javafx/tools/ant/antlib.xml"
classpath="${javafx.tools.ant.jar}"/>
<fx:application id="fxApp"
name="${project.name}"
mainClass="com.precisionhawk.flightplanner.FlightPlannerApp"/>
<fx:jar destfile="${project.build.directory}/${project.build.finalName}-launcher">
<fx:application refid="fxApp"/>
<fx:fileset dir="${project.build.directory}/classes"/>
</fx:jar>
<attachartifact file="${project.build.directory}/${project.build.finalName}-launcher.jar"
classifier="launcher"/>
<fx:deploy>
<fx:info>
<fx:icon href="${basedir}/src/main/deploy/logoIcon.ico"></fx:icon>
</fx:info>
</fx:deploy>
</target>
</configuration>
</execution>
</executions>
</plugin>
but it wont work out..
I just struggled with the same issue using Zonsky's great javafx-maven-plugin. As of version 1.5, which you also were using, the src/main/deploy directory will be added to the classpath. The icon you want to use could be added there and it will be available on the classpath for the native builder!
I added src/main/deploy/package/windows/myapp.ico there and it finally worked :)
For you:
Create src/main/deploy/package/windows/ folder
Add icon with name ${project.build.finalName}.ico
Run mvn jfx:build-native
I haven't played with it extensively - just got it to work and wanted to share. So if you want to use icon with different name, I don't know how. Not yet at least. The <icon>...</icon> section in the config section seems to be for webstart, so I haven't been using it.
Hope you get it to work!
You need to look at the logging while building a native app. That will tell you where the installer looks for the icon files and with wich name. For the default Windows native app it looks in ./package/windows/'appname'.ico
Can't remember where 'appname' comes from, but just look at the logging while building, it will tell you. (I use the Ant targets called from my pom btw)
you can do this:
`<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.8.3</version>
<configuration>
<vendor>YourCompany</vendor>
<mainClass>com.alan344.MapperGenApplication</mainClass>
<appName>mybatis-friend</appName>
<bundleArguments>
<icon>${project.basedir}/src/main/resources/image/icon.ico</icon>
</bundleArguments>
</configuration>
</plugin>`

Resources