为什么 geotools 在作为 Java EE 6 应用程序的一部分运行时抛出 MathTransformFactory?
我正在编写一个小型 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 中找不到任何内容。
解决这个问题的任何帮助都会很棒。
谢谢格兰特。
I'm writing a small Java EE 6 Web Service application that is for converting ESRI Shape Files and passing the data into another application.
I have the application working fine as a command line app. However whilst porting the code, it has started to throw an exception whilst running on the Glassfish server.
The code is checking to see if the coordinate projection type is a valid projection for our legacy app and should be returning a boolean value:
/**
* 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;
}
This code runs fine normally as a command line app. However when running this method in glassfish I am getting the following stacktrace:
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)
I've check to ensure that I have all the geotools.jar files added to the project that I need however I am not sure what is causing this error and (although I think I might of missed it) can't find anything in the docs or api.
Any help in fixing this problem would be fantastic.
Thanks Grant.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
GeoTools 使用 Java 服务提供接口 (SPI) 插件系统;这取决于每个 jar 文件中的魔法目录 (META_INF/servies/)。该目录列出了 jar 中可用的所有插件类;在本例中为 MathTransformFactory 实现)。
问题在于,在某些环境(通常是 OSGi)中,访问 Jar 中的文件(而不是类)被认为存在安全风险。
您能否确保您的 glassfish 环境允许访问这些文件? Java 本身就是以这种方式连接的,因此为 Java 高级成像(其中使用此机制注册新图像格式)提出的解决方法并不罕见。
GeoTools uses the Java Service Provide Interface (SPI) plugin system; this depends on a magic directory in each jar file (META_INF/servies/). This directory lists all the plugin classes available in the jar; in this case the MathTransformFactory implementation).
The trouble is that in some environments (usually OSGi) access to files (rather than classes) in a Jar is considered a security risk.
Can you ensure that your glassfish environment allows these files to be accessed? Java itself is wired up this way so it is not uncommon to see workarounds proposed for Java Advanced Imaging (where new image formats are registered using this mechanism).
我在使用 GeoTools 进行 JUnit 测试时遇到了这个问题。事实证明,我需要包含以下依赖项:vecmath 和 jsr-275。
I had this problem with my JUnit tests using GeoTools. It turned out I needed to include dependencies for: vecmath and jsr-275.