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
Community showcase
Posted Sep 18, 2018 in Jira

What modern development practices are at the heart of how your team delivers software?

Hey Community mates! Claire here from the Software Product Marketing team. We all know software development changes rapidly, and it's often tough to keep up. But from our research, we've found the h...

24,260 views 2 7
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