英文:
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">
<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
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:
- File -> New Project -> Maven Project (created the POM automatically)
- Pasted the JPOS dependency from my main project into new POM file
- Maven Clean + Install from within Intellij Maven Panel
- Created Q2_Main.java
- 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] --------------------------------------------------------------
"
英文:
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
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:
- File -> New Project -> Maven Project (created the POM automatically)
- Pasted the JPOS dependency from my main project into new POM file
- Maven Clean + Install from within Intellij Maven Panel
- Created Q2_Main.java
- 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>
答案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
以下是我执行您的代码的逐步说明:
- 创建一个空文件夹
/tmp/test-jpos
。 - 在该文件夹中创建一个名为
pom.xml
的文件,内容与您分享的相同。 - 在IntelliJ菜单中选择 File -> Open 并打开
/tmp/test-jpos
文件夹。 - 创建一个名为
src/main/java
的目录。 - 在该目录中创建一个名为
Q2_Main.java
的文件,内容与您分享的相同。 - 通过点击运行按钮(绿色三角形)运行项目。
按照这些步骤,项目应该可以正常运行。
然而,这并不是运行 Q2
的推荐方式,我稍后会详细说明。
英文:
Here is a step by step of what I did to tun your code:
- Create an empty folder
/tmp/test-jpos
- Write the file
pom.xml
there with the content you shared. - In IntelliJ menu File -> Open and opened the
/tmp/test-jpos
folder - Create dir
src/main/java
- Create file
Q2_Main.java
in that directory with content you shared. - 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的安装相关。
要确定这是否可能是问题,可以执行以下步骤。
- 首先,尝试移动本地安装中的任何可能的Maven设置。重命名用户级别的
settings.xml
(在Linux中是~/.m2/settings.xml
),如果可能的话,如果您或其他人修改了全局级别的settings.xml
,尝试获取发行版的默认设置。 - 如果在执行步骤1后依赖项正确加载,那么问题可能出在设置上,您可以逐项应用您需要的设置,检查每一步是否正确解析了依赖项。
- 如果步骤1没有奏效,问题可能与Maven缓存有关。重命名整个
.m2
目录,然后重试。 - 如同步骤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.
- 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 levelsettings.xml
try to get the distribution default. - 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.
- If step 1 didn't work, the problem may somehow be in the maven cache. Rename the entire
.m2
directory, and retry. - As in step 2, try to get back your setting from the old
settings.xml
and see if it breaks again.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论