2017-07-03 188 views
1

我想使用Geotools訪問不同的Geotools數據存儲(第17.1節)。在我的POM我使用Maven的組裝插件(V 3.0.0)聚集我的項目輸出:使用Maven Assembly插件時找不到Geotools數據存儲

<plugin> 
    <groupId>org.apache.maven.plugins</groupId> 
    <artifactId>maven-assembly-plugin</artifactId> 
    <version>3.0.0</version> 
    <configuration> 
     <archive> 
      <manifest> 
       <mainClass>de.my.project.MainClass</mainClass> 
       <addDefaultImplementationEntries>true</addDefaultImplementationEntries> 
       <addDefaultSpecificationEntries>true</addDefaultSpecificationEntries> 
      </manifest> 
     </archive> 
     <descriptorRefs> 
      <descriptorRef>jar-with-dependencies</descriptorRef> 
     </descriptorRefs> 
    </configuration> 
    <executions> 
     <execution> 
      <id>make-assembly</id> <!-- this is used for inheritance merges --> 
      <phase>package</phase> <!-- bind to the packaging phase --> 
      <goals> 
       <goal>single</goal> 
      </goals> 
     </execution> 
    </executions> 
</plugin> 

我geotools依賴關係:

dependency> 
    <groupId>org.geotools</groupId> 
    <artifactId>gt-shapefile</artifactId> 
    <version>17.1</version> 
</dependency> 
<dependency> 
    <groupId>org.geotools</groupId> 
    <artifactId>gt-geopkg</artifactId> 
    <version>17.1</version> 
</dependency> 
... 

的問題是,我可以訪問Shape文件。在測試類我寫了這個代碼,以計算出,如果數據存儲,可以發現:

Iterator gtIterator = DataStoreFinder.getAvailableDataStores(); 
while(gtIterator.hasNext()){ 
    System.out.println(gtIterator.next().toString()); 
} 
// results in: 
/* 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
org.geotools.data.shapefile.ShapefileDataStoreFacto[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
[email protected] 
*/ 

如果我使用生成的JAR我只是得到運行相同的代碼:

//[email protected] 
//[email protected] 

任何想法可能會導致這個問題?

回答

4

Geotools使用Java的服務基礎結構來加載實現某些接口的類,如DataStore。 Java的服務基礎設施與位於jar文件內的/ META-INF/services /中的文本文件一起工作。

當構建一個jar-with-dependencies時,可以將多個jar文件合併爲一個。當多個jar文件爲同一接口提供實現時,/ META-INF/services /內部的文本文件很可能會相互覆蓋。

您可以通過查看創建的「fat-jar」中的services-directory,特別是/META-INF/services/org.geotools.data.DataStoreFactorySpi條目來驗證。幾個原始的Geotools jar文件將有不同內容的條目,但「fat-jar」只包含一個隨機內容(在你的情況下是ShapeFiles的內容)。

我不是很熟悉的行家遮陽簾插件,但上的其他問題(如Maven shade + resteasy Could find writer for content-type建議使用額外的變壓器:

<transformer 
    implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer" /> 

也有看一個類似的SO-問題與GeoTools:Geotools cannot find HSQL EPSG DB, throws error: NoSuchAuthorityCodeException

+0

謝謝你,你是對的,'org.geotools.data.DataStoreFactorySpi'中的商店被覆蓋,但順序似乎不是隨機的,但。 – Lars

+0

查看FAQ(http://docs.geotools。 org/stable/userguide/build/faq.html)瞭解Maven Shade設置的詳細信息 –