How to set -Euwc param with axis2-wsdl2code-maven-plugin? - maven

We are using axis2 to generate web-service clients, (I regret this now!). With axis2 command-line tool you can pass switch -Euwc to wrap int into Integer, boolean into Boolean and so on in generated soruces. This is the one way to tell axis2 that its OK for certain int or boolean values to be nillable in schema.
My question is how do you set this parameter via POM or other means with Maven to achieve same behaviour with genrated sources? My stackoverflow and google searches aren't revealing much. There's a Jira issue, which seems to be closed by developers without pointing in right direction.
<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.futile.bizzareservice</groupId>
<artifactId>BizzareService</artifactId>
<version>2.0</version>
<name>BizzareService</name>
<properties>
<wsdl.location>unfortunate-wsdls</wsdl.location>
<axis2.version>1.5.4</axis2.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-wsdl2code-maven-plugin</artifactId>
<version>${axis2.version}</version>
<configuration>
<packageName>com.futile.bizzareservice.client</packageName>
<wsdlFile>${wsdl.location}/bizzareservice.wsdl</wsdlFile>
<language>java</language>
<databindingName>adb</databindingName>
<unpackClasses>true</unpackClasses>
</configuration>
<executions>
<execution>
<goals>
<goal>wsdl2code</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>${axis2.version}</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb-codegen</artifactId>
<version>${axis2.version}</version>
</dependency>
</dependencies>
</project>
Setting unwrap to true in configuration doesn't help, as it's a different option all together. I will look to avoid axis2 in the future but for time being we're stuck with it.

After long meditation with sources I found solution: insert
<options>
<uwc>true</uwc>
</options>
in configuration section.

Use
<options>
<osv>true</osv>
<iu>true</iu>
</options>
This only works with 1.7.2 version of Axis

Related

No schemas have been found - Spring Boot WS

I have the next throuble:
When I follow the Spring boot WS example with maven, when I follow the steps, after add the xsd file, the guide indicate how to add the plugin to pom.xml file and this automatically turn the xsd file into java class objects. But I've received this:
No schemas have been found (org.codehaus.mojo:jaxb2-maven-plugin:1.6:xjc:xjc:generate-sources)
org.apache.maven.plugin.MojoExecutionException: No schemas have been found
at org.codehaus.mojo.jaxb2.AbstractXjcMojo.execute(AbstractXjcMojo.java:376)
at org.apache.maven.plugin.DefaultBuildPluginManager.executeMojo(DefaultBuildPluginManager.java:134)
at org.eclipse.m2e.core.internal.embedder.MavenImpl.execute(MavenImpl.java:331)
at org.eclipse.m2e.core.internal.embedder.MavenImpl$11.call(MavenImpl.java:1362)
...
Here is my 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.tester</groupId>
<artifactId>test-ws</artifactId>
<version>0.0.1</version>
<packaging>war</packaging>
<name>test-ws</name>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.10.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>wsdl4j</groupId>
<artifactId>wsdl4j</artifactId>
</dependency>
</dependencies>
<properties>
<java.version>1.7</java.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<schemaDirectory>${project.basedir}/src/main/resources/</schemaDirectory>
<outputDirectory>${project.basedir}/src/main/java</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
</plugins>
</build>
This is a screenshot how is look like the error:
Any help is appreciated!
Ok, if someone has the same error, I got the solution like this:
First, I configured the maven user settings in eclipse by adding a separate repository folder for the related project (Override the default path located in X:\Users\User.m2\repository).
I removed two custom profiles that I had in the previous file.
I updated the project and magically, the error disappeared.
Thanks to all for the help.

Transitive maven plugin dependency configuration

