samedi 9 mai 2015

GeoTiff error when building Jar with GeoTools

First of all, please forgive any mistakes you'll probably see in my mail, I'm not a native speaker.

I'm seeking some help with GeoTools. I've been using it for a school's project, I had almost no problem until now.

But now that my project is done, I've tried to build an executable jar with the maven's shade plugin like it is shown in the GeoTools' FAQ.

Here's my problem, when I try to use the jar which have been created when I type 'mvn package', I get this error :

java.lang.UnsupportedOperationException: Trying to get a reader from an unknown
format.
        at org.geotools.coverage.grid.io.UnknownFormat.getReader(UnknownFormat.j
ava:62)
        at coeurDLL.SMap.<init>(SMap.java:44)
        at coeurDLL.CoeurController.initialize(CoeurController.java:103)
        at coeur.Interface.getMapsAndDisplay(Interface.java:152)
        at coeur.Interface.<init>(Interface.java:948)
        at coeur.Interface.main(Interface.java:957)
java.lang.NullPointerException
        at coeurDLL.CoeurController.getColumnsFields(CoeurController.java:225)
        at coeur.Interface.setControlPanel(Interface.java:327)
        at coeur.Interface.displayMainWindow(Interface.java:185)
        at coeur.Interface.getMapsAndDisplay(Interface.java:162)
        at coeur.Interface.<init>(Interface.java:948)
        at coeur.Interface.main(Interface.java:957)

It happens when I try to read a GeoTif file with the method "reader.read(null)". Of course I don't have this problem when executing the project on Eclipse.

I read somewhere that it could be a dependency problem, but I don't see what I could have missed.

Some details which could be helpful : - I'm using GeoTools version 12-RC1 - I'm not using the JAI libraries, I'm working in Java Pure mode. It allows me to work with a 64 bits jdk. I tried by curiosity with a 32bit jdk, but I still have the same problem anyway. - I'm working on Windows 7, but it shouldn't make any difference.

Here's the content of my pom.xml :

<project xmlns="http://ift.tt/IH78KX" xmlns:xsi="http://ift.tt/ra1lAU"
  xsi:schemaLocation="http://ift.tt/IH78KX http://ift.tt/VE5zRx">
  <modelVersion>4.0.0</modelVersion>
  <groupId>pfe.coeur</groupId>
  <artifactId>coeur</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>tuto</name>
  <url>http://ift.tt/19pvvEY;


    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <geotools.version>12-RC1</geotools.version>
    </properties>
<build>
      <plugins>
          <plugin>
              <artifactId>maven-compiler-plugin</artifactId>
              <version>3.1</version>
              <configuration>
                  <encoding>UTF-8</encoding>
                  <target>1.8</target>
                  <source>1.8</source>
              </configuration>
          </plugin>
          <plugin>
              <groupId>org.apache.maven.plugins</groupId>
              <artifactId>maven-shade-plugin</artifactId>
              <version>2.3</version>
              <executions>
                  <execution>
                      <phase>package</phase>
                      <goals>
                          <goal>shade</goal>
                      </goals>
                      <configuration>
                          <transformers>
                              <!-- This bit sets the main class for the executable jar as you otherwise -->
                              <!-- would with the assembly plugin                                       -->
                              <transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
                                  <manifestEntries>
                                      <Main-Class>coeur.Interface</Main-Class>
                                  </manifestEntries>
                              </transformer>
                              <!-- This bit merges the various GeoTools META-INF/services files         -->
                              <transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
                          </transformers>
                      </configuration>
                  </execution>
              </executions>
          </plugin>
      </plugins>
  </build>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-coverage</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-render</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-shapefile</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-swing</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-epsg-hsql</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-geotiff</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-image</artifactId>
            <version>${geotools.version}</version>
        </dependency>
        <dependency>
            <groupId>org.geotools</groupId>
            <artifactId>gt-wms</artifactId>
            <version>${geotools.version}</version>
        </dependency>
    </dependencies>

        <repositories>
        <repository>
            <id>maven2-repository.dev.java.net</id>
            <name>Java.net repository</name>
            <url>http://ift.tt/JvbN53;
        </repository>
        <repository>
            <id>osgeo</id>
            <name>Open Source Geospatial Foundation Repository</name>
            <url>http://ift.tt/1vwtQeD;
        </repository>
    </repositories>
</project>

I can get this same error on Eclipse when I delete gt:geotiff from my dependencies. But the jar does contain this dependency.

I'd be very grateful if someone can help me to solve this problem. I need this executable jar to finish my project and I don't have a lot of time to get it.

Regards,

Aucun commentaire:

Enregistrer un commentaire