NoClassDefFoundError 在运行 JPOS Q2 时出现?

huangapple go评论50阅读模式
英文:

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

<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">
4.0.0

<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>

and I see it in my external libraries

jpos in external library

import org.jpos.q2.Q2;

public class Q2_Main {

public static 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] --------------------------------------------------------------




user password artifactory




artifactory
https://artifactory.company.com:443/central
*

artifactory




central
http://central

true


true


central
http://central

true


true


artifactory

"

英文:

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

Exception in thread &quot;main&quot; 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

    &lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;project xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
         xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
         xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 

http://maven.apache.org/xsd/maven-4.0.0.xsd">
	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;

	&lt;groupId&gt;org.example&lt;/groupId&gt;
	&lt;artifactId&gt;Q2_JPOS_TEST&lt;/artifactId&gt;
	&lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;

&lt;properties&gt;
	&lt;maven.compiler.source&gt;8&lt;/maven.compiler.source&gt;
	&lt;maven.compiler.target&gt;8&lt;/maven.compiler.target&gt;
&lt;/properties&gt;

&lt;dependencies&gt;
	&lt;dependency&gt;
		&lt;groupId&gt;org.jpos&lt;/groupId&gt;
		&lt;artifactId&gt;jpos&lt;/artifactId&gt;
		&lt;version&gt;2.1.6&lt;/version&gt;
	&lt;/dependency&gt;
&lt;/dependencies&gt;
&lt;/project&gt;

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(&quot;src/main/java/deploy&quot;);
    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] ----------------------&lt; org.example:Q2_JPOS_TEST &gt;------------ 

[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] -------------------------------------------------------------- 

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

&lt;/profile&gt;
&lt;/profiles&gt;

&lt;activeProfiles&gt;
&lt;!--make the profile active all the time --&gt;
&lt;activeProfile&gt;artifactory&lt;/activeProfile&gt;
&lt;/activeProfiles&gt;
&lt;/settings&gt;

答案1

得分: 0

我在Maven仓库中查看了您试图使用的库,jpos 2.1.6(https://mvnrepository.com/artifact/org.jpos/jpos/2.1.6),我注意到它有一系列的运行时依赖项。根据您发布的堆栈跟踪,似乎您缺少org.osgi.core 6.0.0。请确保您的类路径中包含所有所需的运行时依赖项。

英文:

I checked on the maven repository the library you are trying to use, jpos 2.1.6 (https://mvnrepository.com/artifact/org.jpos/jpos/2.1.6), and I've seen it has a series of runtime dependencies. It seems you miss org.osgi.core 6.0.0 judging from the stacktrace you posted. Make sure you have all the runtime dependencies needed in your classpath.

答案2

得分: 0

以下是我执行您的代码的逐步说明:

  1. 创建一个空文件夹 /tmp/test-jpos
  2. 在该文件夹中创建一个名为 pom.xml 的文件,内容与您分享的相同。
  3. 在IntelliJ菜单中选择 File -> Open 并打开 /tmp/test-jpos 文件夹。
  4. 创建一个名为 src/main/java 的目录。
  5. 在该目录中创建一个名为 Q2_Main.java 的文件,内容与您分享的相同。
  6. 通过点击运行按钮(绿色三角形)运行项目。

按照这些步骤,项目应该可以正常运行。

然而,这并不是运行 Q2 的推荐方式,我稍后会详细说明。

英文:

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.

答案3

得分: 0

基于上一个评论,问题似乎与Maven的安装相关。

要确定这是否可能是问题,可以执行以下步骤。

  1. 首先,尝试移动本地安装中的任何可能的Maven设置。重命名用户级别的settings.xml(在Linux中是~/.m2/settings.xml),如果可能的话,如果您或其他人修改了全局级别的settings.xml,尝试获取发行版的默认设置。
  2. 如果在执行步骤1后依赖项正确加载,那么问题可能出在设置上,您可以逐项应用您需要的设置,检查每一步是否正确解析了依赖项。
  3. 如果步骤1没有奏效,问题可能与Maven缓存有关。重命名整个.m2目录,然后重试。
  4. 如同步骤2,尝试从旧的settings.xml中恢复您的设置,看看是否再次出现问题。
英文:

Based on the last comment, the problem seems to be related to its maven installation.

To figure out if this could be an issue, one can perform the following steps.

  1. First, try to move any possible maven setting in your local installation. Rename the user level settings.xml (in linux ~/.m2/settings.xml) and if it's possible that you or someone modified the installation level settings.xml try to get the distribution default.
  2. If after this the dependencies are correctly brought, then the problem is with that settings, you can try to apply the settings you need, item by item and check in every step, that the dependencies are resolved ok.
  3. If step 1 didn't work, the problem may somehow be in the maven cache. Rename the entire .m2 directory, and retry.
  4. As in step 2, try to get back your setting from the old settings.xml and see if it breaks again.

huangapple
  • 本文由 发表于 2023年2月14日 07:18:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/75442074.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定