Maven plugin default phase - maven

I am trying to write a Hello World Maven plugin.
I assigned defaultPhase=LifecyclePhase.CLEAN to it but when I execute mvn clean it is not working.
When I execute mvn gorov:clean it is working.
Any suggestions?
DS
The code is:
Location in project: maven-plugin\src\main\java\com\gorovdude\plugins\maven\mojos\WriteConsoleMojo.java
package com.gorovdude.plugins.maven.mojos;
import java.io.File;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
#Mojo(name = "clean", defaultPhase = LifecyclePhase.CLEAN, threadSafe = true, aggregator = true)
public class WriteConsoleMojo extends AbstractMojo {
public void execute() throws MojoExecutionException, MojoFailureException {
try {
String path = "C:\\Apache-maven-3.2.5\\testing.txt";
System.out.println("testing");
File f = new File(path);
f.createNewFile();
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
}
}
}
The pom.xml of the plugin:
Location in maven-plugin\pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gorovdude</groupId>
<artifactId>gorov-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<description>gorov Maven Plugin</description>
<properties>
<mavenVersion>3.0</mavenVersion>
<mavenPluginVersion>3.1</mavenPluginVersion>
</properties>
<prerequisites>
<maven>${mavenVersion}</maven>
</prerequisites>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>${mavenVersion}</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>${mavenPluginVersion}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-artifact</artifactId>
<version>2.0.9</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>${mavenPluginVersion}</version>
<executions>
<execution>
<id>generate-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
<configuration>
<goalPrefix>gorov</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
</plugin>
</plugins>
</build>
</project>
The pom.xml that I run mvn commands on:
Location in Project: maven-plugin\src\test\pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.gorovdude</groupId>
<artifactId>test-gorov-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<description>Testing the plugin</description>
<build>
<plugins>
<plugin>
<groupId>com.gorovdude</groupId>
<artifactId>gorov-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
</plugin>
</plugins>
</build>
</project>

Your source code of the plugin can be called as following
<build>
<plugins>
<plugin>
<groupId>com.gorovdude</groupId>
<artifactId>gorov-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>clean</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
You have to specify the goal in the executions. if you type "maven clean", you just call the maven clean plugin, not yours. A plugin may contain multiple goals, unless you define in the executions of you project, which the goals you want to run, they won't run.
Look here: https://maven.apache.org/guides/plugin/guide-java-plugin-development.html

