Netbeans runtime configuration in jar - java

I have a maven project and jni4net is one of the dependency and it's running fine in Netbeans. But when i package it into a jar i get the error java.lang.UnsatisfiedLinkError: no jni4net.n-0.8.8.0 in java.library.path. I solved this problem in Netbenas by setting Working directory and VM Options in Project Properties -> Run. Now is there a way to include these configurations while packaging it as jar, or any other solution.
Thanks in advance...
Here is my 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>com.base</groupId>
<artifactId>base</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>BASE</name>
<repositories>
<repository>
<id>repo</id>
<url>file://${project.basedir}/./temp-repo</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>jni4net</groupId>
<artifactId>jni4net.j</artifactId>
<version>0.8.8.0</version>
</dependency>
<dependency>
<groupId>customId</groupId>
<artifactId>customId</artifactId>
<version>1.0</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-chrome-driver</artifactId>
<version>3.0.0-beta2</version>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-firefox-driver</artifactId>
<version>3.0.0-beta2</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.3.5</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.mysite.myproject.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.1</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/lib</outputDirectory>
<resources>
<resource>
<directory>lib</directory>
<!--<filtering>true</filtering>-->
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

Related

Cannot start Heroku project on windows. Main class not found, and if found it cannot find other classes

I am trying to deploy my first discord bot to heroku, but it cannot find the main File.
My pom.xml 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>
<groupId>org.example</groupId>
<artifactId>kostisBot</artifactId>
<version>1.0-SNAPSHOT</version>
<name>kostisBot</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<repositories>
<repository>
<id>dv8tion</id>
<name>m2-dv8tion</name>
<url>https://m2.dv8tion.net/releases</url>
</repository>
<repository>
<id>central</id>
<name>bintray</name>
<url>http://jcenter.bintray.com</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>15</maven.compiler.source>
<maven.compiler.target>15</maven.compiler.target>
<!-- Use the latest version whenever possible. -->
<jackson.version>2.12.0</jackson.version>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/javax.json/javax.json-api -->
<dependency>
<groupId>javax.json</groupId>
<artifactId>javax.json-api</artifactId>
<version>1.1.4</version>
</dependency>
<dependency>
<groupId>com.codesnippets4all</groupId>
<artifactId>quick-json</artifactId>
<version>1.0.4</version> </dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jackson.version}</version>
</dependency>
<dependency>
<groupId>com.jayway.jsonpath</groupId>
<artifactId>json-path</artifactId>
<version>2.1.0</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>
<dependency>
<groupId>com.sedmelluq</groupId>
<artifactId>lavaplayer</artifactId>
<version>1.3.75</version>
</dependency>
<dependency>
<groupId>com.github.dhiraj072</groupId>
<artifactId>random-word-generator</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.jagrosh</groupId>
<artifactId>jda-utilities</artifactId>
<version>3.0.5</version>
<type>pom</type>
</dependency>
<dependency>
<groupId>net.dv8tion</groupId>
<artifactId>JDA</artifactId>
<version>4.2.1_255</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<!-- This tells Maven to include all dependencies -->
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>src.main.java.Kostis.App.java</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<!-- 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.1</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</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>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>15</source>
<target>15</target>
</configuration>
</plugin>
<plugin>
<groupId>com.heroku.sdk</groupId>
<artifactId>heroku-maven-plugin</artifactId>
<version>3.0.3</version>
<configuration>
<appName>kostisbot</appName>
<processTypes>
<web>java $JAVA_OPTS -cp target/classes:target/dependency/* src.main.java.Kostis.App.java</web>
</processTypes>
</configuration>
</plugin>
<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>
</plugins>
</build>
</project>
`
My proc file looks like this:
web: java $JAVA_OPTS -cp target/classes:target/dependency/* src.main.java.Kostis.App.java
this is the path for Main App [here][1]
Way before i think main loaded but all the other classes failed:
[enter image description here][2]
I'd appreciate any help. I have been trying to run my app for a while now and nothing seems to be working.
Thanks in advance.
[1]: https://i.stack.imgur.com/kNQ0B.png
[2]: https://i.stack.imgur.com/WqMyz.png

Error creating shaded jar: Problem shading JAR java.lang.SecurityException: Invalid signature file digest for Manifest main attributes

I created fat jar(common-1.0-SNAPSHOT.jar) using maven shade plugin. It generated successfully. This common dependency include to new maven project and try to generate fat jar. But it given above error. I tried with different answers as exclude MANIFEST files. After excluding MANIFEST files it asked to exclude .class files in common.jar library.
Need I use any signing method to common library or is there any way to ignore this error.
Thank you.
common library pom.xl
<?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>com.test</groupId>
<artifactId>common</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<jakson-version>2.9.2</jakson-version>
<protobuf-version>3.2.0</protobuf-version>
<slf4j-version>1.7.14</slf4j-version>
<bigtable-version>1.13.0</bigtable-version>
<hbase-version>2.2.3</hbase-version>
<pubsub-version>1.103.0</pubsub-version>
<junit-version>4.12</junit-version>
<netty-version>2.0.29.Final</netty-version>
<grpc-netty-shaded-version>1.27.1</grpc-netty-shaded-version>
<netty-codec-http2-version>4.1.45.Final</netty-codec-http2-version>
<os-maven-plugin-version>1.5.0.Final</os-maven-plugin-version>
<maven-compiler-plugin-version>3.7.0</maven-compiler-plugin-version>
<java-version>1.8</java-version>
<protobuf-maven-plugin-version>0.5.0</protobuf-maven-plugin-version>
<maven-surefire-plugin-version>2.21.0</maven-surefire-plugin-version>
<rabbit-mq-version>5.8.0</rabbit-mq-version>
<spark-core-version>2.7.1</spark-core-version>
<slf4j-simple-version>1.7.7</slf4j-simple-version>
</properties>
<repositories>
<repository>
<id>apache.snapshots</id>
<name>Apache Development Snapshot Repository</name>
<url>https://repository.apache.org/content/repositories/snapshots/</url>
<releases>
<enabled>true</enabled>
</releases>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jakson-version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>${jakson-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>${slf4j-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>${slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.cloud.bigtable</groupId>
<artifactId>bigtable-hbase-2.x-shaded</artifactId>
<version>${bigtable-version}</version>
<exclusions>
<exclusion>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-shaded-client</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.hbase</groupId>
<artifactId>hbase-shaded-client</artifactId>
<version>${hbase-version}</version>
</dependency>
<dependency>
<groupId>com.google.cloud</groupId>
<artifactId>google-cloud-pubsub</artifactId>
<version>${pubsub-version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit-version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>${rabbit-mq-version}</version>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>${spark-core-version}</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>${slf4j-simple-version}</version>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>${os-maven-plugin-version}</version>
</extension>
</extensions>
<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>
</plugin>
<plugin>
<groupId>org.xolstice.maven.plugins</groupId>
<artifactId>protobuf-maven-plugin</artifactId>
<version>${protobuf-maven-plugin-version}</version>
<configuration>
<protocArtifact>com.google.protobuf:protoc:3.6.1:exe:${os.detected.classifier}
</protocArtifact>
<pluginId>grpc-java</pluginId>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.4.0:exe:${os.detected.classifier}</pluginArtifact>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>compile-custom</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven-surefire-plugin-version}</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-javadoc-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<failOnError>false</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
new project 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>com.test</groupId>
<artifactId>new-project</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>com.test</groupId>
<artifactId>common</artifactId>
<version>LATEST</version>
</dependency>
</dependencies>
<build>
<extensions>
<extension>
<groupId>kr.motd.maven</groupId>
<artifactId>os-maven-plugin</artifactId>
<version>1.5.0.Final</version>
</extension>
</extensions>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.1</version>
<executions>
<!-- Run shade goal on package phase -->
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/*.DSA</exclude>
<exclude>META-INF/*.RSA</exclude>
<exclude>META-INF/*.MF</exclude>
</excludes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19</version>
<configuration>
<argLine>-Xmx1024m</argLine>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.7.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.8</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludes>META-INF/*.SF,META-INF/*.DSA,META-INF/*.RSA</excludes>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<configuration>
<cleanupDaemonThreads>false</cleanupDaemonThreads>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Try with spring-boot-maven-plugin.

Apache POI ClasDefNotFoundException when in fat jar compiled with Maven

I had a pom.xml that was previously working, creating a fat .jar library with all the dependencies I need inside of it. Then I needed to use the library Apache POI, then I added this to my pom.xml
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version>
</dependency>
Then, using Eclipse, I run my JUnit tests, that covered the code which I am with the problem. Ok, then I run a Maven Build using Eclipse and then copied the .jar to the place where I am using.
When I called it, I got this error:
java.lang.NoClassDefFoundError: Could not initialize class
org.apache.poi.openxml4j.opc.internal.marshallers.ZipPackagePropertiesMarshaller
at org.apache.poi.openxml4j.opc.OPCPackage.init(OPCPackage.java:162)
at
org.apache.poi.openxml4j.opc.OPCPackage.(OPCPackage.java:142)
at org.apache.poi.openxml4j.opc.Package.(Package.java:37) at
org.apache.poi.openxml4j.opc.ZipPackage.(ZipPackage.java:88) at
org.apache.poi.openxml4j.opc.OPCPackage.open(OPCPackage.java:273) at
org.apache.poi.util.PackageHelper.open(PackageHelper.java:37) at
org.apache.poi.xssf.usermodel.XSSFWorkbook.(XSSFWorkbook.java:273)
at
com.foo.bar.util.FooBar.myMethod(FooBar.java:62) at
...
The code snippet that has the problem is this, in its first line, when creating XSSFWorkbook:
public static Sheet myMethod(File fileEntry) {
XSSFWorkbook wb = new XSSFWorkbook(new FileInputStream(fileEntry));
Sheet sheet = wb.getSheetAt(0);
return sheet;
}
Then again, the tests I wrote passed inside Eclipse. The whole pom.xml is bellow:
<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.foo</groupId>
<artifactId>bar</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>bar/name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.test.skip>true</maven.test.skip>
</properties>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.json</include>
<include>**/*.json</include>
</includes>
</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>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
<configuration>
<finalName>uber-${artifactId}-${version}</finalName>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/classes/lib</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!-- <classpathPrefix>lib</classpathPrefix> -->
<!-- <mainClass>test.org.Cliente</mainClass> -->
</manifest>
<manifestEntries>
<Class-Path>lib/</Class-Path>
</manifestEntries>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>8</source>
<target>8</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-all</artifactId>
<version>1.10.19</version>
</dependency>
<dependency>
<groupId>org.unitils</groupId>
<artifactId>unitils-core</artifactId>
<version>3.4.2</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi-ooxml</artifactId>
<version>3.13</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>28.0-jre</version>
</dependency>
</dependencies>
</project>

