NoClassDefFoundError: javax/ws/rs/client/ClientBuilder
13,930
is there a specific reason you have been using
<version>2.1-m01</version>
It is usually recommended to use Final Builds which are stable. Try using this version.
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1</version>
</dependency>
If you want to use the -m01
Version, You can Maven clean
and Maven install
. This error can also come up, if the respective jar file is not downloaded properly.
also make sure you are importing the right Class.
import javax.ws.rs.client.ClientBuilder;
Hope this helps!
Author by
cristina paniagua
Updated on June 27, 2022Comments
-
cristina paniagua almost 2 years
I'm trying to creat a very simple Rest Client. I,m using: Netbeans 8 maven project
dependecies:
<dependencies> <dependency> <groupId>javax.ws.rs</groupId> <artifactId>javax.ws.rs-api</artifactId> <version>2.1-m01</version> </dependency> <dependency> <groupId>org.glassfish.jersey.core</groupId> <artifactId>jersey-client</artifactId> <version>2.24.1</version> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-client</artifactId> <version>3.0.16.Final</version> </dependency> </dependencies>
and the code:
public class Client_con { public static final String BASE_URI = "http://localhost:8000/test"; public static final String PATH_NAME = "/h"; public static void main (String [] args){ Client client = ClientBuilder.newClient(); //WS text get WebTarget target = client.target(BASE_URI).path(PATH_NAME); String res = target.request().get().readEntity(String.class); System.out.println(res); } }
But I always obtain the same error:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/ws/rs/client/ClientBuilder at ah.consumer.Client_con.main(Client_con.java:38) Caused by: java.lang.ClassNotFoundException: javax.ws.rs.client.ClientBuilder at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more
I don't know what I can do...
-
Kaustubh Kallianpur over 6 yearsis that the full stack trace of the Exception?? did u try Maven clean and Maven install after changing the version
-
Kaustubh Kallianpur over 6 yearsyou can manually check if the jar file is available in the Maven local repository. To check that, go to C:\Users\<Username>\.m2\repository\... check if the jar file is available in the Respective folder.
-
Kaustubh Kallianpur over 6 yearsalso this answer should provide some help to you?
-
cristina paniagua over 6 yearsI get the solution, I had this plugin block in some way the path: <plugin> <!-- Build an executable JAR --> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>3.0.2</version> <configuration> <archive> <manifest> <addClasspath>true</addClasspath> <mainClass>ah.client.Main</mainClass> </manifest> </archive> </configuration> </plugin>