NoSuchFieldError: RESOURCE_PREFIX with a maven project using tess4j - maven

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.

Related

Maven with OpenJDK 11.0.2 and BouncyCastleProvider

Maven builds properly
# mvn archetype:generate -DgroupId=com.help.idea -DartifactId=client -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.4 -DinteractiveMode=false
# mvn install:install-file -Dfile=rs2xml.jar -DgroupId=net.proteanit.sql -DartifactId=rs2xml -Dversion=1.0 -Dpackaging=jar
# mvn package
But while running the jar it gives following error
java -jar target/client-1.0-SNAPSHOT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/bouncycastle/jce/provider/BouncyCastleProvider
at com.help.idea.authen.ClientMain.main(ClientMain.java:76)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.jce.provider.BouncyCastleProvider
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
I have following 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.help.idea</groupId>
<artifactId>client</artifactId>
<version>1.0-SNAPSHOT</version>
<name>client</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.jgoodies/jgoodies-common -->
<dependency>
<groupId>com.jgoodies</groupId>
<artifactId>jgoodies-common</artifactId>
<version>1.8.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.jgoodies/forms -->
<dependency>
<groupId>com.jgoodies</groupId>
<artifactId>forms</artifactId>
<version>1.2.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.bouncycastle/bcprov-jdk15on -->
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk15on</artifactId>
<version>1.65</version>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-dbutils/commons-dbutils -->
<dependency>
<groupId>commons-dbutils</groupId>
<artifactId>commons-dbutils</artifactId>
<version>1.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/xml-apis/xml-apis -->
<dependency>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.help.idea.authen.ClientMain</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Tried many suggestion from google but could not get it right. Thanks in advance.
welcome to StackOverflow. 👋 The error message tells you that your class ClientMain can't access the class BouncyCastleProvider. A likely cause for this is that the Java Virtual Machine (JVM) that you launched doesn't see the JAR that contains that class. Such JARs would have to be mentioned with the --class-path option.
Looking at your launch command, you can see that there's no class path being specified. One way to fix this, is to enumerate all your direct and transitive dependencies with the --class-path option (although that's a lot of work).
On the other hand, it is possible that this project created a so-called fat JAR, which contains all dependencies. That one, you could launch with just such a short command. Have a look into the target folder and see whether there's another JAR that you can use to launch. Probably something with -jar-with-dependencies in its name (don't launch anything with sources or javadoc in their name, that's pointless).
If this doesn't fix your problem, please follow Darren's comment and show us the full pom, so we can see the entire context.
I appreciate all the responses. I need to learn a lot. you may please refine my answer.
I now created a directory "src/main/resources" and put org/bouncycastle/ in there. Now things are working as expected. But things should have worked directly with maven build.

Test class cannot resolve main class when trying to Unit Test groovy using maven on Jenkins

