Issue
Having a livid time trying to figure out a compile problem.
I am branching off of an existing Maven project and mid-project I switched from the Netbeans IDE to Eclipse IDE (yesterday, actually). The project runs perfectly when I run it from inside of the Eclipse IDE. However, when I compile the project to a self-contained executable jar it can no longer find the getClass().getResource() pathing.
I am assuming there is a compiler issue or something when translating this to the jar?
Project path is: /src/main/resources/Images
IDE Target is: target/classes/Images
In the JAR it is in: resources/Images
Is this correct, or am I missing something painfully obvious?
The console error message is:
Exception in thread "AWT-EventQueue-0" java.lang.NullPointerException at javax.swing.ImageIcon.<init>(ImageIcon.java:217)
The code that is throwing this event is:
jLabel1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/com/openbravo/images/unicenta.png"));
In order to troubleshoot and test for NULL
I slide this in before the line:
System.out.println("Testing Resource: " + getClass().getResource("/com/openbravo/images/unicenta.png"));
When executing from the IDE I get this (properly) returned:
Testing Resource: file:/C:/Users/Fearfullsmile/Documents/My%20Programs/KB_Mercantile/target/classes/com/openbravo/images/unicenta.png
When executing from the Executable JAR I get NULL
:
Testing Resource: null
If someone could please offer me some direction I would be greatly appreciative. Not trying to re-work the wheel, but this seems like it should work! I will be working on this all night, so if I come up with the solution I will update as soon as possible. :)
Thanks!
UPDATES:
As per request, here are the contents of 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.unicenta</groupId>
<artifactId>unicentaopos</artifactId>
<version>4.6.4</version>
<packaging>jar</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<kotlin.version>1.3.70</kotlin.version>
<!-- Specify this via command line i.e -Dbitrock.exec=/path/to/bitrock/builder-->
<bitrock.exec/>
<!-- windows, osx, linux -->
<bitrock.platform/>
<!-- Licence location -->
<bitrock.licence/>
</properties>
<dependencies>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>core</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>com.google.zxing</groupId>
<artifactId>javase</artifactId>
<version>3.3.0</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-swing</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-web</artifactId>
<version>11</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.6</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.2.2</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring</artifactId>
<version>2.5</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>2.0.6</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jcommon</artifactId>
<version>1.0.24</version>
</dependency>
<dependency>
<groupId>org.jfree</groupId>
<artifactId>jfreechart</artifactId>
<version>1.0.19</version>
</dependency>
<!--<dependency>
<groupId>org.eclipse.jdt</groupId>
<artifactId>core</artifactId>
<version>3.3.0-v_771</version>
</dependency>-->
<dependency>
<groupId>commons-beanutils</groupId>
<artifactId>commons-beanutils</artifactId>
<version>1.9.3</version>
</dependency>
<dependency>
<groupId>commons-digester</groupId>
<artifactId>commons-digester</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>org.apache.poi</groupId>
<artifactId>poi</artifactId>
<version>3.10.1</version>
</dependency>
<dependency>
<groupId>net.sf.barcode4j</groupId>
<artifactId>barcode4j</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.apache.velocity</groupId>
<artifactId>velocity</artifactId>
<version>1.7</version>
</dependency>
<dependency>
<groupId>oro</groupId>
<artifactId>oro</artifactId>
<version>2.0.8</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.2.2</version>
</dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>org.beanshell</groupId>
<artifactId>bsh</artifactId>
<version>2.0b4</version>
</dependency>
<dependency>
<groupId>org.bidib.jbidib.org.qbang.rxtx</groupId>
<artifactId>rxtxcomm</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.jpos</groupId>
<artifactId>jpos</artifactId>
<version>2.0.10</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>com.sleepycat</groupId>
<artifactId>je</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.swinglabs.swingx</groupId>
<artifactId>swingx-all</artifactId>
<version>1.6.5-1</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.apache.axis</groupId>
<artifactId>axis-jaxrpc</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>javax.xml.soap</groupId>
<artifactId>saaj-api</artifactId>
<version>1.3.5</version>
</dependency>
<dependency>
<groupId>axis</groupId>
<artifactId>axis-wsdl4j</artifactId>
<version>1.5.1</version>
</dependency>
<dependency>
<groupId>commons-discovery</groupId>
<artifactId>commons-discovery</artifactId>
<version>0.5</version>
</dependency>
<!--
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
<version>1.2</version>
</dependency>-->
<dependency>
<groupId>org.swinglabs</groupId>
<artifactId>swing-layout</artifactId>
<version>1.0.3</version>
</dependency>
<dependency>
<groupId>net.sourceforge.javacsv</groupId>
<artifactId>javacsv</artifactId>
<version>2.0</version>
</dependency>
<dependency>
<groupId>org.netbeans.external</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>RELEASE82</version>
</dependency>
<dependency>
<groupId>com.javapos</groupId>
<artifactId>jpos</artifactId>
<version>1.13</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.49</version>
</dependency>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.10.2.0</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.0.b2</version>
</dependency>
<dependency>
<groupId>io.posapps</groupId>
<artifactId>posapps-client</artifactId>
<version>1.4.9</version>
<classifier>exe</classifier>
</dependency>
<!-- Batik Dependencies now wrapped included in apache xmlgraphics fop -->
<!-- https://mvnrepository.com/artifact/org.apache.xmlgraphics/fop -->
<dependency>
<groupId>org.apache.xmlgraphics</groupId>
<artifactId>fop</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports</artifactId>
<version>6.4.0</version>
<exclusions>
<exclusion>
<groupId>com.lowagie</groupId>
<artifactId>itext</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>net.sf.jasperreports</groupId>
<artifactId>jasperreports-fonts</artifactId>
<version>6.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jdt.core.compiler</groupId>
<artifactId>ecj</artifactId>
<version>4.6.1</version>
</dependency>
<!-- Commercial version -->
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.9.7</version>
</dependency>
<!-- https://mvnrepository.com/artifact/de.sciss/weblaf -->
<dependency>
<groupId>de.sciss</groupId>
<artifactId>weblaf</artifactId>
<version>1.2.9</version>
<exclusions>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-nop</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</exclusion>
<exclusion>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>javax.persistence</groupId>
<artifactId>persistence-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>com.dalsemi.onewire</groupId>
<artifactId>OneWireAPI</artifactId>
<version>0.1</version>
</dependency>
<!-- 4.2.2 -->
<dependency>
<groupId>org.usb4java</groupId>
<artifactId>usb4java</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>javax.usb</groupId>
<artifactId>usb-api</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.jdatepicker</groupId>
<artifactId>jdatepicker</artifactId>
<version>1.3.4</version>
</dependency>
<!-- https://mvnrepository.com/artifact/com.sleepycat/je -->
<dependency>
<groupId>com.sleepycat</groupId>
<artifactId>je</artifactId>
<version>5.0.73</version>
</dependency>
<!-- Kotlin -->
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.pushingpixels</groupId>
<artifactId>trident</artifactId>
<version>1.4</version>
</dependency>
<dependency>
<groupId>org.pushingpixels</groupId>
<artifactId>substance</artifactId>
<version>7.1.00</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.postgresql/postgresql -->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>9.4.1208</version>
</dependency>
<dependency>
<groupId>de.sciss</groupId>
<artifactId>weblaf-ui</artifactId>
<version>2.1.3</version>
<type>jar</type>
</dependency>
</dependencies>
<build>
<plugins>
<!-- Kotlin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.openbravo.pos.forms.StartPOS</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<artifactId>kotlin-maven-plugin</artifactId>
<groupId>org.jetbrains.kotlin</groupId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<phase>process-sources</phase>
<goals>
<goal>compile</goal>
</goals>
</execution>
<execution>
<id>test-compile</id>
<phase>process-test-sources</phase>
<goals>
<goal>test-compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>prepare-package</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}/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>
<version>2.6</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>com.openbravo.pos.forms.StartPOS</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>2.7</version>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${project.build.directory}</outputDirectory>
<resources>
<resource>
<targetPath>${basedir}/target/lib/Windows</targetPath>
<directory>${basedir}/src/other/Windows</directory>
<filtering>false</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/lib/Linux</targetPath>
<directory>${basedir}/src/other/Linux</directory>
<filtering>false</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/lib/Mac_OS_X</targetPath>
<directory>${basedir}/src/other/Mac_OS_X</directory>
<filtering>false</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/</targetPath>
<directory>${basedir}/src/scripts</directory>
<filtering>false</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/licensing</targetPath>
<directory>${basedir}/src/installer/licensing</directory>
<filtering>false</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/Bonus</targetPath>
<directory>${basedir}/src/other/Bonus</directory>
<filtering>false</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/Configs</targetPath>
<directory>${basedir}/src/other/Configs</directory>
<filtering>false</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/Templates</targetPath>
<directory>${basedir}/src/other/Templates</directory>
<filtering>false</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/reports/com</targetPath>
<directory>${basedir}/src/main/resources/com</directory>
<filtering>false</filtering>
</resource>
<resource>
<targetPath>${basedir}/target/locales</targetPath>
<directory>${basedir}/src/main/resources</directory>
<filtering>false</filtering>
<excludes>
<exclude>com/**</exclude>
</excludes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<!-- BitRock -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.4.0</version>
<executions>
<execution>
<goals>
<goal>exec</goal>
</goals>
</execution>
</executions>
<configuration>
<executable>${bitrock.exec}</executable>
<arguments>
<argument>build</argument>
<argument>${basedir}/src/installer/unicentaopos.xml</argument>
<argument>${bitrock.platform}</argument>
<argument>--license</argument>
<argument>${bitrock.licence}</argument>
</arguments>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<showDeprecation>true</showDeprecation>
<debug>true</debug>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-source-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>attach-sources</id>
<goals>
<goal>jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
<extensions>
<extension>
<groupId>org.apache.maven.wagon</groupId>
<artifactId>wagon-ftp</artifactId>
<version>2.10</version>
</extension>
</extensions>
<finalName>unicentaopos</finalName>
</build>
<repositories>
<repository>
<id>unicenta-repo</id>
<url>http://repo.unicenta.org/maven2/</url>
<layout>default</layout>
</repository>
<repository>
<id>central</id>
<url>https://repo1.maven.org/maven2/</url>
<layout>default</layout>
</repository>
<!--These are needed for Swing/Netbeans -->
<repository>
<id>netbeans</id>
<name>NetBeans</name>
<url>http://netbeans.apidesign.org/maven2/</url>
</repository>
</repositories>
<distributionManagement>
<repository>
<id>unicenta-repo</id>
<url>ftp://repo.unicenta.org/</url>
<uniqueVersion>false</uniqueVersion>
</repository>
</distributionManagement>
<name>unicentaopos</name>
</project>
JDK Version is: jdk1.8.0_202
Maven Version is: Apache Maven 3.9.4
Eclipse IDE Version is: 2023-09 (4.29.0)
Plugin Installed: Lombok v1.18.30 "Envious Ferret"
Solution
This issue is resolved. There were no coding issues found after many hours of troubleshooting.
Issue lays completely in the IDE.
When running from Eclipse IDE and building it is running as a 'Java Application'. Going to 'Build Executable JAR' always ended in this strange error.
After doing some research, found out about the M2E Maven Integration tools for Eclipse. Actually needed right-click my project in the Project Explorer pane then go to Run As -> Maven build.... From here I can setup my output file information. NOTE: You must set a Goal in the Edit Configuration window or it will not build. I used 'package' as my Goal and it built fine.
Able to now run the JAR from my Command Prompt and everything is working perfectly!
Answered By - Jonathan Styles
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.