NoClassDefFoundError in Java, using maven and Intellij Designer

When I try to run my application with maven from the terminal, I get a NoClassDefFoundError in main thread. I have used IntelliJ GUI Designer. When I run using IntelliJ it runs fine. But when I run from the terminal theses errors pop up.
Exception in thread "main" java.lang.NoClassDefFoundError: com/intellij/uiDesigner/core/GridLayoutManager
at za.co.##.swingy.view.Start.$$$setupUI$$$(Start.java)
at za.co.##.swingy.view.Start.<init>(Start.java:34)
at za.co.##.swingy.view.Gui.GuiView.run(GuiView.java:10)
at za.co.##.swingy.Swingy.main(Swingy.java:26)
Caused by: java.lang.ClassNotFoundException: com.intellij.uiDesigner.core.GridLayoutManager
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:338)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
This is my 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>#####</groupId>
<artifactId>swingy</artifactId>
<version>1</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<mainClass>XLSCreator</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>1.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.12.6</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>4.1.0.Final</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.15</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.15</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>7.0.3</version>
</dependency>
<dependency>
<groupId>org.swinglabs</groupId>
<artifactId>swingx</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>
I have done some research and I think I have all of the plugins and dependencies. Am I missing Something?
You can try adding the
<goal>copy-dependencies</goal>
Reference : https://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-project-dependencies.html
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>false</overWriteSnapshots>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>