If I have two maven plugins, where A depends on B and B has configuration parameters, how and where should I define configuration for B?
I could think of three solutions, which of one I know is not applicable, and I'm not sure which one works, or there are any more possiblities. Unfortunately, I couldn't find any example even for this simple case.
Try 1 (not possible)
Put <configuration> under dependencies. This is not possible as a <dependency> tag cannot contain a <configuration> tag (see xsd).
<plugin>
<groupId>A</groupId>
<artifactId>A</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
<configuration>
<paramForB><param>bbb</param></paramForB>
</configuration>
</dependency>
</dependencies>
</plugin>
Try 2
Put the configuration parameter under the config of A.
<plugin>
<groupId>A</groupId>
<artifactId>A</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<configuration>
<paramForB><param>bbb</param></paramForB>
</configuration>
</plugin>
Try 3
Introduce B as a separate plugin with the configuration I need.
<plugin>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
<configuration>
<paramForB><param>bbb</param></paramForB>
</configuration>
</plugin>
<plugin>
<groupId>A</groupId>
<artifactId>A</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
</plugin>
Further questions (just curious)
Also, what if B depends on C. How should I configure C?
And if I have a maven plugin X which also depends on B but would use it with other configuration: can I do that?
In maven you have profiles and properties.
First start with properties:
Project B
<properties>
<customeParameter>parameterInB</customeParameter>
</properties>
<plugin>
<groupId>A</groupId>
<artifactId>A</artifactId>
<version>1.0.0</version>
<dependencies>
<dependency>
<groupId>B</groupId>
<artifactId>B</artifactId>
<version>1.0.0</version>
<configuration>
<paramForB>${customeParameter}</paramForB>
</configuration>
</dependency>
</dependencies>
</plugin>
Project A
<properties>
<customeParameter>overrideInA</customeParameter>
</properties>
See my answer to question: How to get a command-line property to overwrite a maven property
My example will work if project B is a parent for project A. If not, please define share configuration in parent pom (which will be parent for A and B) and parametrize it. Then in child you can define in "properties" section values for this configuration.
The answer is basically Try 2, i.e., add configurations of B to the plugin usage A, but it depends on how plugin A was implemented as it its responsibility to pass the parameters.

Flexmojos-maven-plugin - How to configure multiple source mxml files to generate multiple swf files?