See the help text if you enter just mvn:
No goals have been specified for this build. You must specify a valid
lifecycle phase or a goal in the format <plugin-prefix>:<goal> [...].
Available lifecycle phases are: [...] , clean, [...].
If you enter mvn clean you're not invoking the clean goal of your plugin but the clean phase of the clean lifecycle (which has the clean goal of the [maven-]clean[-plugin] plugin bound to it by default).
If you enter mvn gorov:clean you're using the plugin prefix gorov declared in <goalPrefix>gorov</goalPrefix> in your plugin's POM (though this declaration wouldn't be necessary since the same prefix would be derived from the artifact ID of your plugin gorov-maven-plugin by default).
See also Maven: Lifecycle vs. Phase vs. Plugin vs. Goal.

Related

random csv data jmeter maven setup

I would like to integrate blazemeter random CSV data plugin set into my jmeter maven project. I am new to both maven and jmeter 3.2, but I have got a project built.
However there is no information on how I can setup the random CSV data plugin and how it should be setup in the configuration of the POM file.
So far, I have added the dependencies for the plugin, but there is no documentation on configuration within the pom file.
Dependency:
<dependency>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-cmn-jmeter</artifactId>
<version>0.5</version>
</dependency>
<dependency>
<groupId>org.apache.jmeter</groupId>
<artifactId>ApacheJMeter_components</artifactId>
<version>4.0</version>
</dependency>
<dependency>
<groupId>kg.apc</groupId>
<artifactId>jmeter-plugins-emulators</artifactId>
<version>0.4</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.blazemeter</groupId>
<artifactId>jmeter-plugins-random-csv-data-set</artifactId>
<version>0.6</version>
</dependency>
Is there a way I can configure the plugin in the verify stage or do I configure the plugin by adding in the properties.user and set the values within the in the pom file.
This is not how you should use dependencies in your JMeter Maven project, you should add any required JMeter Plugins into configuration/jmeterExtensions section like:
<configuration>
<jmeterExtensions>
<artifact>com.blazemeter:jmeter-plugins-random-csv-data-set:0.6</artifact>
<artifact>kg.apc:jmeter-plugins-emulators:0.4</artifact>
<artifact>kg.apc:jmeter-plugins-cmn-jmeter:0.5</artifact>
</jmeterExtensions>
<downloadExtensionDependencies>false</downloadExtensionDependencies>
</configuration>
Full pom.xml just in case:
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>mvn-jmeter</artifactId>
<version>1.0-SNAPSHOT</version>
<name>maven-jmeter-demo</name>
<url>http://maven.apache.org</url>
<build>
<plugins>
<plugin>
<groupId>com.lazerycode.jmeter</groupId>
<artifactId>jmeter-maven-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<id>jmeter-tests</id>
<phase>verify</phase>
<goals>
<goal>jmeter</goal>
</goals>
</execution>
</executions>
<configuration>
<jmeterExtensions>
<artifact>com.blazemeter:jmeter-plugins-random-csv-data-set:0.6</artifact>
<artifact>kg.apc:jmeter-plugins-emulators:0.4</artifact>
<artifact>kg.apc:jmeter-plugins-cmn-jmeter:0.5</artifact>
</jmeterExtensions>
<downloadExtensionDependencies>false</downloadExtensionDependencies>
</configuration>
</plugin>
</plugins>
</build>
</project>
More information:
Adding jar's to the /lib/ext directory
Five Ways To Launch a JMeter Test without Using the JMeter GUI

Custom maven plugin fails when mojo extends mojo from different module (no AbstractMojo)

I have mutli project with 2 maven plugin modules: base and child (<packaging>maven-plugin</packaging>). Child depend on base.
Base plugin has single class:
public abstract class BaseMojo extends AbstractMojo {}
with POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>plugin-set</groupId>
<artifactId>plugin-set</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>plugin-base</artifactId>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.3</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
<configuration>
<goalPrefix>my</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Child plugin has single class:
public abstract class ChildMojo extends BaseMojo {}
with POM:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>plugin-set</groupId>
<artifactId>plugin-set</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>plugin-child</artifactId>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.3</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>plugin-set</groupId>
<artifactId>plugin-base</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
<configuration>
<goalPrefix>my-child</goalPrefix>
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Base compiles correctly, child pass compilation but fails maven-plugin-plugin:3.4:descriptor:
Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.4:descriptor (default-descriptor) on project plugin-child: The API of the mojo scanner is not compatible with this plugin version. Please check the plugin dependencies configured in the POM and ensure the versions match. org/apache/maven/plugin/AbstractMojo: org.apache.maven.plugin.AbstractMojo -> [Help 1]
How to build child module?
Both base and child has almost identical pom.xml, child has 1 more dependency: to base
Source: https://github.com/michaldo/mojo-extend-mojo
The direct solution to your compilation issue is to remove <scope>provided</scope> from the maven-core dependency in plugin-child.
However, although it will compile after that, there are a lot of changes to be made to your project for it to work.
You should have a clear view of what a Mojo is and how it is implemented.
First of all, a Mojo should comply to a simple contract, which is implementing the Mojo interface.
Although the requirements on Mojos are minimal by design, there are still a very few requirements that Mojo developers must keep in mind. Basically, these Mojo requirements are embodied by the org.apache.maven.plugin.Mojo interface, which the Mojo must implement (or else extend its abstract base class counterpart org.apache.maven.plugin.AbstractMojo).
You can have a hierarchy of abstract classes but the top-most abstract one should inherit from AbstractMojo (or implement Mojo). Having a common abstract parent class is not uncommon. It is done by a lot of standard Maven plugins, like the maven-install-plugin.
What is important to note that the abstract classes are simply there to factor common code from multiple Mojo in a plugin. They do not represent a goal. As such, the plugin-base module, which contains your abstract superclass:
should not be packaged as a maven-plugin.
should not declare an execution of the maven-plugin-plugin plugin.
The concrete Mojo is inside plugin-child so it is this module that should be packaged as a maven-plugin. Since this will be the concrete implementation, it must not be abstract and it can be annotated with #Mojo to ease its declaration:
#Mojo(name = "child")
public class ChildMojo extends BaseMojo {
#Override
public void execute() throws MojoExecutionException, MojoFailureException {
}
}
This declares the goal "child" for this Mojo.
Sample code
plugin-base
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>plugin-set</groupId>
<artifactId>plugin-set</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>plugin-base</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.3</version>
</dependency>
</dependencies>
</project>
with the only class being
import org.apache.maven.plugin.AbstractMojo;
public abstract class BaseMojo extends AbstractMojo { }
plugin-child
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>plugin-set</groupId>
<artifactId>plugin-set</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>plugin-child</artifactId>
<packaging>maven-plugin</packaging>
<dependencies>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.4</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-core</artifactId>
<version>3.3.3</version>
</dependency>
<dependency>
<groupId>plugin-set</groupId>
<artifactId>plugin-base</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.4</version>
<configuration>
<goalPrefix>my-child</goalPrefix>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
with the following Java code:
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.Mojo;
#Mojo(name = "child")
public class ChildMojo extends BaseMojo {
#Override
public void execute() throws MojoExecutionException, MojoFailureException {
}
}
Finally, you can test that this works by depending on this plugin:
<plugin>
<groupId>plugin-set</groupId>
<artifactId>plugin-child</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<id>foo</id>
<goals>
<goal>child</goal>
</goals>
<phase>install</phase>
</execution>
</executions>
</plugin>
If you build the test project depending on plugin-child then you will correctly see Maven invoking it, on the install phase here.

NoSuchFieldError: RESOURCE_PREFIX with a maven project using tess4j

tess4j is an OCR packed with native library, I made a maven project to test it,
I did add the installation path of maven to eclipse.
I added M2_HOME, MAVEN_HOME and JAVA_HOME env variable,
here is my parent pom
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.mssb.ongoing</groupId>
<artifactId>ongoing-parent</artifactId>
<packaging>pom</packaging>
<version>1.0</version>
<name>ongoing</name>
<modules>
<module>capcha-solver</module>
</modules>
<build>
<pluginManagement>
<plugins>
<!-- All project will be interpreted (source) and compiled (target) in java 7 -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<!-- this will make eclipse:eclipse goal work and make the project Eclipse compatible -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-eclipse-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<downloadSources>true</downloadSources>
<downloadJavadocs>true</downloadJavadocs>
<classpathContainers>
<classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.7</classpathContainer>
</classpathContainers>
<additionalBuildcommands>
<buildcommand>net.sf.eclipsecs.core.CheckstyleBuilder</buildcommand>
</additionalBuildcommands>
<additionalProjectnatures>
<projectnature>net.sf.eclipsecs.core.CheckstyleNature</projectnature>
</additionalProjectnatures>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<!-- All child pom will inherit those dependancies -->
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
and here is my child pom
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>fr.mssb.ongoing</groupId>
<artifactId>ongoing-parent</artifactId>
<version>1.0</version>
</parent>
<groupId>fr.mssb.ongoing</groupId>
<artifactId>capcha-solver</artifactId>
<version>1.0</version>
<packaging>jar</packaging> <!-- I think this is useless -->
<name>A capcha solver based on terassec ocr</name>
<build>
<plugins>
<!-- autorun unit tests during maven compilation -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>-Xmx1024m -XX:MaxPermSize=256m -XX:-UseSplitVerifier</argLine>
<skipTests>-DskipTests</skipTests>
</configuration>
</plugin>
<!-- this should make the tesseract ocr native dll work without doing anything -->
<plugin>
<groupId>com.googlecode.mavennatives</groupId>
<artifactId>maven-nativedependencies-plugin</artifactId>
<version>0.0.7</version>
<executions>
<execution>
<id>unpacknatives</id>
<goals>
<goal>copy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!--
Log4j 2 is broken up in an API and an implementation (core), where the API
provides the interface that applications should code to. Strictly speaking
Log4j core is only needed at runtime and not at compile time.
However, below we list Log4j core as a compile time dependency to improve
the startup time for custom plugins.
-->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.1</version>
</dependency>
<!--
Integration of tesseract OCR
-->
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>
</project>
and of course, the code (taken from tess4j example)
package test;
import java.io.File;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;
/**
* Classe d'exemple.
*/
public class TesseractExample {
public static void main(String[] args) {
File imageFile = new File("C:\\DEV\\repo\\ongoing\\capcha-solver\\src\\test\\resources\\random.jpg");
Tesseract instance = Tesseract.getInstance(); // JNA Interface Mapping
// Tesseract1 instance = new Tesseract1(); // JNA Direct Mapping
try {
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
}
}
When I lauch it I'm getting this exception
Exception in thread "main" java.lang.NoSuchFieldError: RESOURCE_PREFIX
at net.sourceforge.tess4j.util.LoadLibs.<clinit>(LoadLibs.java:60)
at net.sourceforge.tess4j.TessAPI.<clinit>(TessAPI.java:40)
at net.sourceforge.tess4j.Tesseract.init(Tesseract.java:303)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:239)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:188)
at net.sourceforge.tess4j.Tesseract.doOCR(Tesseract.java:172)
at test.TesseractExample.main(TesseractExample.java:19)
I don't know if this is tess4j related or a JNA/JNI problem, as you can see I have a plugin that "should" (never worked with DLLs before) make them work.
Also in the parent pom my plugin are betwen plugin managment tags, I think I should have put them betwen build tags, no?
Any idea?
Thanks.
There was 2 problems
1/ some dlls and files from tess4j had to be copied to the project root directory
2/ tess4j had a transitive dependancy toward com.sun.jna:jna:jar:3.0.9 conflicting with net.java.dev.jna:jna:jar:4.1.0 (also from tess4j) ecluding the 3.0.9 version makes everything work, the RESSOURCE_PREFIX error was coming from that
pom.xml for 32 bit version (you need a 32 bit JVM installed) which takes care of those 2 things, change win32-x86 to win32-x86-64 if you want to use this in 64 bits
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>fr.mssb.ocr</groupId>
<artifactId>tesseractOcr</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<name>tesseract ocr project</name>
<build>
<plugins>
<!--
this extract the 32 bits dll and the tesseractdata folder to
the project root from tess4j.jar
-->
<plugin>
<groupId>org.apache.portals.jetspeed-2</groupId>
<artifactId>jetspeed-unpack-maven-plugin</artifactId>
<version>2.2.2</version>
<dependencies>
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>1.4.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>unpack-step</id>
<phase>compile</phase>
<goals>
<goal>unpack</goal>
</goals>
<configuration>
<unpack>
<artifact>net.sourceforge.tess4j:tess4j:jar</artifact>
<overwrite>true</overwrite>
<resources combine.children="append">
<resource>
<path>win32-x86</path>
<destination>../</destination>
<overwrite>true</overwrite>
<flat>true</flat>
<include>*</include>
</resource>
<resource>
<path>tessdata</path>
<destination>../tessdata</destination>
<overwrite>true</overwrite>
<flat>true</flat>
<include>*</include>
</resource>
<resource>
<path>tessdata/configs</path>
<destination>../tessdata/configs</destination>
<overwrite>true</overwrite>
<flat>true</flat>
<include>*</include>
</resource>
</resources>
</unpack>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>1.4.1</version>
<exclusions>
<exclusion>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
</project>
The child pom could be easily built without any problems and manually copying libs, this is not TESS4J related.
Anyway the jna 3.0.9 could be removed if not needed anymore: https://github.com/nguyenq/tess4j/issues/8
Still, all you have to do to run tess4j is the maven dependency:
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>1.4.1</version>
</dependency>
and the correct use of the TESS4J-API, for example:
File imageFile = new File("C:\\random.png");
Tesseract instance = Tesseract.getInstance();
//In case you don't have your own tessdata, let it also be extracted for you
File tessDataFolder = LoadLibs.extractTessResources("tessdata");
//Set the tessdata path
instance.setDatapath(tessDataFolder.getAbsolutePath());
try {
String result = instance.doOCR(imageFile);
System.out.println(result);
} catch (TesseractException e) {
System.err.println(e.getMessage());
}
That's it!
The problem is caused by the conflict between net.java.dev.jna:jna and com.sun.jna:jna. Both jars contain a class com.sun.jna.Platform. Both jars are declared as tess4j dependencies. To solve this you can omit the second dependency in your pom:
<dependency>
<groupId>net.sourceforge.tess4j</groupId>
<artifactId>tess4j</artifactId>
<version>1.4.1</version>
<exclusions>
<exclusion>
<groupId>com.sun.jna</groupId>
<artifactId>jna</artifactId>
</exclusion>
</exclusions>
</dependency>
because the JNA version mismatch. you are using more than one version in class path library. just use one version of JNA.

