0

I wrote some java code using geotools library using the maven build tool. This small code runs successfully when i run it as an independent java application in the maven project . But since i needed to use this piece of code in another project where i do not have maven , i copied all the jar files from the Maven Dependencies folder in the maven project to my other project and added these as external jars/dependencies.But this piece of code does not run in the new project when i run it as a java application in eclipse.Here is the piece of code and the stacktrace.:

38.    public static void main(String[] args) throws Exception {
39.     File file = new File("path to shapefile");
40.     modifyShapeFile(file);
    ...........................................
    ............................
    }
52.   public static void modifyShapeFile(final File file) throws Exception {
53.     ShapefileDataStore store = (ShapefileDataStore) FileDataStoreFinder
                .getDataStore(file);
54.     SimpleFeatureSource featureSource = store.getFeatureSource();
55.     SimpleFeatureStore featureStore = (SimpleFeatureStore) featureSource;
56.     Transaction transaction = new DefaultTransaction("modify");
57.     featureStore.setTransaction(transaction);
58.     SimpleFeatureType featureType = store.getSchema();
59.     SimpleFeatureBuilder build = new SimpleFeatureBuilder(featureType);
        ........................................................
        .........................................................

StackTrace:

Exception in thread "main" java.lang.NoSuchFieldError: METER
    at org.geotools.referencing.wkt.Parser.parseSpheroid(Parser.java:560)
    at org.geotools.referencing.wkt.Parser.parseDatum(Parser.java:656)
    at org.geotools.referencing.wkt.Parser.parseGeoGCS(Parser.java:867)
    at org.geotools.referencing.wkt.Parser.parseProjCS(Parser.java:913)
    at org.geotools.referencing.wkt.Parser.parseCoordinateReferenceSystem(Parser.java:225)
    at org.geotools.referencing.wkt.Parser.parseCoordinateReferenceSystem(Parser.java:204)
    at org.geotools.referencing.factory.ReferencingObjectFactory.createFromWKT(ReferencingObjectFactory.java:1090)
    at org.geotools.data.PrjFileReader.<init>(PrjFileReader.java:94)
    at org.geotools.data.PrjFileReader.<init>(PrjFileReader.java:68)
    at org.geotools.data.shapefile.ShapefileSetManager.openPrjReader(ShapefileSetManager.java:106)
    at org.geotools.data.shapefile.ShapefileFeatureSource.readAttributes(ShapefileFeatureSource.java:515)
    at org.geotools.data.shapefile.ShapefileFeatureSource.buildFeatureType(ShapefileFeatureSource.java:471)
    at org.geotools.data.shapefile.ShapefileFeatureStore.buildFeatureType(ShapefileFeatureStore.java:131)
    at org.geotools.data.store.ContentFeatureSource.getAbsoluteSchema(ContentFeatureSource.java:340)
    at org.geotools.data.store.ContentFeatureSource.getSchema(ContentFeatureSource.java:309)
    at org.geotools.data.store.ContentDataStore.getSchema(ContentDataStore.java:339)
    at org.geotools.data.store.ContentDataStore.getSchema(ContentDataStore.java:712)
    at org.geotools.data.shapefile.ShapefileDataStore.getSchema(ShapefileDataStore.java:197)
    at com.amazon.marketplacevolumeviewer.shapefile.ModifyShapeFile.modifyShapeFile(ModifyShapeFile.java:58)
    at com.amazon.marketplacevolumeviewer.shapefile.ModifyShapeFile.main(ModifyShapeFile.java:40)

The pom.xml file for the maven project is according to this tutorial: http://docs.geotools.org/latest/userguide/tutorial/quickstart/eclipse.html.

There is no source code attaches with these jar files , hence i could not follow the stack trace .

jps
  • 173
  • 1
  • 13
  • Might be a version conflict. In the Maven project do a **mvn dependency:tree**, are there perhaps multiple versions of the same libraries in there? – Gimby Sep 03 '15 at 13:10
  • 1
    Can't you make your _"other project"_ a Maven project, too? Because that's one of the things Maven is famous for: No need to copy `jar` files around. – Gerold Broser Sep 03 '15 at 18:00
  • It is already an ANT project and i need to use ANT only . – jps Sep 04 '15 at 05:41

1 Answers1

0

Please use Maven when using GeoTools - it is almost impossible for even hardened developers like me to keep track of all the dependencies that GeoTools needs.

At least run mvn dependency:list on the geotools build to show you which files you need rather than copying blindly. It may be that you need to pick up a plugin jar and it's associated dependencies.

Looking at your error suggests that it is possible that maybe you are missing the Units system which is in net.java.dev.jsr-275.jar.

Ian Turton
  • 10,018
  • 1
  • 28
  • 47