1

I'm trying to use Jersey Test Framework and I'm not happy with it.

java.lang.RuntimeException: java.lang.ClassNotFoundException
        at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:46)
        at javax.ws.rs.client.ClientBuilder.newClient(ClientBuilder.java:57)
        at org.glassfish.jersey.test.JerseyTest.getClient(JerseyTest.java:691)
        at org.glassfish.jersey.test.JerseyTest.setUp(JerseyTest.java:614)
        at org.glassfish.jersey.test.JerseyTestNg$ContainerPerClassTest.setUp(JerseyTestNg.java:181)
        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 org.testng.internal.MethodInvocationHelper.invokeMethod(MethodInvocationHelper.java:108)
        at org.testng.internal.Invoker.invokeConfigurationMethod(Invoker.java:523)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:224)
        at org.testng.internal.Invoker.invokeConfigurations(Invoker.java:146)
        at org.testng.internal.TestMethodWorker.invokeBeforeClassMethods(TestMethodWorker.java:166)
        at org.testng.internal.TestMethodWorker.run(TestMethodWorker.java:105)
        at org.testng.TestRunner.privateRun(TestRunner.java:744)
        at org.testng.TestRunner.run(TestRunner.java:602)
        at org.testng.SuiteRunner.runTest(SuiteRunner.java:380)
        at org.testng.SuiteRunner.runSequentially(SuiteRunner.java:375)
        at org.testng.SuiteRunner.privateRun(SuiteRunner.java:340)
        at org.testng.SuiteRunner.run(SuiteRunner.java:289)
        at org.testng.SuiteRunnerWorker.runSuite(SuiteRunnerWorker.java:52)
        at org.testng.SuiteRunnerWorker.run(SuiteRunnerWorker.java:86)
        at org.testng.TestNG.runSuitesSequentially(TestNG.java:1301)
        at org.testng.TestNG.runSuitesLocally(TestNG.java:1226)
        at org.testng.TestNG.runSuites(TestNG.java:1144)
        at org.testng.TestNG.run(TestNG.java:1115)
        at org.apache.maven.surefire.testng.TestNGExecutor.run(TestNGExecutor.java:135)
        at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.executeMulti(TestNGDirectoryTestSuite.java:193)
        at org.apache.maven.surefire.testng.TestNGDirectoryTestSuite.execute(TestNGDirectoryTestSuite.java:94)
        at org.apache.maven.surefire.testng.TestNGProvider.invoke(TestNGProvider.java:146)
        at org.apache.maven.surefire.booter.ForkedBooter.invokeProviderInSameClassLoader(ForkedBooter.java:386)
        at org.apache.maven.surefire.booter.ForkedBooter.runSuitesInProcess(ForkedBooter.java:323)
        at org.apache.maven.surefire.booter.ForkedBooter.main(ForkedBooter.java:143)
Caused by: java.lang.ClassNotFoundException
        at javax.ws.rs.client.ClientFinder.newInstance(ClientFinder.java:116)
        at javax.ws.rs.client.ClientFinder.find(ClientFinder.java:92)
        at javax.ws.rs.client.ClientBuilder.newBuilder(ClientBuilder.java:40)
        ... 33 more
Caused by: java.lang.InstantiationException
        at sun.reflect.InstantiationExceptionConstructorAccessorImpl.newInstance(InstantiationExceptionConstructorAccessorImpl.java:48)
        at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
        at java.lang.Class.newInstance(Class.java:442)
        at javax.ws.rs.client.ClientFinder.newInstance(ClientFinder.java:112)
        ... 35 more

[INFO]
[INFO] Results:
[INFO]
[ERROR] Failures:
[ERROR]   ProductsResourceTest>JerseyTestNg$ContainerPerClassTest.setUp:181->JerseyTest.setUp:614->JerseyTest.getClient:691 ? Runtime
[INFO]
[ERROR] Tests run: 3, Failures: 1, Errors: 0, Skipped: 2
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.603 s
[INFO] Finished at: 2017-05-06T17:24:35+09:00
[INFO] Final Memory: 18M/279M
[INFO] ------------------------------------------------------------------------

Where the javax.ws.rs.client.ClientFinter came from?

Here come my dependencies. (from :effective-pom)

  <dependencies>
    <dependency>
      <groupId>org.apache.tomee</groupId>
      <artifactId>openejb-core</artifactId>
      <version>7.0.3</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.core</groupId>
      <artifactId>jersey-client</artifactId>
      <version>2.26-b03</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>org.glassfish.jersey.test-framework.providers</groupId>
      <artifactId>jersey-test-framework-provider-jdk-http</artifactId>
      <version>2.26-b03</version>
      <scope>test</scope>
    </dependency>
    <dependency>
      <groupId>javax</groupId>
      <artifactId>javaee-api</artifactId>
      <version>7.0</version>
      <scope>provided</scope>
    </dependency>
  </dependencies>
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
  • You can search for it http://stackoverflow.com/questions/1500141/find-a-jar-file-given-the-class-name – Idos May 06 '17 at 09:24
  • 1
    I wonder if it has to do with using javaee-api. It might use the first version of the JAX-RS 2.0 spec, where as Jersey uses the next update version JAX-RS [2.0.1](https://mvnrepository.com/artifact/javax.ws.rs/javax.ws.rs-api/2.0.1). Might be something different in those two versions that is causing the problem – Paul Samsotha May 06 '17 at 09:46
  • @peeskillet Good to see you again. Man, I'm really wondering where the `javax.ws.rs.client.ClientFinder` came from. – Jin Kwon May 06 '17 at 12:13
  • Looking at the pom for Jersey 2.26-b03, they are [using JAX-RS 2.1-m05](https://github.com/jersey/jersey/blob/2.26-b03/pom.xml#L1884). I don't know what that API looks like, but maybe that's where it's from – Paul Samsotha May 06 '17 at 12:21
  • [Here's the spec to download](http://download.oracle.com/otndocs/jcp/jaxrs-2_1-pr-spec/index.html) – Paul Samsotha May 06 '17 at 12:26
  • 1
    I think that's what it is, 2.1.0. If you look at [2.0.1](http://grepcode.com/file/repo1.maven.org/maven2/javax.ws.rs/javax.ws.rs-api/2.0.1/javax/ws/rs/client/ClientBuilder.java#84), they use some class `FactoryFinder` to find the client. They probably changed that in 2.1.0 to `ClientFinder` – Paul Samsotha May 06 '17 at 12:30

0 Answers0