Search code examples
netbeansjarmaven-plugingeotools

geotools program working perfectly in netbeans but when i execute the jar it seems it has no dependencies


I am building a GIS with geotools, it runs perfectly in netbeans but when I build the jar and executed it it seems like if it has no dependencies. I followed the instructions given in geotools doc for building ( http://docs.geotools.org/stable/userguide/build/faq.html )

My pom.xml has this code

<dependencies>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>4.11</version>
  <scope>test</scope>
</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>
</dependencies>

<repositories>
    <repository>
        <id>maven2-repository.dev.java.net</id>
        <name>Java.net repository</name>
        <url>https://maven.java.net/content/groups/public/</url>
    </repository>
    <repository>
        <id>osgeo</id>
        <name>Open Source Geospatial Foundation Repository</name>
        <url>http://download.osgeo.org/webdav/geotools/</url>
    </repository>
</repositories>

<build>
<plugins>
    <plugin>
          <artifactId>maven-compiler-plugin</artifactId>
          <version>2.3.2</version>
          <configuration>
              <encoding>UTF-8</encoding>
              <target>1.5</target>
              <source>1.5</source>
          </configuration>
      </plugin>
      <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-shade-plugin</artifactId>
          <version>1.3.1</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>com.mycompany.shiftgis.App</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>

And when I run the jar it prompts this error:

    Oct 13, 2014 11:54:47 PM org.geotools.factory.FactoryRegistry scanForPlugins
    WARNING: Can't load a service for category "Function". Cause is "ServiceConfigurationError: org.opengis.filter.expression.Function: Provider org.geotools.styling (...) coverage.FilterFunction_isCoverageorg.geotools.filter.function.PropertyExistsFunction not found".
    java.util.ServiceConfigurationError: org.opengis.filter.expression.Function: Provider org.geotools.styling.visitor.RescaleToPixelsFunctionorg.geotools.resources.coverage.FilterFunction_isCoverageorg.geotools.filter.function.PropertyExistsFunction not found

How can I solve it? I will appreciate your help!! Thanks


Solution

  • I found the problem, I was using wrong versions of maven plugins, the correct version for maven-compiler-plugin was 3.2 and the right version for maven-shade-plugin was 2.3