java - MBeans 构造函数与 gradle 依赖项错误

标签 java gradle jpos

我有一个 java 项目,它使用我生成的外部自定义 jar,我已将 jar 导入到我的 build.gradle 中:

repositories {
    mavenCentral()
    flatDir { dirs './src/dist/lib' } }

dependencies {
    implementation name: 'PaymentServer-Lite'
    compile group: 'org.jpos', name:'jpos', version:'1.9.2'
    compile group: 'org.jpos.ee',   name: 'jposee-server-simulator',    version: '2.0.2-SNAPSHOT'
    compile ('org.jpos:jpos:2.1.2') {
        exclude(module: 'junit')
        exclude(module: 'hamcrest-core')
    }
    testCompile 'junit:junit:4.8.2' }

我的类从我的 jar 中导入了另一个名为 Loader 的类,它看起来像这样:

import com.recharge.mongo.Loader.Loader;

public class PaymentQ2 extends org.jpos.q2.iso.QServer {
    Loader loader;

    public PaymentQ2(){
        loader = Loader.getInstance();
    }
}

我的问题是,当我使用 run gradle 运行我的应用程序时,我收到以下错误:

 <exception name="Error thrown in the MBean's constructor">
    javax.management.RuntimeErrorException: Error thrown in the MBean's constructor
        at com.sun.jmx.mbeanserver.MBeanInstantiator.instantiate(MBeanInstantiator.java:330)
        at com.sun.jmx.mbeanserver.MBeanInstantiator.instantiate(MBeanInstantiator.java:620)
        at com.sun.jmx.mbeanserver.MBeanInstantiator.instantiate(MBeanInstantiator.java:527)
        at com.sun.jmx.mbeanserver.JmxMBeanServer.instantiate(JmxMBeanServer.java:990)
        at org.jpos.q2.QFactory.instantiate(QFactory.java:78)
        at org.jpos.q2.Q2.deploy(Q2.java:578)
        at org.jpos.q2.Q2.deploy(Q2.java:391)
        at org.jpos.q2.Q2.run(Q2.java:259)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.NoClassDefFoundError: com/recharge/mongo/Loader/Loader

我不知道这是我的依赖项的问题还是我的jar引起的问题

最佳答案

问题是您将依赖项定义为实现,这意味着运行 jar 的平台已经包含其实现。

在这种情况下,您正在使用 q2 运行程序,而该程序本身的路径中没有该 jar。如果你想用q2运行程序,你需要将依赖声明为compile

dependencies {
        compile name: 'PaymentServer-Lite'
        ....
}

来源:https://stackoverflow.com/a/44493379/3444205

关于java - MBeans 构造函数与 gradle 依赖项错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58069582/

相关文章:

java - 如何在 Eclipse 中为 Java 版本 6 制作 spring starter 项目(spring boot)?

java - 使用 Spring Boot 启动 tomcat 时出现 NotReadablePropertyException

ionic-framework - Gradle的Android运行错误

使用 MySQL 和 Qtjambi 的 Java 客户端-服务器应用程序 : which licence?

java - 如何用可选的替换获取阶梯?

androiddeployqt : Qt hook gradle android

android - 一个库在导入 Facebook SDK 后使用与本项目相同的包

java - JPos申请错误

iso8583 - 将 ISOMsg 发送到 ISOServer

java - Linux WAR 文件部署错误