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

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
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published Thursday in Jira

Meet the AUG leaders of Northern Virginia

@Rachel Wright (Jira Genie), @Billy Poggi (AUG NOVA, DC), and @Dana Jansen (Confluence Queen) are just some of the folks that lead one of the world's most active Atlassian User Group (AUG)....

121 views 4 9
Read article

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