Run a spring boot app located on another project before running karate tests? [duplicate] - spring-boot

This question already has an answer here:
Is there a way to run Karate tests as an integration test suite against a pre-booted spring boot server?
(1 answer)
Closed 2 years ago.
I'm trying to build some karate tests to a spring boot application. Here's the project structure :
co-training-backend (parent)
|_ co-training-rest (maven module)
|_ co-training-rest-karate (maven module)
If i run the server and launch the karate tests everything works fine. Now i'd like to automate that by running the server from the rest-karate module.
Here's my config :
class CoTrainingTests {
private static ConfigurableApplicationContext context = null;
#BeforeAll
public static void setUp() throws Exception {
context = SpringApplication.run(RestBootstrap.class, new String[]{});
}
#Karate.Test
Karate testAll() {
return Karate.run().relativeTo(getClass());
}
#AfterAll
public static void tearDown() throws Exception {
if(context!=null)
context.stop();
}
}
pom.xml
<artifactId>co-training-rest-karate</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<junit-jupiter.version>5.6.2</junit-jupiter.version>
<karate.version>0.9.6</karate.version>
<maven.compiler.version>3.8.1</maven.compiler.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit-jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-apache</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.intuit.karate</groupId>
<artifactId>karate-junit5</artifactId>
<version>${karate.version}</version>
<scope>test</scope>
</dependency>
<!-- this is the spring boot rest project -->
<dependency>
<artifactId>co-training-rest</artifactId>
<groupId>com.co.training</groupId>
<version>1.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<testResources>
<testResource>
<directory>src/test/java</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</testResource>
</testResources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<encoding>UTF-8</encoding>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.2</version>
<configuration>
<argLine>-Dfile.encoding=UTF-8</argLine>
</configuration>
</plugin>
</plugins>
</build>
If i run the tests from the command line i have this maven compiler error :
mvn clean test
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:testCompile (default-testCompile) on project co-training-rest-karate: Compilation failure
[ERROR] /home/salto/tutorials/co-training/co-training-backend/co-training-rest-karate/src/test/java/cotraining/CoTrainingTests.java:[3,28] package com.co.training.rest does not exist
but this class exists in the rest dependency :
ls /home/salto/.m2/repository/com/co/training/co-training-rest/1.0.0-SNAPSHOT/co-training-rest-1.0.0-SNAPSHOT.jar
/home/salto/.m2/repository/com/co/training/co-training-rest/1.0.0-SNAPSHOT/co-training-rest-1.0.0-SNAPSHOT.jar
any idea ?

You can use the integration-test phase of the maven lifecycle:
pre-integration-test: start the co-training-rest module
integration-test: run you karate integration tests
post-integration-test: shut down the co-training-rest module and do
any other necessary cleanup

Related

Junit test works only when renamed test class name

I am using junit4 to run test. My test class is as below in test->java->com.example->ProductIT.java
When I run mvn clean install on my project, below test is not recognized and not run.
However, when I rename the test class to ProductTest, it works.
I do not understand the difference. Why does it work when I rename ?
#ContextConfiguration(locations = {"classpath:META-INF/spring/test-config.xml"})
#RunWith(SpringJunit4ClassRunner.class)
public class ProductIT{
#Autowried
private ProductServiceImpl serviceImpl;
#Test
public void test() throws Exception{
assertNotNull(serviceImpl)
}
}
pom.xml
<dependencyManagement>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-core></artifactId>
<version>4.2.4-RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.batch</groupId>
<artifactId>spring-batch-infrastructure></artifactId>
<version>4.2.4-RELEASE</version>
</dependency>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-batch></artifactId>
<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter></artifactId>
<dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test></artifactId>
<scope>test</scope>
<dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
The *IT postfix (for integration test) is the default test identifier for the Maven Failsafe plugin. Spring Boot projects don't contain this plugin by default and you have to explicitly add it to your project.
The *Test postfix is the default test identifier for the Maven Surefire Plugin which is used as part of the test phase of the default lifecycle: mvn test.
This answer sheds more light on the differences between these plugins.
In case you want to split your tests (unit & integration) and run them separately (first unit, then integration), add the Maven Failsafe Plugin to your project:
<project>
<!-- other dependencies -->
<build>
<!-- further plugins -->
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M5</version>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
... and it should recognize your existing ProductIT when you run mvn verify (or mvn install).
For more information on such testing defaults and standards, consider this guide on testing Java applications with Maven.

RestController works fine in SpringBoot, but throws 404 on Tomcat