copy jars used by plugin to single folder using Maven

In my POM.xml other the plugin configuration, i am not required to configure any dependenices to run the plugin. I would like to download dependent jars used by plugin(soapui-maven-plugin) from the repository into one single folder. I tried the command "mvn dependency:copy-dependencies", but no jars are copied. Is there any way to do it?
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>service.report</groupId>
<artifactId>service-report</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Maven 2 SoapUI Sample</name>
<build>
<plugins>
<plugin>
<groupId>com.smartbear.soapui</groupId>
<artifactId>soapui-maven-plugin</artifactId>
<version>5.0.0</version>
<executions>
<execution>
<phase>test</phase>
<goals>
<goal>loadtest</goal>
</goals>
<configuration>
<projectFile>${basedir}/src/main/resources/xxxxx-soapui-project.xml</projectFile>
<testSuite>xxxx</testSuite>
<testCase>sssss</testCase>
<loadTest>LoadTest 1</loadTest>
<outputFolder>${basedir}/target/surefire</outputFolder>
<junitReport>true</junitReport>
<exportAll>true</exportAll>
<printReport>true</printReport>
<testFailIgnore>false</testFailIgnore>
<!-- <projectProperties>
<value>message=Hello World!</value>
</projectProperties> -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
mvn dependency:copy-dependencies is only applied to current maven module only. It won't works on plugins. If you want to download all soapui-maven-plugin dependencies, you need to execute command from soapui-maven-plugin project. You can follow the following steps. I assumed you familiar with GIT CLI. If not, you need to manually download from https://github.com/SmartBear/soapui
git clone https://github.com/SmartBear/soapui
cd soapui/soapui-maven-plugin
mvn dependency:copy-dependencies
You can get list of dependencies in soapui/soapui-maven-plugin/target/dependency (total 82files)
[ERROR] Failed to execute goal on project soapui-maven-plugin: Could not resolve dependencies for project com.smartbear.soapui:soapui-maven-plugin:maven-plugin:5.0.0: Could not find artifact javafx:jfxrt:jar:2.2 at specified path (your jdk path)
If you get the above error, it means your maven jdk is version jdk.1.7 (u6 or earlier) which is not installed with javafx. Download newer jdk that comes with javafx at http://www.oracle.com/technetwork/java/javase/downloads/jdk7-downloads-1880260.html . Remember change your maven jdk to this newer jdk.
If you want to use the dependency-plugin you could add the dependencies to the pom...and download with the depepndency-plugin...
It works right for me...
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.ab.forge.utility.copydependenciespom</groupId>
<artifactId>copydependenciespom</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<!-- BINARIES -->
<dependencies>
<!--CUSTOMER RETURN -->
<dependency>
<groupId>com.ab...</groupId>
<artifactId>customerret.....</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<overWriteIfNewer>true</overWriteIfNewer>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<excludeGroupIds>com.ab.ah.scad.acl</excludeGroupIds>
<excludeTypes>pom</excludeTypes>
<includeGroupIds>com.ab.oneleo</includeGroupIds>
<outputDirectory>${outputDirectory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
After I just run the install passing the -DoutputDirectory parameter....
Try this...
To view all the plugin dependencies you can run a dependency:tree on the pom (where the plugin in configured)

Dependency management does not work for multi-module project

I have a Maven project with multiple modules and I'm trying to set it up so that module dependencies are automatically built to the correct lifecycle phase needed for building depending modules to the requested lifecycle phase.
In the example, the module plugin builds a Maven plugin, which is used to generate source code and is used by the module main. If I just try to use mvn -am -pl main compile, the module plugin is compiled but the process-classes lifecycle phase is not executed (which is necessary for a plugin to be usable). Compiling the module main then fails then with the following error:
[ERROR] Failed to parse plugin descriptor for example:plugin:1.0.0-SNAPSHOT (/Users/ims/Dropbox/IMS/Projects/PARITy_R4/codegen-test-simple/plugin/target/classes): No plugin descriptor found at META-INF/maven/plugin.xml -> [Help 1]
Is Maven, or a plugin for it, capable of resolving the dependencies of modules in a multi-module project and build them to stage necessary by other modules? And if so, how do I need to set up the project for this to work?
These are the POMs of my project:
pom.xml:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>plugin</module>
<module>main</module>
</modules>
</project>
plugin/pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>maven-plugin</packaging>
<parent>
<groupId>example</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<dependencies>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugin-tools</groupId>
<artifactId>maven-plugin-annotations</artifactId>
<version>3.2</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.2</version>
<configuration>
<goalPrefix>configurator</goalPrefix>
</configuration>
<executions>
<execution>
<id>default-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
<phase>process-classes</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
main/pom.xml:
<project xmlns="http://maven.apache.org/POM/4.0.0">
<modelVersion>4.0.0</modelVersion>
<groupId>example</groupId>
<artifactId>main</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<parent>
<groupId>example</groupId>
<artifactId>project</artifactId>
<version>1.0.0-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>example</groupId>
<artifactId>plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<executions>
<execution>
<goals>
<goal>codegen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
If you look at the reference documentation for the Maven lifecycle, you'll see that compile is before process-classes.
If you want this step to happen, you need to use mvn -am -pl main process-classes instead.
But I suggest that you always use mvn ... install - it also runs the tests and makes sure that the plugin which main uses is actually the one you think it should: Without install, the build will use an old/outdated version from the local repository (Maven will not magically determine "oh, there is a plugin in my reactor, I'll use that instead of the version from the local repo").

Resources