10 Replies Latest reply on Jun 8, 2016 11:10 PM by Nicolas Savy

    REST API Sample - Compile errors

    Adam Ratkewicz

      Good day,

       

      I'm new to Tableau and am trying to use the REST API Java Sample. However, after verifying ANT installation and JDK, I'm getting errors while compiling the code. Getting a lot of 'does not exist errors'. Would you be able to point me in the right direction please? Seems like I'm missing some basic dependencies.


       

      Believe I have JAVA_HOME and ANT_HOME variables correct. A few differences with the README file include, running updated versions of the JDK (8.65) and the required libraries (see attached picture). Trying to run the example in a windows 7 64 bit environment.

      REST_API_lib.PNG

       

      C:\Adam's Files\Tableau\

       

      rest-api-java-sample>ant

      Buildfile: C:\Adam's Files\Tableau\rest-api-java-sample\build.xml

       

      clean:

         [delete] Deleting directory C:\Adam's Files\Tableau\rest-api-java-sample\build

       

      compile:

          [mkdir] Created dir: C:\Adam's Files\Tableau\rest-api-java-sample\build\classes

          [javac] Compiling 27 source files to C:\Adam's Files\Tableau\rest-api-java-sample\build\classes

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:13: error: package javax.ws.rs.core does not exist

          [javac] import javax.ws.rs.core.MediaType;

          [javac]                        ^

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:14: error: package javax.ws.rs.core.Response does not exist

          [javac] import javax.ws.rs.core.Response.Status;

          [javac]                                 ^

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:15: error: package javax.ws.rs.core does not exist

          [javac] import javax.ws.rs.core.UriBuilder;

          [javac]                        ^

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:29: error: package com.sun.jersey.api.client does not exist

          [javac] import com.sun.jersey.api.client.Client;

          [javac]                                 ^

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:30: error: package com.sun.jersey.api.client does not exist

          [javac] import com.sun.jersey.api.client.ClientResponse;

          [javac]                                 ^

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:31: error: package com.sun.jersey.api.client does not exist

          [javac] import com.sun.jersey.api.client.WebResource;

          [javac]                                 ^

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:112: error: cannot find symbol

          [javac]     private static UriBuilder getApiUriBuilder() {

          [javac]                    ^

          [javac]   symbol:   class UriBuilder

          [javac]   location: class RestApiUtils

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:71: error: cannot find symbol

          [javac]         private final UriBuilder m_builder;

          [javac]                       ^

          [javac]   symbol:   class UriBuilder

          [javac]   location: class Operation

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:73: error: cannot find symbol

          [javac]         Operation(UriBuilder builder) {

          [javac]                   ^

          [javac]   symbol:   class UriBuilder

          [javac]   location: class Operation

          [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:77: error: cannot find symbol

          [javac]         UriBuilder getUriBuilder() {

          [javac]         ^

          [javac]   symbol:   class UriBuilder

          [javac]   location: class Operation

          [javac] 10 errors

       

      BUILD FAILED

      C:\Adam's Files\Tableau\rest-api-java-sample\build.xml:27: Compile failed; see the compiler error output for details.

       

      Total time: 2 seconds


      Would love some thoughts please.

        • 1. Re: REST API Sample - Compile errors

          Hey Adam,

           

          A few thoughts:

           

          1. Does the issue occur when installing on all drives?

          2. Do you have admin privilege on that account?

          • 2. Re: REST API Sample - Compile errors
            Adam Ratkewicz

            Hi Diego - Thank you for your reply. I've only tried on my laptop (running windows 7). Yes, this account has admin privileges. It seems to fail when compiling because it doesn't find the packages in the expected place. Would really like to troubleshoot this with anyone here or support. It started out as a fun exercise, but now we can see the business value that would come from using the API.

             

            Tried to compile it again today with similar results:

             

            C:\Adam's Files\Tableau\rest-api-java-sample>ant

            Buildfile: C:\Adam's Files\Tableau\rest-api-java-sample\build.xml

             

            clean:

               [delete] Deleting directory C:\Adam's Files\Tableau\rest-api-java-sample\build

             

            compile:

                [mkdir] Created dir: C:\Adam's Files\Tableau\rest-api-java-sample\build\classes

                [javac] Compiling 27 source files to C:\Adam's Files\Tableau\rest-api-java-sample\build\classes

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:13: error: package javax.ws.rs.core does no

            t exist

                [javac] import javax.ws.rs.core.MediaType;

                [javac]                        ^

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:14: error: package javax.ws.rs.core.Respons

            e does not exist

                [javac] import javax.ws.rs.core.Response.Status;

                [javac]                                 ^

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:15: error: package javax.ws.rs.core does no

            t exist

                [javac] import javax.ws.rs.core.UriBuilder;

                [javac]                        ^

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:29: error: package com.sun.jersey.api.clien

            t does not exist

                [javac] import com.sun.jersey.api.client.Client;

                [javac]                                 ^

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:30: error: package com.sun.jersey.api.clien

            t does not exist

                [javac] import com.sun.jersey.api.client.ClientResponse;

                [javac]                                 ^

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:31: error: package com.sun.jersey.api.clien

            t does not exist

                [javac] import com.sun.jersey.api.client.WebResource;

                [javac]                                 ^

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:112: error: cannot find symbol

                [javac]     private static UriBuilder getApiUriBuilder() {

                [javac]                    ^

                [javac]   symbol:   class UriBuilder

                [javac]   location: class RestApiUtils

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:71: error: cannot find symbol

                [javac]         private final UriBuilder m_builder;

                [javac]                       ^

                [javac]   symbol:   class UriBuilder

                [javac]   location: class Operation

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:73: error: cannot find symbol

                [javac]         Operation(UriBuilder builder) {

                [javac]                   ^

                [javac]   symbol:   class UriBuilder

                [javac]   location: class Operation

                [javac] C:\Adam's Files\Tableau\rest-api-java-sample\src\com\tableausoftware\documentation\api\rest\util\RestApiUtils.java:77: error: cannot find symbol

                [javac]         UriBuilder getUriBuilder() {

                [javac]         ^

                [javac]   symbol:   class UriBuilder

                [javac]   location: class Operation

                [javac] 10 errors

             

            BUILD FAILED

            C:\Adam's Files\Tableau\rest-api-java-sample\build.xml:27: Compile failed; see the compiler error output for details.

             

            Total time: 2 seconds

            • 3. Re: REST API Sample - Compile errors
              Adam Ratkewicz

              For fun, tried to load the project into Eclipse....loaded the external jar files, configured build path, etc....
              Have no errors in the build path or any of the code. However, when I run it I get the following:

               

              Error: Could not find or load main class com.tableausoftware.documentation.api.rest.Demo

              • 4. Re: REST API Sample - Compile errors
                Ben Lower

                Did you copy the four .jar files (see https://onlinehelp.tableau.com/current/api/sdk/en-us/help.htm#SDK/tableau_sdk_using_java_eclipse.htm%3FTocPath%3D_____5 ) to <your install dir>\Java\ ?  What about setting the PATH?

                • 5. Re: REST API Sample - Compile errors
                  Adam Ratkewicz

                  Thanks Ben -

                   

                  The original question was to use the REST API rather than the Tableau SDK. I'm still having issues with that. Here's the link to the sample I'm trying to use. (It's the java version.)

                  http://onlinehelp.tableau.com/current/api/rest_api/en-us/help.htm#REST/rest_api_samples.htm%3FTocPath%3D_____5

                   

                  However, for fun I installed the SDK this morning as was able to publish an extract using the Java examples and Eclipse. I appreciate your tip on the path variable.

                   

                  Any tips on using the REST API samples linked above? Very grateful for your effort.

                  • 6. Re: REST API Sample - Compile errors
                    Ben Lower

                    Ah sorry I missed that you were only interested in the REST API   But glad to hear you can publish with the SDK.  Can you please try downloading and installing the exact versions of the required java libs that are listed in the README.txt file and see if that fixes things?

                    • 7. Re: REST API Sample - Compile errors
                      Adam Ratkewicz

                      Thanks Ben, Sorry for the delay in my response.

                       

                      I'm able to build successfully now. However, still can't run the demo....

                       

                      Buildfile: C:\Users\username\workspace\Tableau API\build.xml

                       

                      Trying to override old definition of task javac

                       

                      clean:

                       

                         [delete] Deleting directory C:\Users\username\workspace\Tableau API\build

                       

                      compile:

                       

                          [mkdir] Created dir: C:\Users\username\workspace\Tableau API\build\classes

                       

                          [javac] Compiling 27 source files to C:\Users\username\workspace\Tableau API\build\classes

                       

                      jar:

                       

                          [mkdir] Created dir: C:\Users\username\workspace\Tableau API\build\jar

                       

                            [jar] Building jar: C:\Users\username\workspace\Tableau API\build\jar\tab-documentation-api.jar

                       

                      main:

                       

                      BUILD SUCCESSFUL

                      Total time: 2 seconds

                       

                       

                      Getting this error when running Demo.java....

                      Exception in thread "main" java.lang.ExceptionInInitializerError

                      Caused by: java.lang.IllegalStateException: Failed to initialize the REST API

                          at com.tableausoftware.documentation.api.rest.util.RestApiUtils.initialize(Unknown Source)

                          at com.tableausoftware.documentation.api.rest.util.RestApiUtils.getInstance(Unknown Source)

                          at com.tableausoftware.documentation.api.rest.Demo.<clinit>(Unknown Source)

                       

                      Will try backing down java from version 8 to version 7.

                      • 8. Re: REST API Sample - Compile errors
                        Adam Ratkewicz

                        ok, so backed down to Java SDK 7u79...no joy.

                         

                        Exception in thread "main" java.lang.UnsupportedClassVersionError: com/tableausoftware/documentation/api/rest/Demo : Unsupported major.minor version 52.0

                            at java.lang.ClassLoader.defineClass1(Native Method)

                            at java.lang.ClassLoader.defineClass(ClassLoader.java:800)

                            at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)

                            at java.net.URLClassLoader.defineClass(URLClassLoader.java:449)

                            at java.net.URLClassLoader.access$100(URLClassLoader.java:71)

                            at java.net.URLClassLoader$1.run(URLClassLoader.java:361)

                            at java.net.URLClassLoader$1.run(URLClassLoader.java:355)

                            at java.security.AccessController.doPrivileged(Native Method)

                            at java.net.URLClassLoader.findClass(URLClassLoader.java:354)

                            at java.lang.ClassLoader.loadClass(ClassLoader.java:425)

                            at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)

                            at java.lang.ClassLoader.loadClass(ClassLoader.java:358)

                            at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:482)

                        • 9. Re: REST API Sample - Compile errors
                          Jeff Krieg

                          Hey Adam,

                           

                          We found a few causes for the "Failed to initialize the REST API" error you were receiving.

                           

                          Check out my response in this thread:

                          REST API sample run time errors

                          • 10. Re: REST API Sample - Compile errors
                            Nicolas Savy

                            To fix this issue you need to add all the Jars file in the folder /lib under the root.

                            Screen Shot 2016-06-08 at 8.41.35 PM.png