How to pack switchyard application with maven

How can I pack switchyard application with has dependencies to my another project with Maven? Currently I'm trying to make things work as explained here
official dock.
But with no result, on startup of application in log file I see
Caused by: java.lang.NoClassDefFoundError: com/aspiderngi/common/switchyard/InventoryRequest
Caused by: java.lang.ClassNotFoundException: com.aspiderngi.common.switchyard.InventoryRequest from...
Is it possible to achieve anyways?
pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example.switchyard</groupId>
<version>0.0.1-SNAPSHOT</version>
<name>com.example.switchyard:sy-example</name>
<artifactId>sy-example</artifactId>
<properties>
<switchyard.version>2.0.0.Final</switchyard.version>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<packaging>war</packaging>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-bom</artifactId>
<version>${switchyard.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.aspiderngi</groupId>
<artifactId>artifacts-common</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-camel</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-camel-jms</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-resteasy</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-api</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-transform</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-validate</artifactId>
</dependency>
<dependency>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-test-mixin-cdi</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.switchyard.components</groupId>
<artifactId>switchyard-component-bean</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-plugin</artifactId>
<version>${switchyard.version}</version>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
</executions>
<configuration>
<scannerClassNames>
<param>org.switchyard.transform.config.model.TransformSwitchYardScanner</param>
</scannerClassNames>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<failOnMissingWebXml>false</failOnMissingWebXml>
<packagingExcludes>
WEB-INF/lib/*.jar,
WEB-INF/classes/META-INF/switchyard.xml
</packagingExcludes>
<webResources>
<resource>
<directory>target/classes/META-INF</directory>
<targetPath>WEB-INF</targetPath>
<includes>
<include>switchyard.xml</include>
</includes>
</resource>
</webResources>
</configuration>
</plugin>
</plugins>
</build>
</project>
You can use Maven Shade plugin:
https://maven.apache.org/plugins/maven-shade-plugin/
example:
<project>
...
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jackofall</shadedClassifierName> <!-- Any name that makes sense -->
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
...
</project>
Please try this out. The dependent project must have its own pom.xml(child)
Include this child pom to the parent pom. And include the below code in the parent pom.xml
This would directly deploy the application in the server
From project root in cmd execute the below commands:
1. mvn clean
2. mvn dependency:resolve
3. mvn install
if you are using Eclipse, use maven update. then Run As maven install
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
<debug>true</debug>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<configuration>
<skip>false</skip>
</configuration>
</plugin>
<plugin>
<groupId>org.switchyard</groupId>
<artifactId>switchyard-plugin</artifactId>
<version>${switchyard.version}</version>
<executions>
<execution>
<goals>
<goal>configure</goal>
</goals>
</execution>
</executions>
<configuration>
<scannerClassNames>
<param>org.switchyard.transform.config.model.TransformSwitchYardScanner</param>
</scannerClassNames>
</configuration>
</plugin>
<plugin>
<groupId>org.jboss.as.plugins</groupId>
<artifactId>jboss-as-maven-plugin</artifactId>
<executions>
<execution>
<phase>install</phase>
<goals>
<goal>deploy</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
if you are using Bean then include
<scannerClassNames>
<param>org.switchyard.transform.config.model.BeanSwitchYardScanner</param>
</scannerClassNames>

Categories

Resources