Je suis en train d'écrire une petite application de service Web Java EE 6 destinée à la conversion de fichiers de formes ESRI et à la transmission des données dans une autre application. J'ai l'application fonctionne bien comme une application de ligne de commande. Cependant, lors du portage du code, il a commencé à émettre une exception lors de l'exécution sur le serveur Glassfish.Pourquoi geotools lance MathTransformFactory lorsqu'il est exécuté dans le cadre d'une application Java EE 6?
Le code vérifie pour voir si le type de projection de coordonnées est une projection valable pour notre application héritée et ne doit être retourne une valeur booléenne:
/**
* Validates that the shape file is using one of the valid coordinate systems. Returns true if
* the coordinate system is valid.
*
* @param shpFilePath The path to the shape files.
* @return
*/
public boolean validCoordinateSystem(String shpFilePath) {
try {
ShpFiles shapeFiles = new ShpFiles(shpFilePath);
PrjFileReader fileReader = new PrjFileReader(shapeFiles);
CoordinateReferenceSystem coordSystem = fileReader.getCoodinateSystem();
for (int i = 0; i < this.acceptedCoordinateSystems.length; i++) {
if (this.acceptedCoordinateSystems[i].equalsIgnoreCase(coordSystem.getName().toString())) {
return true;
}
}
fileReader.close();
} catch (MalformedURLException ex) {
Logger.getLogger(GeoTools.class.getName()).log(Level.SEVERE, null, ex);
return false;
} catch (IOException ioe) {
Logger.getLogger(GeoTools.class.getName()).log(Level.SEVERE, null, ioe);
return false;
} catch (Exception nex){
Logger.getLogger(GeoTools.class.getName()).log(Level.SEVERE, null, nex);
return false;
}
return false;
}
Ce code fonctionne bien normalement comme une application de ligne de commande. Cependant lors de l'exécution de cette méthode dans GlassFish Je reçois le stacktrace suivant:
org.geotools.factory.FactoryNotFoundException: No factory of kind "MathTransformFactory" found.
at org.geotools.factory.FactoryRegistry.getServiceProvider(FactoryRegistry.java:374)
at org.geotools.factory.FactoryCreator.getServiceProvider(FactoryCreator.java:143)
at org.geotools.referencing.ReferencingFactoryFinder.getFactory(ReferencingFactoryFinder.java:193)
at org.geotools.referencing.ReferencingFactoryFinder.getMathTransformFactory(ReferencingFactoryFinder.java:503)
at org.geotools.referencing.factory.ReferencingObjectFactory.getMathTransformFactory(ReferencingObjectFactory.java:152)
at org.geotools.referencing.factory.ReferencingObjectFactory.createFromWKT(ReferencingObjectFactory.java:1084)
at org.geotools.data.shapefile.prj.PrjFileReader.<init>(PrjFileReader.java:78)
at com.spectrum.demeter.utils.GeoTools.validCoordinateSystem(GeoTools.java:61)
at com.spectrum.demeter.ejb.Converter.addSurveyToDatabase(Converter.java:117)
at com.spectrum.demeter.ws.SurveyManager.convertShpToDb(SurveyManager.java:76)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
at java.lang.reflect.Method.invoke(Method.java:597)
at org.glassfish.webservices.InstanceResolverImpl$1.invoke(InstanceResolverImpl.java:137)
J'ai vérifier que j'ai tous les fichiers geotools.jar ajoutés au projet que j'ai besoin mais je ne suis pas sûr ce qui est causant cette erreur et (bien que je pense que je pourrais l'avoir raté) ne trouve rien dans les documents ou l'API.
Toute aide pour résoudre ce problème serait fantastique.
Merci Grant.
Juste une mise à jour rapide le code fonctionne bien comme un test unitaire? Je pense que cela a quelque chose à voir avec le serveur Glassfish mais je ne vois pas pourquoi. –
Nous avons rencontré la même erreur lors de l'exécution de Geotools dans Hadoop. Je ne sais pas si c'est le correctif idéal, mais nous l'avons résolu en utilisant maven-shade-plugin pour empaqueter nos dépendances avec notre hadoop-job.jar au lieu d'utiliser geotools comme bibliothèque partagée à travers le cache distribué. – arcdrag