0

I have a java project that uses an external custom jar generated by me, I've imported my jar in my build.gradle as:

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

My class imported another class from my jar called Loader and it looks something like this:

import com.recharge.mongo.Loader.Loader;

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

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

My problem is that when I run my app, with run gradle I receive the following error:

 <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

I don't know if this is a problem of my dependencies or is a problem caused by my jar

Ophy
  • 81
  • 1
  • 12
  • As this is a JPos project I'm running the Q2 script with **run gradle** or with ./q2 – Ophy Sep 23 '19 at 20:27

1 Answers1

2

Problem is that you are defining the dependency as implementation which means that the platform running the jar already contains its implementation.

In this case you are running the program with q2 that does not have that jar in its path by itself. You need to declare the dependency as compile if you want to run the program with q2

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

source: https://stackoverflow.com/a/44493379/3444205

Andrés Alcarraz
  • 1,570
  • 1
  • 12
  • 21
  • Hey, I'm defining my jar with **implementation name: 'PaymentServer-Lite'** – Ophy Sep 24 '19 at 11:17
  • Hi, this solution is independent of the name of the jar, don't quite understand your clarification – Andrés Alcarraz Sep 24 '19 at 15:04
  • if you add this dependency it doesn't solve your problem? – Andrés Alcarraz Sep 24 '19 at 23:21
  • Andrés it doesn't, in my latest comment the name it doesn't matter either, I was trying to say that I'm defining my dependency with *implementation* – Ophy Sep 25 '19 at 18:36
  • 1
    well then that's the problem, defining the dependency as implementation, the build system is not copying the jars to the install directory, implementation means that the platform running the jar already has that jar in place, which jpos doesn't. Bottomline you need to declare the dependency as compile if you want to run it through q2 script – Andrés Alcarraz Sep 25 '19 at 19:43
  • I edited my answer, now that we identified the problem, it's not clear in the question that your custom jar is PaymentServer-Lite – Andrés Alcarraz Sep 25 '19 at 19:59