Current working code:
I am able to build a flex project using flexmojos-maven-plugin successfully. However, I can only provide one 'sourceFile' under my plugin configuration. Refer below my working pom.xml, which builds Main.mxml file correctly from 'src' directory. It generates the 'swf' file for Main.mxml successfully:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.test</groupId>
<artifactId>TA_UI_Test2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>swf</packaging>
<name>TA_UI_Test2 Flex</name>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>playerglobal</artifactId>
<version>10-3.3.0.4852</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>rpc</artifactId>
<version>4.5.1.21328</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>framework</artifactId>
<version>3.2.0.3958</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>mx</artifactId>
<version>4.5.0.19786</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.8</version>
<extensions>true</extensions>
<configuration>
<sourceFile>Main.mxml</sourceFile>
<debug>true</debug>
<storepass/>
</configuration>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>3.2.0.3958</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Problem description:
Now I have got multiple other mxml files under my 'src' directory, i.e. all mxml files under one single 'src' directory. How do I add them in above plugin, which only expects one single name in sourceFile configuration?
Things I have tried:
I tried copy-pasting multiple blocks of flexmojos-maven-plugin, and each of them having different sourceFile specified. However, that does not help, because maven just generates the final 'swf' file from the last block of flexmojos-maven-plugin. For eg. if first plugin block has sourceFile Main.mxml, and second plugin block has sourceFile Secondary.mxml, then the 'swf' will be generated for Secondary.mxml only, not for Main.mxml.
Could you provide any other suggestions to generate individual swf files for respective mxml files using single pom/maven build?
After quite a lot of R&D, trying a few hacks, and based on valuable suggestion of Christofer Dutz on this forum, finally a clean solution is available for above problem. Here is the updated pom.xml, which will generate the individual swf files for provided source files:
<?xml version="1.0" encoding="UTF-8"?>
<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>com.test</groupId>
<artifactId>TA_UI_Test2</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>swf</packaging>
<name>TA_UI_Test2 Flex</name>
<dependencies>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>playerglobal</artifactId>
<version>10-3.3.0.4852</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>rpc</artifactId>
<version>4.5.1.21328</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>framework</artifactId>
<version>3.2.0.3958</version>
<type>swc</type>
</dependency>
<dependency>
<groupId>com.adobe.flex.framework</groupId>
<artifactId>mx</artifactId>
<version>4.5.0.19786</version>
<type>pom</type>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.sonatype.flexmojos</groupId>
<artifactId>flexmojos-maven-plugin</artifactId>
<version>3.8</version>
<extensions>true</extensions>
<configuration>
<storepass></storepass>
</configuration>
<executions>
<execution>
<id>default-compile-swf</id> <!--DO NOT change this ID, else the plugin execution will fail.-->
<configuration>
<sourceFile>File1.mxml</sourceFile>
<debug>true</debug>
<output>${basedir}/target/File1.swf</output>
</configuration>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
<execution>
<id>default-compile-swf-2</id>
<configuration>
<sourceFile>File2.mxml</sourceFile>
<debug>true</debug>
<output>${basedir}/target/File2.swf</output>
</configuration>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
<execution>
<id>default-compile-swf-3</id>
<configuration>
<sourceFile>File3.mxml</sourceFile>
<debug>true</debug>
<output>${basedir}/target/File3.swf</output>
</configuration>
<goals>
<goal>compile-swf</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>com.adobe.flex</groupId>
<artifactId>compiler</artifactId>
<version>3.2.0.3958</version>
<type>pom</type>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
</project>
Important note: You have to provide the ID of any one of the executions as 'default-compile-swf', without which it would fail to identify the source file. For more information on the error which it will throw, refer to the link of the forum given above where I was discussing the same.
Hope this helps someone someday :)

Testng-Xslt reports are not getting generated

I have gone through many posts and blogs but couldn't generate reportng or testng-xslt reports via maven. Finally I have got this tutorial but no luck. I cant understand what am I missing.
Here's what I have tried : It successfully generates the surefire reports in the target folder but does"nt create(generate reports) a directory for reportng reports.Following is my Pom.xml file.
<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>tiger</groupId>
<artifactId>SampleProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>SampleProject</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>2.45.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.9.6</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>testng.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<reporting>
<plugins>
<!-- TestNG-xslt related configuration. -->
<plugin>
<groupId>org.reportyng</groupId>
<artifactId>reporty-ng</artifactId>
<version>1.2</version>
<configuration>
<!-- Output directory for the testng xslt report -->
<outputDir>/target/testng-xslt-report</outputDir>
<sortTestCaseLinks>true</sortTestCaseLinks>
<testDetailsFilter>FAIL,SKIP,PASS,CONF,BY_CLASS</testDetailsFilter>
<showRuntimeTotals>true</showRuntimeTotals>
</configuration>
</plugin>
</plugins>
</reporting>
</project>
Looks like they have removed reporty-ng plugin from maven repository, so you may not be able to generate xslt report directly through maven.
If you want to generate XSLT reports you can take help of Ant XSLT
If you don't like the default report for any reasons, you can write your own one by implementing IReporter:
http://testng.org/doc/documentation-main.html#logging
I believe you are using below
<pluginRepositories>
<pluginRepository>
<id>reporty-ng</id>
<url>https://github.com/cosminaru/reporty- ng/raw/master/dist/maven</url>
Url is not working. They have removed it from that URL. However, I think you can use this URL https://github.com/prashanth-sams/testng-xslt-1.1.2/tree/master/src/main/java/org/testng/xslt/mavenplugin . I haven't tried it though.
You can download it from. https://drive.google.com/drive/folders/0B5v_nInLNoquV1p5YWtHc3lkUkU

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.

Resources