I have a simple RestController application -
#RestController
public class GreetingController {
private static final Logger logger = LogManager.getLogger(GreetingController.class);
#RequestMapping("/greeting")
public ResponseEntity<GreetingResponse> greeting(#RequestParam(value = "name", defaultValue = "World") String name) throws ServiceException, Exception {
logger.info("Received Request. Name: " + name);
It works fine on SpringBoot (http://localhost:8080/greeting), but when I create a WAR and deploy it on Tomcat (9.0.2), it throws a 404.
Application is deployed fine and I can hit a static HTML page in the application, so my context path is correct.
What could I be missing?
Here is my gradle tasks -
dependencies {
compile("org.springframework.boot:spring-boot-starter-web")
providedRuntime 'org.springframework.boot:spring-boot-starter-tomcat'
testCompile('org.springframework.boot:spring-boot-starter-test')
testCompile('com.jayway.jsonpath:json-path')
compile group: 'org.apache.logging.log4j', name: 'log4j-api', version: '2.10.0'
compile group: 'org.apache.logging.log4j', name: 'log4j-core', version: '2.10.0'
}
war {
archiveName = "ROOT.war"
manifest {attributes "Implementation-Version": "${version}"}
}
I have zip of my whole application here, if anyone is curious.
Found the issue. My application had to extend SpringBootServletInitializer
#SpringBootApplication
public class Application extends SpringBootServletInitializer {
Your answer is correct, I just wanted to add on it, that if you have the requirement where you need to create a war file for your application and deploy it on an external app server like Tomcat or IBM Liberty, it is is best you disable the inbuilt tomcat starter when deploying it in external App servers. This can be done via using profiles tag in your POM file and using the exclusion tag to specify that you do not need "spring-boot-starter-tomcat"
Our POM looks like this
<groupId>com.anz.tpp</groupId>
<artifactId>example-project</artifactId>
<packaging>war</packaging>
<version>1.0.0-SNAPSHOT</version>
<name>Example Project</name>
<!-- Versions -->
<properties>
<apache.camel.version>X.X.X</apache.camel.version>
<junit.version>X.X</junit.version>
</properties>
<!-- Spring Boot Parent -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.1.RELEASE</version>
<relativePath />
</parent>
<profiles>
<profile>
<id>dev</id>
<properties>
<activatedProperties>dev</activatedProperties>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
<configuration>
<skip>true</skip>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>local</id>
<properties>
<activatedProperties>local</activatedProperties>
</properties>
<activation>
<activeByDefault>true</activeByDefault>
</activation>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>
.......
</profile>
</profiles>
Not sure if this is really a concern at your end, but it is best to operate under two profiles where you use one profile to run your project through an IDE like intelliJ or Eclipse and other way, you can use the dev profile to build your package by specifying "mvn clean install -U -P dev" to deploy the war file in an external appserver like tomcat or IBM Liberty.
My apologies if you have already figured it out, just that this helped me during my starting stages of my spring-boot project. Hope this helps!

NoClassDefFoundError when attempting to run unit tests when building Jenkins plugin

I have a custom Jenkins plugin that I've built. I have some test cases that leverage some code out of the jenkins-test-harness project (namely the Junit JenkinsRule.)
Anyway, the unit tests run and pass when I run them in IntelliJ. No exceptions, no errors.
When I try to run them from the Maven commandline, however, all of the tests that rely on the JenkinsRule fail:
[ERROR] testGetLastDate(com.mycompany.myplugin.portlet.utils.UtilsHudsonTest) Time elapsed: 0 s <<< ERROR!
java.lang.NoClassDefFoundError: Could not initialize class org.jvnet.hudson.test.TestPluginManager
at org.jvnet.hudson.test.JenkinsRule.<init>(JenkinsRule.java:325)
at com.mycompany.myplugin.portlet.utils.UtilsHudsonTest.<init>(UtilsHudsonTest.java:19)
That TestPluginManager is in the jenkins-test-harness jar. The JenkinsRule that attempts to call it is right next to it in the same package in the same jar, so clearly the jar itself is successfully on the classpath.
I can't quite figure out why I can't run this job from the commandline using mvn test.
My POM is very simple -- I declare a Parent on the Jenkins plugin-3.2 pom:
<parent>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>plugin</artifactId>
<version>3.2</version>
<relativePath/>
</parent>
And I have a dependency on the test harness:
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>dashboard-view</artifactId>
<version>${dashboard-view.version}</version>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-test-harness</artifactId>
<scope>test</scope>
<version>2.34</version>
</dependency>
</dependencies>
(That's the entire dependencies section, no omissions.)
And in my build section, I only declare the compiler, surefire, and hpi plugins:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
</plugin>
<plugin>
<groupId>org.jenkins-ci.tools</groupId>
<artifactId>maven-hpi-plugin</artifactId>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>hpi</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
</plugins>
</build>
(The surefire config is inherited from the plugin-3.2 parent.)
Here's the bit of the UtilHudsonTest that causes the error -- line 19 is the #Rule annotation:
public class UtilsHudsonTest {
#Rule // This is line 19
public JenkinsRule j = new JenkinsRule();
#Test
public void testGetLastDate() throws Exception {
FreeStyleProject prj = j.createFreeStyleProject("prj1");
prj.scheduleBuild2(0).get();
FreeStyleProject prj2 = j.createFreeStyleProject("prj2");
prj2.scheduleBuild2(0).get();
List<Job> jobs = new ArrayList<>();
jobs.add(prj);
jobs.add(prj2);
LocalDate lastDate = Utils.getLastDate(jobs);
assertNotNull(lastDate);
}
// other tests
}
I'm kind of stumped why this would work in IntelliJ and not in Maven. A mvn dependency:tree shows that the correct and expected dependencies. Any ideas in how to get this plugin to successfully run its test from commandline?

Running Specific TestNG Suites with Maven via command line

I am trying to run specific TestNG suites in Maven using the command line.
I have two different suites
smoke.xml
regression.xml
My pom.xml file looks like this
<groupId>com.FNB</groupId>
<artifactId>FNB_Testing</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>FNB_Testing</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>3.4.0</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.11</version>
<scope>test</scope>
</dependency>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20</version>
<configuration>
<suiteXmlFiles>
<suiteXmlFile>/FNB_Testing/regression.xml</suiteXmlFile>
<suiteXmlFile>/FNB_Testing/smoke.xml</suiteXmlFile>
</suiteXmlFiles>
</configuration>
</plugin>
</plugins>
</build>
I am using the command mvn test -DsuiteXmlFile=*suite name*
However it will only ever run the regression suite even if somke.xml is used
You can parameterize multiple suite files like below
<suiteXmlFiles>
<!-- Pass testng.xml files as argument from command line -->
<suiteXmlFile>${suiteXmlFile}</suiteXmlFile>
</suiteXmlFiles>
Then execute the following command to parametrize multiple testng.xml files using Maven:
mvn clean test -Dsurefire.suiteXmlFiles=regression.xml,smoke.xml

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