No Source Code is available for type : GWT Compilation Error

Saurabh Saxena picture Saurabh Saxena · Mar 3, 2012 · Viewed 44.7k times · Source

I am trying to make get requests by a servlet in my GWT application. On compiling the code I am getting these errors.

[ERROR] Line 16: No source code is available for type org.apache.http.client.ClientProtocolException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.apache.http.ParseException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.json.simple.parser.ParseException; did you forget to inherit a required module?

What should I do to remove these errors? Are these classes are not supported by GWT?

Following is the code I am using

public String getJSON() throws ClientProtocolException, IOException, ParseException{
    HttpClient httpclient = new DefaultHttpClient(); 
    JSONParser parser = new JSONParser();
    String url = "some - url - can't disclose";
    HttpResponse response = httpclient.execute(new HttpGet(url));
    JSONObject json_data = (JSONObject)parser.parse(EntityUtils.toString(response.getEntity()));
    JSONArray results = (JSONArray)json_data.get("result");
}

This code is working fine If I use this on a usual java project/ console application.

Answer

Viacheslav Dobromyslov picture Viacheslav Dobromyslov · Feb 23, 2013

If you use Maven then you can do this.

maven-gwt-plugin with parameter compileSourcesArtifacts will do all sources management work and will let you to compile GWT module.

In the module that you want to include, you'll have to enable the generation of source package. And take a look at external GWT module example on Github.

GWT can't compile any Java class to JavaScript client code. It supports only several base classes. See GWT JRE Emulation Reference.

Example pom.xml:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">

    <dependencies>
        <dependency>
            <groupId>com.my.group</groupId>
            <artifactId>my-artifact</artifactId>
            <version>1.0</version>
        </dependency>
    </dependencies>

    <!-- ... -->

    <build>
        <plugins>
            <plugin>
                <groupId>org.codehaus.mojo</groupId>
                <artifactId>gwt-maven-plugin</artifactId>
                <version>2.5.0</version>
                <!-- ... -->
                <configuration>
                    <compileSourcesArtifacts>
                        <compileSourcesArtifact>com.my.group:my-artifact</compileSourcesArtifact>
                    </compileSourcesArtifacts>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>