Maven obfuscation with ProGuard - java

I have recently created a JAR file that needs obfuscation, but I cannot seem to get it working what so ever. Either it throws a bunch of warnings about not found references, duplications or it just doesn't obfuscate anything at all. I'm using the Maven Proguard plugin.
Maven build log: https://hastebin.com/oneyozizoh.hs
It says build succeed but it is not what I'm looking for: it does not include the external dependencies (influxDB) and it's not even obfuscated.
Here's the deal:
It uses external libraries such as InfluxDB. This needs to be included in JAR upon exporting. The plugin will not work without it. These external libs should not be obfuscated (unless there's a way to obfuscate every single required dependency as well and still have it work).
It also uses some other JAR files as optional dependencies (scope system or provided). These are NOT included in the export JAR. These libraries should not be obfuscated what so ever as they are resolved at runtime (if present).
It would most likely be the easiest if only my project package gets obfuscated, which is com.dyescape.*. I have tried this but I cannot seem to get it working.
Here is the pom.xml file I have so far.
<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.dyescape</groupId>
<artifactId>ServerStatistics</artifactId>
<version>1.0.0</version>
<name>ServerStatistics</name>
<description>A plugin that gathers server statistics and pushes them to an external panel.</description>
<url>https://www.dyescape.com</url>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<repositories>
<repository>
<id>spigot-repo</id>
<url>https://hub.spigotmc.org/nexus/content/repositories/snapshots/</url>
</repository>
<repository>
<id>vault-repo</id>
<url>http://nexus.hc.to/content/repositories/pub_releases</url>
</repository>
<repository>
<id>viaversion-repo</id>
<url>https://repo.viaversion.com</url>
</repository>
<repository>
<id>votifier-repo</id>
<url>http://repo.howaner.de/com/vexsoftware/votifier/1.9/</url>
</repository>
<repository>
<id>minebuilders-repo</id>
<url>http://minebuilders.me:8080/plugin/repository/everything/</url>
</repository>
</repositories>
<dependencies>
<!--Spigot API-->
<dependency>
<groupId>org.spigotmc</groupId>
<artifactId>spigot-api</artifactId>
<version>1.12-R0.1-SNAPSHOT</version>
<scope>provided</scope>
<exclusions>
<exclusion> <!-- declare the exclusion here -->
<groupId>sample.ProjectB</groupId>
<artifactId>Project-B</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.influxdb</groupId>
<artifactId>influxdb-java</artifactId>
<version>2.7</version>
</dependency>
<dependency>
<groupId>net.milkbowl.vault</groupId>
<artifactId>VaultAPI</artifactId>
<version>1.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.MassiveCraft</groupId>
<artifactId>MassiveCore</artifactId>
<version>2.13.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/MassiveCore.jar</systemPath>
</dependency>
<dependency>
<groupId>com.MassiveCraft</groupId>
<artifactId>Factions</artifactId>
<version>2.13.2</version>
<scope>system</scope>
<systemPath>${project.basedir}/Factions.jar</systemPath>
</dependency>
<dependency>
<groupId>me.leoko.advancedban</groupId>
<artifactId>AdvancedBan</artifactId>
<version>2.1.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/AdvancedBan.jar</systemPath>
</dependency>
<dependency>
<groupId>fr.neatmonster.nocheatplus</groupId>
<artifactId>NoCheatPlus</artifactId>
<version>3.15.1-RC-sMD5NET-b1084</version>
<scope>system</scope>
<systemPath>${project.basedir}/NoCheatPlus.jar</systemPath>
</dependency>
<dependency>
<groupId>us.myles</groupId>
<artifactId>viaversion</artifactId>
<scope>provided</scope>
<version>1.2.0-17w31a-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.vexsoftware</groupId>
<artifactId>votifier</artifactId>
<version>1.9</version>
<scope>system</scope>
<systemPath>${project.basedir}/Votifier.jar</systemPath>
</dependency>
<dependency>
<groupId>com.gmail.nossr50</groupId>
<artifactId>mcMMO</artifactId>
<version>1.5.08-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/mcMMO.jar</systemPath>
</dependency>
<dependency>
<groupId>me.konsolas</groupId>
<artifactId>aac</artifactId>
<version>3.3.0-b1</version>
<scope>system</scope>
<systemPath>${project.basedir}/AAC.jar</systemPath>
</dependency>
<dependency>
<groupId>PAC</groupId>
<artifactId>PAC</artifactId>
<version>1.2.1</version>
<scope>system</scope>
<systemPath>${project.basedir}/PAC.jar</systemPath>
</dependency>
<dependency>
<groupId>de.Keyle</groupId>
<artifactId>MyPet</artifactId>
<version>2.3.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/MyPet.jar</systemPath>
</dependency>
<dependency>
<groupId>me.minebuilders</groupId>
<artifactId>clearlag-core</artifactId>
<version>2.9.0-SNAPSHOT</version>
<scope>provided</scope>
</dependency>
</dependencies>
<!-- Build -->
<build>
<!-- Resources -->
<sourceDirectory>src/main/java</sourceDirectory>
<defaultGoal>clean install</defaultGoal>
<resources>
<resource>
<directory>src/main/resources</directory>
<!-- Keeping filtering at true here reduces plugin.yml redundancy! -->
<filtering>true</filtering>
<includes>
<include>plugin.yml</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<!-- Keep filtering at false for other resources to prevent bad magic -->
<filtering>false</filtering>
<excludes>
<exclude>**/*.java</exclude>
<exclude>plugin.yml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>com.github.wvengen</groupId>
<artifactId>proguard-maven-plugin</artifactId>
<version>2.0.14</version>
<dependencies>
<dependency>
<groupId>net.sf.proguard</groupId>
<artifactId>proguard-base</artifactId>
<version>5.3.3</version>
</dependency>
</dependencies>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>proguard</goal>
</goals>
</execution>
</executions>
<configuration>
<proguardVersion>5.3.3</proguardVersion>
<options>
<option>-dontshrink</option>
<option>-dontoptimize</option>
<option>-keep class !com.dyescape.**,com.dyescape.serverstatistics.ServerStatistics { *; }</option>
<option>-keepattributes Exceptions,InnerClasses,Signature,Deprecated,SourceFile,LineNumberTable,LocalVariable*Table,*Annotation*,Synthetic,EnclosingMethod,*Annotations*</option>
</options>
<libs>
<lib>${java.home}/lib/rt.jar</lib>
<lib>${java.home}/lib/jce.jar</lib>
</libs>
</configuration>
</plugin>
</plugins>
</build>
</project>
The command I used to use to build the JAR (including required dependencies) is the following:
clean package assembly:single

Related

Error: Could not find or load main class ... Caused by: java.lang.NoClassDefFoundError: javafx/application/Application

Can't open an executable jar from Maven project in IntelliJ
Hello everyone
So I am currently working on a Maven project using JavaFX interface on the IDE IntelliJ. Everything works fine except when I try to export the project in an executable jar file.
Everytime I try the "java -jar myproject-1.0-SNAPSHOT.jar" command in the terminal it shows this error
Error: Could not find or load main class mypackage.myproject.Main Caused by: java.lang.NoClassDefFoundError: javafx/application/Application
I also tried to generate a .jar with artifact in project structure but when I try to open it, I get another error which is :
Error: A JNI error has occurred, please check your installation and try again
Exception in thread "main" java.lang.SecurityException: Invalid signature file digest for Manifest main attributes
at java.base/sun.security.util.SignatureFileVerifier.processImpl(SignatureFileVerifier.java:340)
at java.base/sun.security.util.SignatureFileVerifier.process(SignatureFileVerifier.java:282)
at java.base/java.util.jar.JarVerifier.processEntry(JarVerifier.java:327)
at java.base/java.util.jar.JarVerifier.update(JarVerifier.java:239)
at java.base/java.util.jar.JarFile.initializeVerifier(JarFile.java:760)
at java.base/java.util.jar.JarFile.ensureInitialization(JarFile.java:1058)
at java.base/java.util.jar.JavaUtilJarAccessImpl.ensureInitialization(JavaUtilJarAccessImpl.java:72)
at java.base/jdk.internal.loader.URLClassPath$JarLoader$2.getManifest(URLClassPath.java:883)
at java.base/jdk.internal.loader.BuiltinClassLoader.defineClass(BuiltinClassLoader.java:848)
at java.base/jdk.internal.loader.BuiltinClassLoader.findClassOnClassPathOrNull(BuiltinClassLoader.java:760)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClassOrNull(BuiltinClassLoader.java:681)
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:639)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:188)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:495)
at java.base/java.lang.Class.forName(Class.java:474)
at java.base/sun.launcher.LauncherHelper.loadMainClass(LauncherHelper.java:790)
at java.base/sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:685)
My JDK is version 19.
In the MANIFEST FILE, the Main-Class is specified.
Here is 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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mypackage</groupId>
<artifactId>PearCar</artifactId>
<version>1.0-SNAPSHOT</version>
<name>PearCar</name>
<repositories>
<repository>
<id>AsposeJavaAPI</id>
<name>Aspose Java API</name>
<url>https://repository.aspose.com/repo/</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>5.9.0</junit.version>
</properties>
<dependencies>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>19-ea+7</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>19-ea+7</version>
</dependency>
<dependency>
<groupId>org.kordamp.bootstrapfx</groupId>
<artifactId>bootstrapfx-core</artifactId>
<version>0.4.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox</artifactId>
<version>2.0.27</version>
</dependency>
<dependency>
<groupId>org.apache.pdfbox</groupId>
<artifactId>pdfbox-tools</artifactId>
<version>2.0.27</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.30</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>kernel</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>io</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>layout</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>forms</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdfa</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>com.itextpdf</groupId>
<artifactId>pdftest</artifactId>
<version>7.0.4</version>
</dependency>
<dependency>
<groupId>net.sf.cssbox</groupId>
<artifactId>pdf2dom</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>com.aspose</groupId>
<artifactId>aspose-pdf</artifactId>
<version>21.5</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220924</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>mypackage.myproject.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.10.1</version>
<configuration>
<source>19</source>
<target>19</target>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<executions>
<execution>
<!-- Default configuration for running with: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>mypackage.myproject/mypackage.myproject.Main</mainClass>
<launcher>app</launcher>
<jlinkZipName>app</jlinkZipName>
<jlinkImageName>app</jlinkImageName>
<noManPages>true</noManPages>
<stripDebug>true</stripDebug>
<noHeaderFiles>true</noHeaderFiles>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
here is my module-info.java file :
module mypackage.myproject {
requires javafx.controls;
requires javafx.fxml;
requires org.kordamp.bootstrapfx.core;
requires java.sql;
requires org.apache.pdfbox;
requires java.desktop;
requires layout;
requires kernel;
requires io;
//requires aspose.pdf;
requires net.sf.cssbox.pdf2dom;
requires aspose.pdf;
requires forms;
requires commons.lang3;
opens mypackage.myproject to javafx.fxml;
exports mypackage.myproject;
exports Controller;
opens Controller to javafx.fxml;
}
Thank you !
I found the solution !
So if you are using IntelliJ with a Maven Project, you have to add :
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.4.2</version>
<configuration>
<archive>
<manifest>
<mainClass>mypackage.myproject.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
and run the exe jar in the terminal with the cmd :
java --module-path "mypath\openjfx-19_windows-x64_bin-sdk\javafx-sdk-19\lib" --add-modules javafx.controls,javafx.fxml -jar myproject-SNAPSHOT-jar-with-dependencies.jar
It worked for me !
Hope it helps :)

Java Implementation of JAXB-API has not been found on module path or classpath

I have an application that should work, but here I have a JAXB error. I don't know which version of Java it is, I think it's 8.
I run in Java 8. In Java 8+ iIhave to add javax.xml.bind and com.sun.xml.bind to pom. I also ran it with Java 11 and 16 and jakarta in the pom.
I have read that applications which are supposed to run on Java 8 but were running it on Java 11, generate this error, and that has jous in the pom of jakarta and javax.
And another question how to detect the Java to use? And that the solution applies according to the version of java
I have this error.
Exception in thread "main" javax.xml.bind.JAXBException: Implementation of JAXB-API has not been found on module path or classpath.
- with linked exception:
[java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory]
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:131)
at javax.xml.bind.ContextFinder.find(ContextFinder.java:318)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:478)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:435)
at javax.xml.bind.JAXBContext.newInstance(JAXBContext.java:336)
at mypackage (ConsoleApp.java:136)
Caused by: java.lang.ClassNotFoundException: com.sun.xml.bind.v2.ContextFactory
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:581)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
at javax.xml.bind.ServiceLoaderUtil.nullSafeLoadClass(ServiceLoaderUtil.java:92)
at javax.xml.bind.ServiceLoaderUtil.safeLoadClass(ServiceLoaderUtil.java:125)
at javax.xml.bind.ContextFinder.newInstance(ContextFinder.java:128)
... 5 more
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>
<parent>
<groupId>myapp-parent</groupId>
<artifactId>myapp-parent</artifactId>
<version>0.1.3-SNAPSHOT</version>
</parent>
<artifactId>myapp-lst</artifactId>
<version>0.2.2-SNAPSHOT</version>
<packaging>jar</packaging>
<name>example</name>
<description></description>
<properties>
<plugin.download.version>1.4.1</plugin.download.version>
<santuario.version>2.1.2</santuario.version>
</properties>
<build>
<finalName>${project.artifactId}-${project.version}</finalName>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>buildnumber-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.myapp-parent.myapp.mylist.app.ConsoleApp</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
<plugin>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>${plugin.download.version}</version>
<executions>
<execution>
<id>CRL-IGC-ELEM-ORG</id>
<phase>process-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>**url**</url>
<outputFileName>ACI-EL-ORG.crl</outputFileName>
<outputDirectory>${project.basedir}/crls</outputDirectory>
<skipCache>true</skipCache>
</configuration>
</execution>
<execution>
<id>CRL-IGC-ELEM</id>
<phase>process-resources</phase>
<goals>
<goal>wget</goal>
</goals>
<configuration>
<url>**url**</url>
<outputFileName>ACR-EL.crl</outputFileName>
<outputDirectory>${project.basedir}/crls</outputDirectory>
<skipCache>true</skipCache>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xml-maven-plugin</artifactId>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven.dependency.version}</version>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>com.googlecode.maven-download-plugin</groupId>
<artifactId>download-maven-plugin</artifactId>
<version>${plugin.download.version}</version>
<type>maven-plugin</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.ldaptive</groupId>
<artifactId>ldaptive</artifactId>
</dependency>
<dependency>
<groupId>org.ldaptive</groupId>
<artifactId>ldaptive-unboundid</artifactId>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-jcl</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.apache.santuario</groupId>
<artifactId>xmlsec</artifactId>
<version>${santuario.version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>chl-public-released</id>
<name>releases</name>
<url>**url**</url>
<snapshots>
<enabled>false</enabled>
</snapshots>
</repository>
<repository>
<id>chl-public-snapshots</id>
<name>snapshots</name>
<url>**url**</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
</project>
it missed that in the pom
<dependency>
<groupId>jakarta.annotation</groupId>
<artifactId>jakarta.annotation-api</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.3</version>
</dependency>
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.5</version>
</dependency>

Support/Alternative of Nashorn with Spring Native

In my company we use Nashorn in Java 11 and spring-boot which is working fine, but we recently decided to use spring-native with docker. We ended up to make the image build, but at startup, the project crash because the Nashorn is not supported (And will probably be never supported by graalVM).
Here is the error I get when tring to run the native image
We can't migrate easily from Nashorn to GraalVM.js and the deadline are short, so it's not a solution for us.
I'm asking here if you already had the issue, and how you overcame it.
I already tried to change the ScriptEngine from 'nashorn' to 'js' (which is available in my project), but it also failed at run time. We basically need for an engine which don't use 'invokedynamic' to compute js code.
An other solution would be : Export the Nashorn part as an external microservice.
But we prefere avoid using this solution, since the current implementation is working and it would add some security issue to considere to secure the communication. We will considere it only if we run out of solution ^^'
Here is the problematic code :
Engine.java
public class Engine {
public Engine() {
ScriptEngineManager manager = new ScriptEngineManager();
engine = manager.getEngineByName("nashorn");
}
}
pom.xml
<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/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.test</groupId>
<artifactId>testtest</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>...</name>
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<java.version>11</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-mongodb</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-websocket</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-json</artifactId>
</exclusion>
<exclusion>
<artifactId>jackson-databind</artifactId>
<groupId>com.fasterxml.jackson.core</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
</dependency>
<dependency>
<groupId>io.jsonwebtoken</groupId>
<artifactId>jjwt</artifactId>
<version>0.9.1</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.1</version>
</dependency>
<dependency>
<groupId>com.opencsv</groupId>
<artifactId>opencsv</artifactId>
<version>4.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.google.code.gson/gson -->
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.6</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.mongodb/mongo-java-driver -->
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>3.12.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.java.dev.jna/jna -->
<dependency>
<groupId>net.java.dev.jna</groupId>
<artifactId>jna</artifactId>
<version>5.6.0</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.0-jre</version>
</dependency>
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-java</artifactId>
<version>3.11.11</version>
</dependency>
<dependency>
<groupId>com.konghq</groupId>
<artifactId>unirest-object-mappers-gson</artifactId>
<version>3.11.11</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-native</artifactId>
<version>0.10.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<!-- Disable maven resources filtering for bin library files and p12 certificates -->
<nonFilteredFileExtensions>
<nonFilteredFileExtension>p12</nonFilteredFileExtension>
<nonFilteredFileExtension>dylib</nonFilteredFileExtension>
<nonFilteredFileExtension>dll</nonFilteredFileExtension>
</nonFilteredFileExtensions>
</configuration>
</plugin>
<plugin>
<!-- Build an executable JAR-->
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.test.testtest.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.test.testtest.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M1</version>
<configuration>
<argLine>-Dnashorn.args=--language=es6</argLine>
</configuration>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.3.2</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<builder>paketobuildpacks/builder:tiny</builder>
<env>
<BP_NATIVE_IMAGE>true</BP_NATIVE_IMAGE>
</env>
</image>
<excludes>
<exclude>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</exclude>
</excludes>
<systemPropertyVariables>
<env>local</env>
</systemPropertyVariables>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.experimental</groupId>
<artifactId>spring-aot-maven-plugin</artifactId>
<version>0.10.1</version>
<executions>
<execution>
<id>test-generate</id>
<goals>
<goal>test-generate</goal>
</goals>
</execution>
<execution>
<id>generate</id>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>spring-release</id>
<name>Spring release</name>
<url>https://repo.spring.io/release</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-release</id>
<name>Spring release</name>
<url>https://repo.spring.io/release</url>
</pluginRepository>
</pluginRepositories>
</project>
Part 1.
Migration from Nashorn to GraalVM.js is standard topic and covered in documentation
https://www.graalvm.org/reference-manual/js/NashornMigrationGuide/
And most likely there will not be alternative (at least developed by Oracle)
Part 2. Spring Native (still experimental) is ongoing effort to build Spring application using native-image compiler from GraalVM to produce native-image. This project focuses on Spring project and js support will be out of scope, you would need again follow Oracle work.
During this native-image build, the engine like GraalVM.js (that is graalVM component) must be included into resulted app, and it may be non trivial.
And life advice: if you really under deadline, consider going with older technologies if you want to guarantee delivery. And use JDK before JDK15 where Nashorn is still present.

Version combination (Maven / Log4J in Java 9 Jigsaw project)

I am trying to get a very simple JavaFX application to run with maven and Java 10 in IntelliJ.
The project:
https://github.com/ClanWolf/C3-Client_Phoenix
The structure:
The module-info.java:
module net.clanwolf.c3.client {
requires javafx.graphics;
requires javafx.fxml;
requires javafx.controls;
requires javafx.base;
requires org.apache.logging.log4j;
exports net.clanwolf.c3.client;
}
The pom.xml:
<?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>net.clanwolf.c3</groupId>
<artifactId>C3-Client_Phoenix</artifactId>
<version>4.6.2</version>
<packaging>jar</packaging>
<name>C3-Client Phoenix</name>
<url>http://c3.clanwolf.net</url>
<organization>
<name>ClanWolf W-7</name>
<url>http://www.clanwolf.net</url>
</organization>
<description>Starsystem map of the Inner Sphere, Periphery and Clan space (BattleTech).</description>
<prerequisites>
<maven>3.5.3</maven>
<!--<maven>3.3.9</maven>-->
</prerequisites>
<!-- Repositories ############################################################################################## -->
<repositories>
<repository>
<id>mvnrepository</id>
<name>mvnrepository</name>
<url>http://www.mvnrepository.com</url>
</repository>
<repository>
<id>mvncentral</id>
<name>mvncentral</name>
<url>http://central.maven.org/maven2/</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>oss-sonatype-snapshots</id>
<url>https://oss.sonatype.org/content/groups/public/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</pluginRepository>
</pluginRepositories>
<!-- Properties ################################################################################################ -->
<properties>
<!-- __________________________________________________________ Versions -->
<java.version>10</java.version>
<maven.compiler.plugin.version>3.7.0</maven.compiler.plugin.version>
<maven.surefire.plugin.version>2.22.0</maven.surefire.plugin.version>
<junit.version>4.12</junit.version>
<junit.jupiter.version>5.2.0</junit.jupiter.version>
<junit.platform.surefire.provider.version>1.2.0</junit.platform.surefire.provider.version>
<asm.version>6.2</asm.version>
<!-- __________________________________________________________ Encoding -->
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<mainClass>net.clanwolf.c3.client.MainFrame</mainClass>
<maven.compiler.source>${java.version}</maven.compiler.source>
<maven.compiler.target>${java.version}</maven.compiler.target>
</properties>
<!-- Dependencies ############################################################################################## -->
<dependencies>
<!-- _____________________________________________________________ Maven -->
<dependency>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
</dependency>
<!-- _____________________________________________________________ JUnit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apiguardian</groupId>
<artifactId>apiguardian-api</artifactId>
<version>1.0.0</version>
<scope>test</scope>
</dependency>
<!-- ___________________________________________________________ Logging -->
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-api</artifactId>
<version>2.11.0</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-core</artifactId>
<version>2.11.0</version>
</dependency>
<!-- _______________________________________________ Tektosyne / Voronoi -->
<dependency>
<groupId>org.kynosarges</groupId>
<artifactId>tektosyne</artifactId>
<version>6.2.0</version>
</dependency>
<!-- ______________________________________________________ C3-Preloader -->
<dependency>
<groupId>net.clanwolf</groupId>
<artifactId>C3-Preloader</artifactId>
<version>1.0.0</version>
</dependency>
<!-- ____________________________________________________________ Nadron -->
<!--<dependency>-->
<!--<groupId>com.github.menacher</groupId>-->
<!--<artifactId>nadron</artifactId>-->
<!--<version>0.8-SNAPSHOT</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.github.menacher</groupId>-->
<!--<artifactId>nadclient</artifactId>-->
<!--<version>0.8-SNAPSHOT</version>-->
<!--</dependency>-->
<!-- _________________________________________________________ Hibernate -->
<!--<dependency>-->
<!--<groupId>org.hibernate.javax.persistence</groupId>-->
<!--<artifactId>hibernate-jpa-2.1-api</artifactId>-->
<!--<version>1.0.0.Final</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>org.hibernate</groupId>-->
<!--<artifactId>hibernate-core</artifactId>-->
<!--<version>5.0.3.Final</version>-->
<!--</dependency>-->
<!-- ___________________________________________________________________________ C H E C K I F N E E D E D -->
<!--<dependency>-->
<!--<groupId>net.sourceforge.collections</groupId>-->
<!--<artifactId>collections-generic</artifactId>-->
<!--<version>4.01</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>com.google.code.gson</groupId>-->
<!--<artifactId>gson</artifactId>-->
<!--<version>2.4</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>commons-codec</groupId>-->
<!--<artifactId>commons-codec</artifactId>-->
<!--<version>1.10</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>dom4j</groupId>-->
<!--<artifactId>dom4j</artifactId>-->
<!--<version>1.6.1</version>-->
<!--</dependency>-->
<!--<dependency>-->
<!--<groupId>commons-net</groupId>-->
<!--<artifactId>commons-net</artifactId>-->
<!--<version>3.3</version>-->
<!--</dependency>-->
</dependencies>
<!-- Build ##################################################################################################### -->
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
<includes>
<include>**/version.number</include>
</includes>
</resource>
<resource>
<directory>src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>**/version.number</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.plugin.version}</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
<dependencies>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>${asm.version}</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.surefire.provider.version}</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>org.ow2.asm</groupId>
<artifactId>asm</artifactId>
<version>${asm.version}</version>
</dependency>
</dependencies>
<configuration>
<parallel>methods</parallel>
<threadCount>10</threadCount>
<includes>
<include>**/Test*.java</include>
<include>**/*Test.java</include>
<include>**/*Tests.java</include>
<include>**/*TestCase.java</include>
</includes>
</configuration>
</plugin>
<plugin>
<groupId>com.zenjava</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>8.9.0-SNAPSHOT</version>
<configuration>
<mainClass>net.clanwolf.c3.client.MainFrame</mainClass>
<preLoader>c3_preloader.C3_Preloader</preLoader>
<verbose>true</verbose>
<bundleArguments>
<!-- MSI installer Options -->
<!-- https://docs.oracle.com/javase/9/tools/javapackager.htm#GUID-E51F9601-E121-4A50-BCA7-C7F8730078B2__WINDOWSEXEBUNDLERARGUMENTS-26C9A39C -->
<!-- Custonmize MSI installer -->
<!-- http://wixtoolset.org/documentation/manual/v3/wixui/wixui_customizations.html -->
<icon>target/classes/icon.ico</icon>
<installdirChooser>true</installdirChooser>
<module-path>target/classes</module-path>
<module>net.clanwolf.c3.client</module>
<!--<add-modules>module1,module2,module3</add-modules>-->
<!--<limit-modules>module1,module2,module3</limit-modules>-->
<!--<runtime /> Not working together with the above commands -->
</bundleArguments>
<!--<jfxMainAppJarName>${project.build.finalName}.jar</jfxMainAppJarName>-->
<identifier>${project.artifactId}</identifier>
<vendor>ClanWolf.net</vendor>
<!-- win.app | linux.app | mac.app | exe | msi | rpm | deb -->
<bundler>msi</bundler>
<nativeReleaseVersion>${project.version}</nativeReleaseVersion>
<needShortcut>true</needShortcut>
<needMenu>true</needMenu>
<appName>${project.artifactId}</appName>
<jvmArgs>
<jvmArg>-Xmx2g</jvmArg>
<jvmArg>-Djavafx.verbose=true</jvmArg>
<!--<jvmProperty>-DMyProperty=true</jvmProperty>-->
</jvmArgs>
<!--<jvmProperties>-->
<!--<UserProperty>foo</UserProperty>-->
<!--</jvmProperties>-->
<!--<userJvmArgs>-->
<!--<Argument3>AppCommand</Argument3>-->
<!--</userJvmArgs>-->
<!--<keyStoreAlias>example-user</keyStoreAlias>-->
<!--<keyStorePassword>example-password</keyStorePassword>-->
<allPermissions>false</allPermissions>
<manifestAttributes>
<Specification-Title>${project.name}</Specification-Title>
<Specification-Version>${project.version}</Specification-Version>
<Specification-Vendor>${project.organization.name}</Specification-Vendor>
<Implementation-Title>${project.name}</Implementation-Title>
<Implementation-Version>${project.version}</Implementation-Version>
<Implementation-Vendor-Id>${project.groupId}</Implementation-Vendor-Id>
<Implementation-Vendor>${project.organization.name}</Implementation-Vendor>
</manifestAttributes>
</configuration>
<executions>
<execution>
<id>create-jfxjar</id>
<phase>package</phase>
<goals>
<goal>build-jar</goal>
</goals>
</execution>
<execution>
<id>create-native</id>
<phase>package</phase>
<goals>
<goal>build-native</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
This does not run. The maven build completes without problems, but if I start it in IntelliJ, it gives me this:
Error occurred during initialization of boot layer
java.lang.module.ResolutionException: Modules maven.core and maven.artifact export package org.apache.maven.artifact.resolver.filter to module aether.impl
If I do remove the dependency for log4j-core, it will run, but it will complain at runtime that there is no implementation of log4j and that I should please add log4j-core. If I do that, the Resolution Bullshit is shown again. How can this be resolved, if possible at all?
Java 9 modularization came with a couple of new rules like: Split packages, i.e. classes with the same package but in different jars, are not allowed. This is only an issue when working on the modulepath, not with the traditional classpath.
It seems like intellij decides for the wrong reason to switch to the modulepath, probably because log4j has a module descriptor.
After all the problem was that maven-compiler-plugin was in the pom.xml as a dependency. That is not necessary as it is only used during packaging. After I removed it, the errors went away.

persistence unit gets overwritten

I'm coding a standalone java application, build it from a Maven project and executed by calling the jar file.
In the application I have an entity manager using a persistence unit, defined in my persistence.xml to be standalone (transaction-type="RESOURCE_LOCAL")
The actual Entity annotated classes comes from another project and are hence added to the pom.xml file as a dependency.
The problem is that the persistence.xml of the project containing the entity classes overwrites the actual standalone application's persistence.xml in the target folder of the jar when it's build.
The Maven build process goes through successfully, but when running the jar I get an exception like:
Exception in thread "main" javax.persistence.PersistenceException: No
persistence providers available for "PersistenceUnitXXX" after trying
the following discovered implementations:
org.eclipse.persistence.jpa.PersistenceProvider
Furthermore the persistence unit of the projects containing the Entity classes is meant for deployment on an application server, so I don't think it is possible to reuse that persistence.xml for the standalone application.
The pom looks like this:
<?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>
<parent>
<groupId>com.my</groupId>
<artifactId>projects</artifactId>
<version>1.0</version>
<relativePath>../..</relativePath>
</parent>
<groupId>com.my.projects</groupId>
<artifactId>mystandaloneapp</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.oracle.weblogic</groupId>
<artifactId>ojdbc7</artifactId>
<version>12.1.3-0-0</version>
</dependency>
<dependency>
<groupId>org.apache.openejb</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0-5</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.2</version>
</dependency>
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>javax.persistence</artifactId>
<version>2.1.0</version>
</dependency>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-web-api</artifactId>
<version>7.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20170516</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4.5</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
<version>1.4.2.RELEASE</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.16.16</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.my</groupId>
<artifactId>my_entities</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.my.StandAloneApp</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>create-my-bundle</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<descriptors>
<descriptor>eksport-assembly.xml</descriptor>
</descriptors>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
The file structure is
-projects
-mystandaloneapp
-src
-main
-java
-com
-my
-db
-EntityConsumer
-resources
-WEB-INF
-persistence.xml
-my_entities
-src
-main
-java
-com
-my
-model
-db
-MyEntity
-resources
-WEB-INF
-persistence.xml
Okay the problem is a duplicate of this one, which presents a workable solution:
Maven overwrite resource file in dependency

Categories

Resources