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

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

This widget could not be displayed.

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
Atlassian Summit 2018

Meet the community IRL

Atlassian Summit is an excellent opportunity for in-person support, training, and networking.

Learn more
Community showcase
Posted Wednesday in New to Jira

Are you planning to trial, or are currently trialling Jira Software? - We want to talk to you!

Hello! I'm Rayen, a product manager at Atlassian. My team and I are working hard to improve the trial experience for Jira Software Cloud. We are interested in   talking to 20 people planning t...

232 views 3 0
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you