I am having trouble getting my Unit Tests to work in Maven for a Jenkins shared library written in Groovy.
I am new to Maven and relatively new to Jenkins. The situation is the following:
We have a TFVC server hosting our shared library. The shared library is stored this way:
TFVC
- sharedLibrary
- src
- br
- common
- v1
- SomeClass1.groovy
- SomeClass2.groovy
- SomeClass3.groovy
- test
- groovy
- SomeClass1Tests.groovy
- SomeClass2Tests.groovy
- Jenkinsfile
- pom.xml
The structure src-br-common-v1 cannot be changed. I added the test-groovy structure according to information I found online.
The Jenkinsfile contains the Job to test the library in Maven. It's calling
mvn clean gplus:testCompile
My POM looks like this:
<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>my.company</groupId>
<artifactId>sharedLib</artifactId>
<version>1.0</version>
<name>Jenkins Shared Pipeline Library</name>
<repositories>
<repository>
<id>jenkins</id>
<url>http://repo.jenkins-ci.org/releases/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>maven-plugin</artifactId>
<version>3.5</version>
</dependency>
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.main</groupId>
<artifactId>jenkins-core</artifactId>
<version>2.85</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.codehaus.groovy</groupId>
<artifactId>groovy-all</artifactId>
<version>2.4.12</version>
</dependency>
<dependency>
<groupId>com.cloudbees</groupId>
<artifactId>groovy-cps</artifactId>
<version>1.11</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>script-security</artifactId>
<version>1.24</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.jenkins-ci.plugins</groupId>
<artifactId>pipeline-utility-steps</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>org.apache.maven.doxia</groupId>
<artifactId>doxia-site-renderer</artifactId>
<version>1.9.2</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src/br/common/v1</sourceDirectory>
<testSourceDirectory>src/test/groovy</testSourceDirectory>
<resources>
<resource>
<directory>E:\Jenkins\plugins\pipeline-utility-steps\WEB-INF\lib</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.gmavenplus</groupId>
<artifactId>gmavenplus-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<goals>
<goal>addSources</goal>
<goal>addTestSources</goal>
<goal>compile</goal>
<goal>testCompile</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>
<directory>${project.basedir}/src/br/common/v1</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</source>
</sources>
<testSources>
<testSource>
<directory>${project.basedir}/src/br/common/v1</directory>
<directory>${project.basedir}/src/test/groovy</directory>
<includes>
<include>**/*.groovy</include>
</includes>
</testSource>
</testSources>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.12.4</version>
<configuration>
<trimStackTrace>false</trimStackTrace>
<argLine>${surefireArgLine}</argLine>
<includes>
<include>**/*Test*.*</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Here is a simplified version of a Test class, lets just assume SomeClass1 contains a method returnTrue that does exactly what you think:
package test.groovy;
import br.common.v1.SomeClass1;
public class SomeClass1Tests extends GroovyTestCase
{
public void testReturnTrue() {
def someClass1Object = new SomeClass1();
def expected = true;
def result = someClass1Object.returnTrue();
assertEquals(expected, result);
}
}
I now have the problem that my Test class cannot resolve the class I want to test.
Unable to resolve class br.common.v1.SomeClass1 # line 2, column 1
Originaly I had my test files in another location in TFVC, but that did not work and I read that gmaven-plus is very picky about where to store your test classes.
I hope I provided all information needed in a practical way, please let me know if I missed anything.
Thank you for your help in advance!
The source directories configured for maven are to specific (they point to where the files are). If you want to import br.common.v1 make sure, that the directory hierarchy br/common/v1 is inside the source roots.

Browserstack automate-maven-plugin not working

