Search code examples
mavenjpos

NoClassDefFoundError when running JPOS Q2?


Trying to setup JPOS Q2 for the first time through Maven / Intellij, and coming across an error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/osgi/framework/BundleException
at Q2_Main.main(Q2_Main.java:6)
Caused by: java.lang.ClassNotFoundException: org.osgi.framework.BundleException
    at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
    ... 1 more

Process finished with exit code 1

I downloaded JPOS through maven, and I've tried looking at dozens of threads on the error but cannot resolve it on my own

    <?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>Q2_JPOS_TEST</artifactId>
    <version>1.0-SNAPSHOT</version>

<properties>
    <maven.compiler.source>8</maven.compiler.source>
    <maven.compiler.target>8</maven.compiler.target>
</properties>

<dependencies>
    <dependency>
        <groupId>org.jpos</groupId>
        <artifactId>jpos</artifactId>
        <version>2.1.6</version>
    </dependency>
</dependencies>
</project>

and I see it in my external libraries

jpos in external library

import org.jpos.q2.Q2;

public class Q2_Main {

public static void main(String[] args){
    Q2 q2 = new Q2("src/main/java/deploy");
    q2.start();
}

}

Edit for steps that I did:

  1. File -> New Project -> Maven Project (created the POM automatically)
  2. Pasted the JPOS dependency from my main project into new POM file
  3. Maven Clean + Install from within Intellij Maven Panel
  4. Created Q2_Main.java
  5. Hit green play button, which results in that error

Edit 2:

[INFO] Scanning for projects...
[INFO]
[INFO] ----------------------< org.example:Q2_JPOS_TEST >------------ 

[INFO] Building Q2_JPOS_TEST 1.0-SNAPSHOT
[INFO] --------------------------------[ jar ]----------------------- 

[INFO]
[INFO] --- maven-dependency-plugin:2.8:tree (default-cli) @ 
Q2_JPOS_TEST ---
[INFO] org.example:Q2_JPOS_TEST:jar:1.0-SNAPSHOT
[INFO] \- org.jpos:jpos:jar:2.1.6:compile
[INFO]    +- commons-cli:commons-cli:jar:1.4:compile
[INFO]    +- org.apache-extras.beanshell:bsh:jar:2.0b6:compile
[INFO]    +- org.bouncycastle:bcprov-jdk15on:jar:1.67:compile
[INFO]    +- org.bouncycastle:bcpg-jdk15on:jar:1.67:compile
[INFO]    +- org.hdrhistogram:HdrHistogram:jar:2.1.12:compile
[INFO]    +- org.javatuples:javatuples:jar:1.2:compile
[INFO]    +- org.jdom:jdom2:jar:2.0.6:compile
[INFO]    +- org.jline:jline:jar:3.19.0:compile
[INFO]    \- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] --------------------------------------------------------------    
[INFO] BUILD SUCCESS
[INFO] --------------------------------------------------------------    
[INFO] Total time:  2.205 s
[INFO] Finished at: 2023-02-17T15:43:38-07:00
[INFO] -------------------------------------------------------------- 

<?xml version="1.0" encoding="UTF-8"?>
<settings xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.1.0 
http://maven.apache.org/xsd/settings-1.1.0.xsd" 
xmlns="http://maven.apache.org/SETTINGS/1.1.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<servers>
    <server>
        <username>user</username>
        <password>password</password>
        <id>artifactory</id>
    </server>
</servers>
<mirrors>
    <mirror>
        <id>artifactory</id>
        <url>https://artifactory.company.com:443/central</url>
        <mirrorOf>*</mirrorOf>
    </mirror>
</mirrors>
<profiles>
<profile>
  <id>artifactory</id>
  <!--Override the repository (and pluginRepository) "central" from the     
Maven Super POM
      to activate snapshots for both! -->
  <repositories>
    <repository>
      <id>central</id>
      <url>http://central</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </repository>
  </repositories>
  <pluginRepositories>
    <pluginRepository>
      <id>central</id>
      <url>http://central</url>
      <releases>
        <enabled>true</enabled>
      </releases>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
    </pluginRepository>
  </pluginRepositories>

</profile>
</profiles>

<activeProfiles>
<!--make the profile active all the time -->
<activeProfile>artifactory</activeProfile>
</activeProfiles>
</settings>

Solution

  • Here is a step by step of what I did to tun your code:

    1. Create an empty folder /tmp/test-jpos
    2. Write the file pom.xml there with the content you shared.
    3. In IntelliJ menu File -> Open and opened the /tmp/test-jpos folder
    4. Create dir src/main/java
    5. Create file Q2_Main.java in that directory with content you shared.
    6. Run the project by hitting the play run button (the green triangle)

    With those steps it ran OK.

    However that is not the recommended way to run Q2 I will expand on this later.