0

I'm working on a Web Map Service written in Java and using the GeoTools library. My goal is to make the data parsing json format, so I'm using the form Unsupported GeoTools. This is the parsingJSON method that takes in the path of the input file and returns as output the FeatureCollection of the files feature:

public FeatureCollection parsingJSON(String path) throws FileNotFoundException, IOException, ParseException {
        System.out.println("INTO PARSINGJSON");
        JSONParser parser = new JSONParser();

        File f = new File(path); 
        System.out.println("complete path file --->" + f.getAbsolutePath());

        Object obj = parser.parse(new java.io.FileReader(path));
        FeatureJSON fJSON = new FeatureJSON();
        FeatureCollection fc = fJSON.readFeatureCollection(obj.toString());
        return fc;
    }

When I run the code by passing the path of the file, gives me this exception:

mag 02, 2016 4:09:42 PM org.apache.catalina.core.StandardWrapperValve invoke
GRAVE: Servlet.service() for servlet ServletWMS threw exception
java.lang.ClassNotFoundException: org.json.simple.parser.ParseException
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1680)
    at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1526)
    at com.lamiaservlet.servlets.ServletWMS.operation(ServletWMS.java:140)
    at com.lamiaservlet.servlets.ServletWMS.doGet(ServletWMS.java:51)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:617)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:723)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:861)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:612)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:503)
    at java.lang.Thread.run(Unknown Source)

I want to clarify that I imported the library properly json-simple-1.1 and I have the following pom.xml:

<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">
  <modelVersion>4.0.0</modelVersion>
  <groupId>Servlet</groupId>
  <artifactId>Servlet</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>
  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <geotools.version>13.2</geotools.version>
  </properties>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
  <dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-main</artifactId>
            <version>${project.version}</version>
        </dependency>
        <!--   Third-party dependencies   -->
        <dependency>
            <groupId>com.googlecode.json-simple</groupId>
            <artifactId>json-simple</artifactId>
            <version>1.1</version>
        </dependency>

        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-epsg-hsql</artifactId>
            <version>${project.version}</version>
            <scope>test</scope>
        </dependency>
        <dependency>
          <groupId>commons-lang</groupId>
          <artifactId>commons-lang</artifactId>
        </dependency>
        <dependency>
             <groupId>org.geotools</groupId>
            <artifactId>gt-geojson</artifactId>
             <version>${geotools.version}</version>
        </dependency>
    </dependencies>
  </dependencyManagement>
</project>
maxada
  • 1
  • 2

1 Answers1

0

In fact you don't need to specify json-simple in your pom file as the magic of maven will pull it in automatically. But it won't hurt either! I'm guessing that your code works fine in Eclipse (or other IDE) but fails when you deploy it to Tomcat.

It seems that Maven isn't bundling all of the dependencies into the war file - the only issue I can see with your pom is that you use project.version and geotools-version but only define geotools-version which may confuse Maven.

Unrelated to your problem, you declare gt-epsg-hsql as a test dependency but you will need it in your service. You may also be better of using the gt-geojsondatastore module as that will allow you to use GeoJSON in the same way as any other GeoTools datasource.

EDIT

I have created a simple Maven Project and the following pom creates a working war file with all the GeoTools jars included when you run mvn install. If you intend to use referencing then you will need to add an epsg jar as described here.

<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">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.ianturton.cookbook</groupId>
  <artifactId>simple</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>simple</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <geotools.version>14.3</geotools.version>
  </properties>
 <repositories>
    <repository>
      <id>maven2-repository.dev.java.net</id>
      <name>Java.net repository</name>
      <url>http://download.java.net/maven/2</url>
    </repository>
    <repository>
      <id>osgeo</id>
      <name>Open Source Geospatial Foundation Repository</name>
      <url>http://download.osgeo.org/webdav/geotools/</url>
    </repository>
    <repository>
      <snapshots>
        <enabled>true</enabled>
      </snapshots>
      <id>imageio-ext-repository</id>
      <name>imageio-ext Repository</name>
      <url>http://maven.geo-solutions.it/</url>
    </repository>
    <!--  <repository>
    <snapshots>
      <enabled>true</enabled>
    </snapshots>
    <id>boundless</id>
    <name>Boundless Maven Repository</name>
    <url>https://boundless.artifactoryonline.com/boundless/</url>
  </repository> -->
  </repositories>
  <dependencies>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
    <dependency>
        <groupId>org.geotools</groupId>
        <artifactId>gt-geojson</artifactId>
        <version>${geotools.version}</version>
    </dependency>
  </dependencies>
  <build>
    <sourceDirectory>src</sourceDirectory>
    <resources>
      <resource>
        <directory>src</directory>
        <excludes>
          <exclude>**/*.java</exclude>
        </excludes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId>maven-war-plugin</artifactId>
        <version>2.4</version>
        <configuration>
          <warSourceDirectory>WebContent</warSourceDirectory>
          <failOnMissingWebXml>false</failOnMissingWebXml>
        </configuration>
      </plugin>
    </plugins>
  </build>
</project>

Gives me the following in the war file:

201006 Wed Apr 20 16:32:56 BST 2016 WEB-INF/lib/gt-api-14.3.jar
342540 Wed Oct 14 16:41:20 BST 2015 WEB-INF/lib/core-0.26.jar
 96221 Wed Oct 14 16:41:20 BST 2015 WEB-INF/lib/commons-pool-1.5.4.jar
 31693 Wed Oct 14 16:41:22 BST 2015 WEB-INF/lib/GeographicLib-Java-1.44.jar
 16046 Wed Oct 14 17:16:18 BST 2015 WEB-INF/lib/json-simple-1.1.jar
794991 Wed Oct 14 16:41:28 BST 2015 WEB-INF/lib/jts-1.13.jar
 91347 Wed Oct 14 16:41:20 BST 2015 WEB-INF/lib/jsr-275-1.0-beta-2.jar
345853 Wed Apr 20 16:33:04 BST 2016 WEB-INF/lib/gt-opengis-14.3.jar
284220 Wed Oct 14 17:16:20 BST 2015 WEB-INF/lib/commons-lang-2.6.jar
151304 Wed Oct 14 16:41:28 BST 2015 WEB-INF/lib/jdom-1.1.3.jar
508935 Wed Apr 20 16:33:02 BST 2016 WEB-INF/lib/gt-metadata-14.3.jar
 11497 Wed Oct 14 16:41:56 BST 2015 WEB-INF/lib/jgridshift-1.0.jar
1722452 Wed Apr 20 16:32:56 BST 2016 WEB-INF/lib/gt-main-14.3.jar
 63066 Fri May 06 11:52:30 BST 2016 WEB-INF/lib/gt-geojson-14.3.jar
1171353 Wed Apr 20 16:33:00 BST 2016 WEB-INF/lib/gt-referencing-14.3.jar
1900631 Wed Oct 14 16:42:16 BST 2015 WEB-INF/lib/jai_core-1.1.3.jar
Ian Turton
  • 10,018
  • 1
  • 28
  • 47
  • I had to put the libraries in the lib directory. [SOLVED] – maxada May 06 '16 at 10:40
  • mvn war should do that for you if your pom is correct – Ian Turton May 06 '16 at 10:41
  • I can not correct the pom.xml file. Unfortunately I'm working on a project initiated by another person, this is the best that I could do, or add them manually. Would someone know tell me how I could adjust the pom.xml file? – maxada May 06 '16 at 10:43