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

1 vote
Volodymyr Krupach Community Champion Oct 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 Join to answer
Community showcase
Sarah Schuster
Posted Jan 29, 2018 in Jira

What are common themes you've seen across successful & failed Jira Software implementations?

Hey everyone! My name is Sarah Schuster, and I'm a Customer Success Manager in Atlassian specializing in Jira Software Cloud. Over the next few weeks I will be posting discussion topics (8 total) to ...

3,321 views 14 20
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
Atlassian Team Tour

Join us on the Team Tour

We're bringing product updates and pro tips on teamwork to ten cities around the world.

Save your spot