0

I'm currently in the process of adding the Jasper API to our project, and I've made a JUnit-test to test the connection. Our Maven project architecture is one parent project, with a few inner projects.

I've added the dependencies I need for jasper to the parent pom:

<dependencyManagement>
  <dependencies>
    ...

    <dependency>
      <groupId>com.jaspersoft.jasperserver</groupId>
      <artifactId>jasperserver-common-ws</artifactId>
      <version>5.5.0</version>
    </dependency>
    <dependency>
      <groupId>com.jaspersoft.jasperserver</groupId>
      <artifactId>jasperserver-ireport-plugin</artifactId>
      <version>3.0.0</version>
    </dependency>
  </dependencies>
</dependencyManagement>

And I've added it to the inner project that requires the jasper dependencies for its unit test:

<dependencies>
  ...

  <dependency>
    <groupId>com.jaspersoft.jasperserver</groupId>
    <artifactId>jasperserver-common-ws</artifactId>
  </dependency>
  <dependency>
    <groupId>com.jaspersoft.jasperserver</groupId>
    <artifactId>jasperserver-ireport-plugin</artifactId>
  </dependency>
</dependencies>

After I've done a Maven Update; Maven clean install; and Project built & refresh, I try to execute the UnitTest:

package jasper;

import org.junit.Assert;
import org.junit.Test;
import com.jaspersoft.jasperserver.api.metadata.xml.domain.impl.ResourceDescriptor;
import com.jaspersoft.jasperserver.irplugin.JServer;
import junit.framework.TestCase;

public class JasperApiTest extends TestCase{

  private JServer jasperServer;

  public ResourceDescriptor get(String uri) throws Exception{
    ResourceDescriptor rd = new ResourceDescriptor();
    rd.setUriString(uri);
    return this.jasperServer.getWSClient().get(rd, null, null);
  }

  @Override
  protected void setUp(){
    this.jasperServer = new JServer();
    this.jasperServer.setName("__ourName__");
    this.jasperServer.setPassword("__ourPassword__");
    this.jasperServer.setUrl("__ourServer__/jasperserver-pro/services/repository");
  }

  @Test
  public void testJasperApi(){
    try{
      ResourceDescriptor rd = get("/test");
      Assert.assertNotNull(rd);
    } catch(Exception ex){
      Assert.fail("Failed: " + ex);
    }
  }
}

Now the problem is that it gives a java.lang.ClassNotFoundException. Initially for the org.apache.axis.EngineConfiguration. When I explicitly add this to the pom it goes to the next ClassNotFoundException, but this time for org.apache.commons.logging.LogFactory. And if I add this one as well, it continues with the next inner dependency.
Since I don't use these dependencies myself, only Jasper is, I don't need to add them, but just let Maven add them for me automatically. So, I've read about Transitive_Dependencies, which is just what I need, but this link didn't really gave an example of how to configure this.
I've also tried the following small 'tutorial', but the inner dependencies aren't added..

How can I add all the inner dependency jars through Maven without adding them all manually to the pom? I thought this was done automatically when the scope is compile (which is the default, although I've also tried setting it explicitly just in case - without any difference).


EDIT: When I build the project with the mvn dependency:tree goal, it shows the following two lines for the Jasper jars:

[INFO] |  +- com.jaspersoft.jasperserver:jasperserver-common-ws:jar:5.5.0:compile
[INFO] |  \- com.jaspersoft.jasperserver:jasperserver-ireport-plugin:jar:3.0.0:compile

But no inner dependencies, which is why they aren't being added.

But, when I debug the UnitTest it goes to the .getWSClient() line, and the actual error occurs in junit.framework.TestCase#runTest(), with the following Stacktrace:

java.lang.NoClassDefFoundError: org/apache/axis/EngineConfiguration
    at com.jaspersoft.jasperserver.irplugin.JServer.getWSClient(JServer.java:102)
    at jasper.JasperApiTest.get(JasperApiTest.java:20)
    at jasper.JasperApiTest.testJasperApi(JasperApiTest.java:34)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at junit.framework.TestCase.runTest(TestCase.java:176)
    at junit.framework.TestCase.runBare(TestCase.java:141)
    at junit.framework.TestResult$1.protect(TestResult.java:122)
    at junit.framework.TestResult.runProtected(TestResult.java:142)
    at junit.framework.TestResult.run(TestResult.java:125)
    at junit.framework.TestCase.run(TestCase.java:129)
    at junit.framework.TestSuite.runTest(TestSuite.java:252)
    at junit.framework.TestSuite.run(TestSuite.java:247)
    at org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:86)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: org.apache.axis.EngineConfiguration
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 22 more

Is this some kind of UnitTest (TestCase-class) reflection problem which causes the ClassNotFoundException. So the classes it gives these errors aren't inner dependencies of the two Jasper API jars, so I am forced to add them all manually even though I don't use them directly in my own code? Or can I still use transitivity somehow?

Kevin Cruijssen
  • 9,153
  • 9
  • 61
  • 135
  • do you have the artifact in your local repository or where are they comming from? – Hisham Khalil Nov 16 '16 at 12:13
  • @Hishamkh All our jars are placed in Nexus. During a Maven update we get them from Nexus, and they are placed in our local .m2 folder. The project's Maven dependencies reference to that file-path in the .m2 folder. As for this Jasper API, we use it in other projects as well, and I just checked, the Jasper API itself, as well as the first two jars that were given as `ClassNotFoundException` are all three present in Nexus. (The other projects are too big, and I have too little expertise, to find how transitivity is used in those projects - if at all. So I can't really use them as example.) – Kevin Cruijssen Nov 16 '16 at 12:19
  • try to use [mvn dependency:tree] to display all deps and transitive deps of your project or shrink the result by adding [-Dincludes=*jasper*] to the command – Hisham Khalil Nov 16 '16 at 12:33
  • @Hishamkh Hmm, weird. It only displays the `[INFO] | +- com.jaspersoft.jasperserver:jasperserver-common-ws:jar:5.5.0:compile [INFO] | \- com.jaspersoft.jasperserver:jasperserver-ireport-plugin:jar:3.0.0:compile`, but no inner dependencies.. I'll add some more details to the question (including the stacktrace), since this comment box is too small. It's weird it requires classes in the UnitTest (causing `ClassNotFoundExceptions`), but they aren't inner classes of the Jasper API. – Kevin Cruijssen Nov 16 '16 at 13:07
  • unpack one of them and see if it include any pom file – Hisham Khalil Nov 16 '16 at 13:33
  • @Hishamkh Both contain a pom. I don't see the `org.apache.axis.` or the other jars as dependency directly, but they do have dependencies. I could copy both poms to the question if it helps. To answer your question: Yes, they both contain a pom file. – Kevin Cruijssen Nov 16 '16 at 13:52
  • These libraries are not in maven central, or any other public repo afaik, and from what you've said above about the poms, I'd say that these aren't maven compatible libraries, which, in my mind, as a very senior engineer, makes them unprofessional and unfit for purpose. – Software Engineer Nov 16 '16 at 14:22

0 Answers0