我正在编写一个小型 Java EE 6 Web 服务应用程序,用于转换 ESRI 形状文件并将数据传递到另一个应用程序。
我的应用程序作为命令行应用程序运行良好。然而,在移植代码时,它在 Glassfish 服务器上运行时开始引发异常。
代码正在检查坐标投影类型是否是我们遗留应用程序的有效投影,并且应该返回一个布尔值:
/**
* 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;
}
此代码作为命令行应用程序正常运行。但是,在 glassfish 中运行此方法时,我得到以下堆栈跟踪:
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)
我已经检查以确保我已将所有 geotools.jar 文件添加到我需要的项目中但是我不确定是什么导致了这个错误并且(虽然我想我可能会错过它)在文档或 API。
解决这个问题的任何帮助都会很棒。
谢谢格兰特。