我正在使用Java編寫的Web地圖服務以及使用GeoTools庫。我的目標是使數據解析JSON格式,所以我使用的是form Unsupported GeoTools。這是parsingJSON方法,它在輸入文件並返回作爲輸出的文件的FeatureCollection功能的路徑:Java Servlet:使用Geotools解析geo JSON
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;
}
當我通過傳遞文件的路徑運行的代碼,使我這個例外:
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)
我要澄清的是我導入庫正常json-simple-1.1,我有以下的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>
我不得不把庫lib目錄中。 [已解決] – maxada
如果您的pom正確,mvn war應該爲您做這件事 –
我無法更正pom.xml文件。不幸的是,我正在開展另一個人發起的項目,這是我可以做的最好的,或者手動添加它們。有人知道告訴我如何調整pom.xml文件嗎? – maxada