I'm trying to run my appium test on the BrowserStack device cloud with the use of Jenkins.
After adding the dependencies to my pom.xml mentioned in the following section
https://www.browserstack.com/app-automate/appium/jenkins#reporting
I received the following error:
[ERROR] Failed to execute goal com.browserstack:automate-maven-plugin:1.0.0-SNAPSHOT:test-compile (default) on project 1.0: Execution default of goal com.browserstack:automate-maven-plugin:1.0.0-SNAPSHOT:test-compile failed: Plugin com.browserstack:automate-maven-plugin:1.0.0-SNAPSHOT or one of its dependencies could not be resolved: The following artifacts could not be resolved: org.codehaus.mojo:aspectj-maven-plugin:jar:${aspectj.maven.version}, org.aspectj:aspectjtools:jar:${aspectj.tools.version}: Could not find artifact org.codehaus.mojo:aspectj-maven-plugin:jar:${aspectj.maven.version} in central (https://repo.maven.apache.org/maven2) -> [Help 1]
My pom.xml file:
<?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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>xxxx</groupId>
<artifactId>1.0</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<jdk.source.version>1.8</jdk.source.version>
<jdk.target.version>1.8</jdk.target.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<source>${jdk.source.version}</source>
<target>${jdk.target.version}</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<!-- JUnit 5 requires Surefire version 2.22.0 or higher -->
<version>2.22.0</version>
</plugin>
<plugin>
<groupId>com.browserstack</groupId>
<artifactId>automate-maven-plugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<configuration>
<source>${jdk.source.version}</source>
<target>${jdk.target.version}</target>
<complianceLevel>${jdk.source.version}</complianceLevel>
</configuration>
<executions>
<execution>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- https://mvnrepository.com/artifact/io.appium/java-client -->
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>7.2.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-api -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.junit.jupiter/junit-jupiter-engine -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.5.2</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/com.browserstack/automate-testassist -->
<dependency>
<groupId>com.browserstack</groupId>
<artifactId>automate-testassist</artifactId>
<version>1.0.0-SNAPSHOT</version>
</dependency>
</dependencies>
Can anyone help me with this problem?
<source>${jdk.source.version}</source>
<target>${jdk.target.version}</target>
<complianceLevel>${jdk.source.version}</complianceLevel>
you need to mention the jdk source and the targer versions here.
That's because BrowserStack repository no longer have a snapshot feature so you need to include the plugin as follows. You can check this answer for more on snapshot
<groupId>com.browserstack</groupId>
<artifactId>automate-maven-plugin</artifactId>
<version>1.0.0</version>
Without the SNAPSHOT

Manually creating a deployable JAR for Liferay

I created a liferay workspace in gradle format and it basically only contains a theme and a TemplateContextContributor-module.
Now I want to build a maven "wrapper" around both artifacts to make them compatible with some other maven-processes/-plugins while keeping the original gradle structure. I dont want to use the liferay-maven-plugin or maven-tools to build those artifacts, because it seems to behave differently from the gradle/gulp toolset when it comes to compiling scss for example.
So I created some POMs from scratch for
Theme
TemplateContextContributor-Module
First off I will take about the mechanism for the theme, which is already working:
That wrapper uses the maven-war-plugin to bundle the contents of the build/-folder, where the previously built gradle artifact resides, into a WAR-file that can be deployed by Liferay without problems.
theme pom.xml:
<properties>
<src.dir>src</src.dir>
<com.liferay.portal.tools.theme.builder.outputDir>build</com.liferay.portal.tools.theme.builder.outputDir>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
[...]
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<webResources>
<resource>
<directory>${com.liferay.portal.tools.theme.builder.outputDir}</directory>
<excludes>
<exclude>**/*.sass-cache/</exclude>
</excludes>
</resource>
</webResources>
</configuration>
</plugin>
However, I am having difficulties creating a OSGI-Compatible JAR-File for the module contents. It seems that only the META-INF/MANIFEST.MF does not contain the right information and I seemingly cannot generate it in a way that Liferay (or OSGI) understands.
this is the module pom.xml dependencies and plugins that I tried:
<dependency>
<groupId>org.apache.felix</groupId>
<artifactId>org.apache.felix.scr.ds-annotations</artifactId>
<version>1.2.10</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.gradle.plugins</artifactId>
<version>3.9.9</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
[...]
<plugin>
<groupId>biz.aQute.bnd</groupId>
<artifactId>bnd-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<goals>
<goal>bnd-process</goal>
</goals>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>biz.aQute.bnd</groupId>
<artifactId>biz.aQute.bndlib</artifactId>
<version>3.2.0</version>
</dependency>
<dependency>
<groupId>com.liferay</groupId>
<artifactId>com.liferay.ant.bnd</artifactId>
<version>2.0.48</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-scr-plugin</artifactId>
<version>1.25.0</version>
<executions>
<execution>
<id>generate-scr-scrdescriptor</id>
<goals>
<goal>scr</goal>
</goals>
</execution>
</executions>
</plugin>
I was able to create a JAR using the above but its' META-INF/MANIFEST.MF is not identical to the one produced by the gradle build:
I guess that's why Liferay does not deploy it. The log says "processing module xxx ....", but that never ends and the module does not work in Liferay.
These are the plugins I have tried in different combinations so far:
maven-build-plugin
maven-scr-plugin
maven-jar-plugin
maven-war-plugin
maven-compiler-plugin
Any help in creating a liferay-deployable module JAR would be great.
I'm not sure why you're manually building a maven wrapper for the Template Context Contributor. The Liferay (blade) samples are available for Liferay-workspace, pure Gradle as well as for Maven. I'd just go with the standard and not worry about re-inventing the wheel.
To make this answer self-contained: The current pom.xml listed in the Template Context Contributor plugin is:
<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>
<artifactId>template-context-contributor</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<parent>
<groupId>blade</groupId>
<artifactId>parent.bnd.bundle.plugin</artifactId>
<version>1.0.0</version>
<relativePath>../../parent.bnd.bundle.plugin</relativePath>
</parent>
<dependencies>
<dependency>
<groupId>com.liferay.portal</groupId>
<artifactId>com.liferay.portal.kernel</artifactId>
<version>2.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.portlet</groupId>
<artifactId>portlet-api</artifactId>
<version>2.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.osgi</groupId>
<artifactId>org.osgi.service.component.annotations</artifactId>
<version>1.3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<finalName>com.liferay.blade.template.context.contributor-${project.version}</finalName>
</build>
</project>

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 :)

Resources