java.lang.NoClassDefFoundError: com/google/gson/GsonBuilder

Jane Guo October 13, 2015

I am developing a rest plugin with sdk5.1.2. It throws a runtime error: java.lang.NoClassDefFoundError: com/google/gson/GsonBuilder when calling Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();

It compiles fine import com.google.gson.Gson; import com.google.gson.GsonBuilder;

added the dependency in pom.xml <dependency>             <groupId>com.google.code.gson</groupId>             <artifactId>gson</artifactId>             <version>2.2.2-atlassian-1</version>         </dependency>

I also tried with versin gson-2.4, it failed too.

version -JIRA v6.4.8

It works in java stand alone code.

But it is in a get service function and deploy to the server. it would throw the runtime error.

 

@GET

  @AnonymousAllowed   

@Path("/service")   

//@Consumes({MediaType.APPLICATION_JSON})   

@Produces({MediaType.APPLICATION_JSON  })   

public  Response getRequestList( ) throws  Exception {

    String json ="Hello";

    String output ="";

   

Gson gson = new GsonBuilder().disableHtmlEscaping().setPrettyPrinting().create();

       

try 

           

            HashMap<String, JIRAField> map =

new  HashMap<String, JIRAField>();

           

 

            Client client = Client.create();     

           client.addFilter(new  HTTPBasicAuthFilter("test1", "pswd"));

           

           String url ="http://xyz:8180/rest/api/2/field?projectKeys=SR";

           

          

logger .log(Level.INFO , "info1 " + url);

           

//get client         

          

         

//WebResource webResource = client.resource("http://www.google.com");

            WebResource webResource = client.resource(url);     

           

            webResource.setProperty("User-Agent", "Mozilla/5.0");

          

 

          

logger .log(Level.INFO , "info2 " + output);

            ClientResponse response = webResource.type("application/json").get(ClientResponse.class );

      

           

if  (response.getStatus() != 200) {

              

throw  new  RuntimeException("Failed : HTTP error code : "

               + response.getStatus());}           

         

           

          output = response.getEntity(String.class );

 

 

Thanks for the help!

           

1 answer

1 vote
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 13, 2015

Try to run atlas-clean in your plugin folder.

For future please use the code block for pasting code snippets.

Suggest an answer

Log in or Sign up to answer