Using poi-ooxml broke resource providing - java

I am trying to make jar file with external config files. Everything worked fine before using poi-ooxml library. After it I encounter problem with resource providing. I use next 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>xxx</groupId>
<artifactId>yyy</artifactId>
<version>0.1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<mainClass>zzz</mainClass>
</manifest>
<manifestEntries>
<Class-Path>./configs/</Class-Path>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<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.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3</version>
<configuration>
<excludes>
<exclude>**/*.properties</exclude>
</excludes>
<archive>
<manifestEntries>
<Class-Path>configs/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>install</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/configs</outputDirectory>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.9</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.3.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>RELEASE</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>xxx</groupId>
<artifactId>core</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
</project>
I failed on this line:
LogManager.getLogManager().readConfiguration(MethodHandles.lookup().lookupClass().getClassLoader().getResourceAsStream(fileName));
getResourceAsStream return null, but when I delete poi-ooxml dependency from pom file everything works fine.

The problem is in Apache Assembly plugin. Use Apache Shade plugin instead.
https://maven.apache.org/plugins/maven-shade-plugin/

Related

Could not generate DSL.xtext in maven

I have xtext project. I usualy generate src-gen by double clicking on my DSL.xtext and click generate artifacts but I don't know how to do that in pom xml.
I instead used inappropraite way which is copy all the src-gen and xtend-gen to target which not good. I need maven to take care of my the generation.
The ultimale goal is mvn install then getting a jar file.
myxtext called : DSL.xtext
can someone advise me ?
My pom.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.xtext.DSL</groupId>
<artifactId>org.xtext.DSL</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<properties>
<xtextVersion>2.27.0</xtextVersion>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<SdlFileName>sdl2-v8.1.2</SdlFileName>
</properties>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<includes>
<include>**/*.java</include>
<include>**/*.xtend</include>
<include>**/*.xtext</include>
<include>**/*.mwe2</include>
<include>**/*.tokens</include>
<include>**/*.xtextbin</include>
</includes>
</resource>
<resource>
<directory>src-gen</directory>
<includes>
<include>**/*.java</include>
<include>**/*.xtend</include>
<include>**/*.xtext</include>
<include>**/*.mwe2</include>
<include>**/*.tokens</include>
<include>**/*.xtextbin</include>
</includes>
</resource>
<resource>
<directory>xtend-gen</directory>
<includes>
<include>**/*.java</include>
<include>**/*.xtend</include>
<include>**/*.xtext</include>
<include>**/*.mwe2</include>
<include>**/*.tokens</include>
<include>**/*.xtextbin</include>
</includes>
</resource>
<resource>
<directory>resources</directory>
<includes>
<include>**/*.properties</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>3.3.0</version>
<executions>
<execution>
<id>add-gen-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>src-gen</source>
</sources>
</configuration>
</execution>
<execution>
<id>add-extra-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>xtend-gen</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>org.xtext.DSL.Main</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<finalName>${SdlFileName}</finalName>
<appendAssemblyId>false</appendAssemblyId>
</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>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
<plugin>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
<version>${xtextVersion}</version>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.codehaus.mojo
</groupId>
<artifactId>
exec-maven-plugin
</artifactId>
<versionRange>
[1.2.1,)
</versionRange>
<goals>
<goal>java</goal>
</goals>
</pluginExecutionFilter>
<action>
<ignore></ignore>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
<dependencies>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore</artifactId>
<version>2.6.0.v20100614-1136</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.common</artifactId>
<version>2.20.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.mwe2.language</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtend</groupId>
<artifactId>xtend-maven-plugin</artifactId>
<version>${xtextVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext</artifactId>
<version>${xtextVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.xbase</artifactId>
<version>${xtextVersion}</version>
</dependency>
<dependency>
<groupId>org.eclipse.xtext</groupId>
<artifactId>org.eclipse.xtext.xtext.generator</artifactId>
<version>${xtextVersion}</version>
</dependency>
<!--<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.mwe2.launch</artifactId>
<version>2.13.0</version>
</dependency>
-->
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>30.0-jre</version>
</dependency>
<dependency>
<groupId>com.google.inject</groupId>
<artifactId>guice</artifactId>
<version>5.0.1</version>
</dependency>
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.json</artifactId>
<version>1.1.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.eclipse.emf/org.eclipse.emf.ecore.xmi -->
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore.xmi</artifactId>
<version>2.16.0</version>
</dependency>
</dependencies>
</project>
If you noticed, instead of making maven generating the files, I copied them from eclipse. However the generated jar is working in this way, but i maven to take care and generate for me the src-gen and xtend-gen

JavaFX export without VM options

Let me start off by saying this question is very similar to this one:
JavaFX Export and VM arguments
I've seen this question and it has helped me a lot further. However, I am quite new to Maven.
I'm trying to export my maven project, which uses both JavaFX and JMTP, to an executeable jar file. However, after running mvn clean package, running the jar file (with dependecies) gives the following error:
Error: JavaFX runtime components are missing, and are required to run this application
This is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>TestMavenFX</artifactId>
<version>1.0-SNAPSHOT</version>
<repositories>
<repository>
<id>in-project</id>
<name>JMTP-in-project</name>
<url>file://${project.basedir}\libs</url>
<layout>default</layout>
</repository>
</repositories>
<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>org.openjfx</groupId>
<artifactId>javafx-graphics </artifactId>
<version>14</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>14</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml </artifactId>
<version>14</version>
<classifier>win</classifier>
</dependency>
<dependency>
<groupId>jmtp</groupId>
<artifactId>jmtp-sdk</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<resources>
<resource>
<directory>src</directory>
<excludes>
<exclude>*.java</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>12</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.1</version>
<configuration>
<mainClass>org.example.App</mainClass>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<goals>
<goal>java</goal>
</goals>
</execution>
</executions>
<configuration>
<mainClass>main.java.org.example.App</mainClass>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>
main.java.org.example.App
</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>make-jar-with-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<archive>
<manifest>
<mainClass>main.java.org.example.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Is there anyone who could help with this? I would like to use this instead of a .bat file to run a command to actually run the JAR file, but I'm quite stuck.

How do I work correctly with profiles, classifiers and modules in Maven?

I'm trying to create a Maven configuration that supports the same code for two different environments. One environment is Java 6 with Seam, the other is Java 7 with JEE.
My project is a multi module project with a parent pom where I've configured two profiles. The interesting parts in the parent pom:
<profiles>
<profile>
<id>JDK7</id>
<properties>
<jdk.version>1.7</jdk.version>
<profile.classifier>with-beans-xml</profile.classifier>
</properties>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>${profile.classifier}</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>JDK6</id>
<properties>
<jdk.version>1.6</jdk.version>
<profile.classifier>without-beans-xml</profile.classifier>
</properties>
<!-- Identical parts left out for brevity -->
<build>
<plugins>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>${profile.classifier}</classifier>
<excludes>
<exclude>src/main/resources/META-INF/beans.xml</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
In a sub module of this pom I need to reference specific versions of other modules to be sure they are all using the same build version of Java and should contain or not contain beans.xml.
This is how I've done that:
<parent>
<groupId>commons</groupId>
<artifactId>parent-pom</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>some-module</artifactId>
<dependencies>
<dependency>
<groupId>commons</groupId>
<artifactId>core</artifactId>
<version>${project.version}</version>
<classifier>${profile.classifier}</classifier>
</dependency>
</dependencies>
The properties decalared above resolves just fine, but the dependency called core above contains references to other modules that contain the core functionality of the entire project.
The dependencies in core doesn't resolve when I import that module into other modules.
This is the dependency hierarchy I'm expecting:
- some-module
- core
- some-other-module
However, after adding core as a dependency to another module, I explicitly need to add some-other-module for it to be available too, i.e. some-other-module is not transitive from referencing core.
Am I going about this the wrong way? It works just fine with the different versions, just that I have to add them explicitly which I'd rather not to avoid confusion when other users are going to use this.
Updated
By request, here is the full parent pom and one of the modules that are experiencing the problems with transitive dependencies.
parent 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>se.commons</groupId>
<artifactId>healthcheck-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>healthcheck-parent-pom</name>
<modules>
<module>healthcheck-core</module>
<module>healthcheck-xsd</module>
<module>healthcheck-jms</module>
<module>healthcheck-db</module>
<module>healthcheck-filesystem</module>
<module>healthcheck-http</module>
</modules>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.home>${JAVA_1_7_HOME}</java.home>
</properties>
<profiles>
<profile>
<id>JDK7</id>
<!-- <activation> -->
<!-- <activeByDefault>true</activeByDefault> -->
<!-- </activation> -->
<properties>
<!-- Build properties -->
<jdk.version>1.7</jdk.version>
<profile.classifier>with-beans-xml</profile.classifier>
<bom.version>2.0.0.R</bom.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>se.commons</groupId>
<artifactId>bom</artifactId>
<version>${bom.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>${profile.classifier}</classifier>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Default</effort>
<threshold>Default</threshold>
<xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
<failOnError>true</failOnError>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<targetJdk>${jdk.version}</targetJdk>
<configuration>
<omitVisitors>FindReturnRef</omitVisitors>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<goals>
<goal>checkstyle</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<configLocation>${basedir}/../src/site/checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<dependencies>
<dependency>
<!-- add support for ssh/scp -->
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<configuration>
<locales>sv</locales>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>JDK6</id>
<properties>
<!-- Build properties -->
<jdk.version>1.6</jdk.version>
<profile.classifier>without-beans-xml</profile.classifier>
<bom.version>2.0.0.R</bom.version>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>se.commons</groupId>
<artifactId>bom</artifactId>
<version>${bom.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<resources>
<resource>
<directory>src/main/resources/META-INF</directory>
<excludes>
<exclude>beans.xml</exclude>
</excludes>
</resource>
</resources>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classifier>${profile.classifier}</classifier>
<excludes>
<exclude>src/main/resources/META-INF/beans.xml</exclude>
</excludes>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Default</effort>
<threshold>Default</threshold>
<xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
<failOnError>true</failOnError>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<targetJdk>${jdk.version}</targetJdk>
<configuration>
<omitVisitors>FindReturnRef</omitVisitors>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.18.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<version>2.15</version>
<executions>
<execution>
<goals>
<goal>checkstyle</goal>
</goals>
<phase>compile</phase>
</execution>
</executions>
<configuration>
<configLocation>${basedir}/../src/site/checkstyle.xml</configLocation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>attach-javadocs</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<version>3.3</version>
<dependencies>
<dependency><!-- add support for ssh/scp -->
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ssh</artifactId>
<version>2.4</version>
</dependency>
</dependencies>
<configuration>
<locales>sv</locales>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>2.4</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-report-plugin</artifactId>
<version>2.18.1</version>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>3.0.1</version>
<configuration>
<effort>Default</effort>
<threshold>Default</threshold>
<xmlOutputDirectory>target/findbugs</xmlOutputDirectory>
<failOnError>true</failOnError>
<xmlOutput>true</xmlOutput>
<findbugsXmlOutput>true</findbugsXmlOutput>
<findbugsXmlWithMessages>true</findbugsXmlWithMessages>
<targetJdk>${jdk.version}</targetJdk>
<configuration>
<omitVisitors>FindReturnRef</omitVisitors>
</configuration>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-pmd-plugin</artifactId>
<version>3.4</version>
<configuration>
<targetJdk>${jdk.version}</targetJdk>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.7</version>
<reportSets>
<reportSet>
<reports>
<report>cobertura</report>
</reports>
</reportSet>
</reportSets>
<configuration>
<instrumentation>
</instrumentation>
<formats>
<format>xml</format>
<format>html</format>
</formats>
<instrumentation>
<includes>
<include>**/*.class</include>
</includes>
</instrumentation>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>2.8</version>
</plugin>
</plugins>
</reporting>
</project>
And here is one of the modules that use core as a dependency:
<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>se.commons</groupId>
<artifactId>healthcheck-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>healthcheck-jms</artifactId>
<dependencies>
<dependency>
<groupId>se.commons</groupId>
<artifactId>healthcheck-core</artifactId>
<version>${project.version}</version>
<classifier>${profile.classifier}</classifier>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_1.1_spec</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.enterprise</groupId>
<artifactId>cdi-api</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
And finally, here is the pom of core:
<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>se.commons</groupId>
<artifactId>healthcheck-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>healthcheck-core</artifactId>
<dependencies>
<dependency>
<groupId>se.commons</groupId>
<artifactId>healthcheck-xsd</artifactId>
<version>${project.version}</version>
<classifier>${profile.classifier}</classifier>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
I finally gave up on the above solution after finding similar questions that never got a clear answer.
It doesn't seem to be possible to resolve transitive dependencies using a classifier, only the standard GAV.
I settled on a different artifactId to differentiate the projects instead.

Compile C to native library in Maven

I have a Java project that relies on C source files. I have the proper JNI header files, I just need to compile them with the C code to a dll (or Linux/OSX equivalent) in target/. My current pom.xml builds the Java code, but doesn't build the dll.
<?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>xyz.jadonfowler</groupId>
<artifactId>o</artifactId>
<packaging>jar</packaging>
<version>2.0</version>
<properties>
<!-- Native compiler -->
<compiler-name>clang</compiler-name>
<linker-name>clang</linker-name>
</properties>
<dependencies>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-jdbc</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.9</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
</dependencies>
<build>
<defaultGoal>install</defaultGoal>
<sourceDirectory>src</sourceDirectory>
<testSourceDirectory>src</testSourceDirectory>
<resources>
<resource>
<directory>res</directory>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
<optimize>true</optimize>
<debug>true</debug>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>xyz.jadonfowler.o.WebIDE</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.1</version>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.SF</exclude>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
</excludes>
</filter>
</filters>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>xyz.jadonfowler.o.WebIDE</mainClass>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.alexkasko.maven</groupId>
<artifactId>jni-headers-maven-plugin</artifactId>
<version>1.0.6</version>
<executions>
<!-- generate header for native methods -->
<execution>
<id>javah</id>
<phase>compile</phase>
<goals>
<goal>javah</goal>
</goals>
<configuration>
<javahClass>xyz.jadonfowler.o.OCBindings</javahClass>
<javahOutputFilePath>${project.basedir}/xyz_jadonfowler_o_OCBindings.h</javahOutputFilePath>
</configuration>
</execution>
<!-- generate header for java methods -->
<!-- Not need atm
<execution>
<id>javap</id>
<phase>compile</phase>
<goals>
<goal>javap</goal>
</goals>
<configuration>
<javapClass>xyz.jadonfowler.o.OCBindings</javapClass>
<javapOutputFilePath>${project.basedir}/my_header_callbacks.h</javapOutputFilePath>
</configuration>
</execution> -->
</executions>
</plugin>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<version>3.2.3</version>
<extensions>true</extensions>
<configuration>
<c>
<name>${compiler-name}</name>
<debug>false</debug>
<includes>
<include>*.h</include>
<include>*.c</include>
</includes>
<!-- Options for compiler -->
<options combine.children="append">
<option>-I $JAVA_HOME</option>
<option>-I $JAVA_HOME/*</option>
</options>
</c>
<linker>
<name>${linker-name}</name>
</linker>
<libraries>
<library>
<type>jni</type>
<narSystemPackage>xyz.jadonfowler.o</narSystemPackage>
</library>
</libraries>
</configuration>
</plugin>
</plugins>
</build>
<profiles>
<profile>
<id>windows-common</id>
<activation>
<os>
<family>windows</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<cpp>
<options combine.children="append">
<option>-mthreads</option>
</options>
</cpp>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>linux-common</id>
<activation>
<os>
<family>linux</family>
</os>
</activation>
<build>
<plugins>
<plugin>
<groupId>com.github.maven-nar</groupId>
<artifactId>nar-maven-plugin</artifactId>
<extensions>true</extensions>
<configuration>
<cpp>
<options combine.children="append">
<option>-pthread</option>
</options>
</cpp>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I'm using Java 8 with Clang. I have the jni-headers-maven-plugin, but I don't think I need it because I don't need to generate the headers on-the-fly. I also have the nar-maven-plugin, which I think is configured correctly, but it isn't showing up in the log anywhere.

Error: Could not find or load main class - how to compile to jar by maven?

I have problem with compiling classes to jar. When i do mvn package ant try to run it then i get error Could not find or load main class.
<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.test</groupId>
<artifactId>JIRA-Re-Index</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>JIRA-Re-Index</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.sourceforge.htmlunit</groupId>
<artifactId>htmlunit</artifactId>
<version>2.15</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<mainClass>com.test.main.App</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
What am I doing wrong? My main class is in src/main/java/com.test.main.App
You need maven-jar-plugin to help with that.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.test.main.App</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
Whereas maven-assembly-plugin is used for
The Assembly Plugin for Maven is primarily intended to allow users to aggregate the project output along with its dependencies, modules, site documentation, and other files into a single distributable archive.
Hope below link can help you.
main-class-in-the-manifest-of-my-generated-jar

Categories