How to modify the configuration file name when spring boot Maven is packaged, such as config. xml. re to config. XML - maven

我在兼容老项目时必须用到个config的配置文件
我该怎么用spring boot Maven 打包时如何修改配置文件名称,比如把config.xml.re修改成config.xml
已经解决
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<move file="${project.build.directory}/classes/config-${profileActive}.xml"
tofile="${project.build.directory}/classes/config.xml"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
</plugins>

Related

Mockserver maven plugin: init mockserver expectations from file

I'm using Mockserver maven plugin to mock some requests for integration tests.
My pom.xml looks like:
...
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>5.5.1</version>
<configuration>
<serverPort>1080</serverPort>
<logLevel>DEBUG</logLevel>
<initializationClass>com.mycompany.ExampleInitializationClass</initializationClass>
</configuration>
<executions>
<execution>
<id>run-mockserver</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
<execution>
<id>stop-mockserver</id>
<phase>post-integration-test</phase>
<goals>
<goal>stop</goal>
</goals>
</execution>
</executions>
</plugin>
...
Problem here is that I have to provide expectations using a class (com.mycompany.ExampleInitializationClass) and I want to provide expectations using a JSON file like described here:
http://www.mock-server.com/mock_server/initializing_expectations.html
I didn't find any way in the plugin configuration to initialize the Mockserver with the property:
-Dmockserver.initializationJsonPath
Is there any way to achieve that? Thanks in advance.
You just have to define initializationJson property specifying path to JSON file with expectations:
<plugin>
<groupId>org.mock-server</groupId>
<artifactId>mockserver-maven-plugin</artifactId>
<version>5.5.1</version>
<configuration>
<serverPort>1080</serverPort>
<logLevel>DEBUG</logLevel>
<initializationJson>expectations.json</initializationJson>
</configuration>
<executions>
...
</executions>
</plugin>
The catch here is that the file path is relative to testClasspath directory (e.g. ${project.basedir}/target/test-classes/), so you have to copy the expectation file there. You may use e.g. maven-antrun-plugin for this (as below) or
maven-resources-plugin.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>run</goal>
</goals>
<configuration>
<tasks>
<copy file="your/expectations.json" todir="${project.basedir}/target/test-classes/"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>

maven-javadoc-plugin : How could customize the package

My target that's extract whole javadoc in the package com.axonivy.compensation.entity to html my maven
I already tried with:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>domain-models</id>
<phase>prepare-package</phase>
<!-- <goals> <goal>javadoc</goal> </goals> -->
<goals>
<goal>jar</goal>
</goals>
<configuration>
<includes>com.axonivy.compensation.entity.*.java</includes>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
Or following this way https://maven.apache.org/plugins/maven-javadoc-plugin/examples/group-configuration.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<executions>
<execution>
<id>domain-models</id>
<phase>prepare-package</phase>
<!-- <goals> <goal>javadoc</goal> </goals> -->
<goals>
<goal>jar</goal>
</goals>
<configuration>
<groups>
<group>
<packages>com.axonivy.compensation.entity</packages>
</group>
</groups>
<additionalparam>-Xdoclint:none</additionalparam>
</configuration>
</execution>
</executions>
</plugin>
But still unsuccessfully. Now the javadoc of whole project are extracted, not just the package com.axonivy.compensation.entity,
Could anyone have some idea about that? Thanks

Inegration test using maven

I am trying to create something like integration tests - i am using groovy to send requests and to parse answers. I'd also want starting of jboss and deploying of .ear to be automatically. Using cargo plugin i was able to start jboss. By using exec plugin i am trying to execute perl script that puts ear to deploy folder. Next phase - execute groovy tests, but this phase starts without waiting for ear to be deployed. Is it possible to make phase to wait for server to be deployed to jboss? My pom:
<build>
<plugins>
<plugin>
<groupId>org.codehaus.groovy.maven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<id>unpack-application-server</id>
<phase>pre-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${basedir}/src/main/script/appserver/unzip.groovy</source>
<defaults>
<installDirectory>${appserver.install.directory}</installDirectory>
<zipUrl>${appserver.zip.url}</zipUrl>
</defaults>
</configuration>
</execution>
<execution>
<id>prepare-application-server-configs</id>
<phase>pre-integration-test</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>${basedir}/src/main/script/appserver/${suffix}/postUnzipAction.groovy</source>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<executions>
<execution>
<id>start-container</id>
<phase>pre-integration-test</phase>
<goals>
<goal>start</goal>
</goals>
</execution>
</executions>
<configuration>
<wait>false</wait>
<container>
<containerId>${appserver.id}</containerId>
<home>${appserver.home}</home>
<timeout>6000000</timeout> <!--in ms-->
</container>
<configuration>
<properties>
<cargo.servlet.port>${servlet.port}</cargo.servlet.port>
<cargo.rmi.port>${rmi.port}</cargo.rmi.port>
<!-- corresponds to -Djboss.bind.address=0.0.0.0 under jboss -->
<cargo.hostname>0.0.0.0</cargo.hostname>
</properties>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<executions>
<execution>
<id>deploy-with-script</id>
<phase>pre-integration-test</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>perl</executable>
<workingDirectory>.</workingDirectory>
<commandlineArgs>${deploy.pl.cmd} -x redeploy</commandlineArgs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
setup and tear down your server before and after integration test phase, something like that:
<executions>
<execution>
<id>start-tomcat</id>
<phase>pre-integration-test</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
<execution>
<id>stop-tomcat</id>
<phase>post-integration-test</phase>
<goals>
<goal>shutdown</goal>
</goals>
</execution>
</executions>
Rename your unit tests to be skipped by surefire but executed by maven-failsave-plugin to *IT.java: http://maven.apache.org/surefire/maven-failsafe-plugin/examples/inclusion-exclusion.html

Copy a jar file with maven

I'm trying to copy the .jar, created by Maven 3, to another location.
Currently, I'm using Ant's copy task, but Maven simply doesn't copy the file.
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<configuration>
<tasks>
<copy file="target/myfile.jar" tofile="D:/Bukkit/plugins/myfile.jar"/>
</tasks>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-antrun-plugin</artifactId>
<configuration>
<tasks>
<copy file="target/myfile.jar" tofile="D:/Bukkit/plugins/myfile.jar"/>
</tasks>
</configuration>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>run</goal>
</goals>
</execution>
</executions>
</plugin>

How can I combine jars using Maven?

The following snippet creates 2 JARS:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>build-dependency</id>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>dependency</classifier>
<classesDirectory>${project.build.directory}\dependency</classesDirectory>
<includes>
<include>${dependancyInclude}</include>
</includes>
</configuration>
</execution>
<execution>
<phase>compile</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>module</classifier>
<classesDirectory>${project.build.directory}\classes</classesDirectory>
</configuration>
</execution>
</executions>
</plugin>
I would like to combine these two JARs into one using the assembly plugin, currently I have the following:
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2</version>
<executions>
<!-- Combine all the JARs in the /target folder into one JAR -->
<execution>
<id>make-assembly</id>
<phase>compile</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<attach>true</attach>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${project.artifactId}-${project.version}</finalName>
<appendAssemblyId>true</appendAssemblyId>
</configuration>
</execution>
</executions>
</plugin>
Currently only one of the two JARS in included in the final JAR that is created by the assembly plugin.
If I understand you correctly, you actually want to merge the jar files into one big jar file. This can be achieved using the maven-shade-plugin (instead of the maven-assembly-plugin).
For example:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.0</version>
<configuration>
<!-- Put your configuration here, if you need any extra settings.
(You should be okay with the defaults). -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>

Resources