1

我正在编写一个小型 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。

解决这个问题的任何帮助都会很棒。

谢谢格兰特。

4

2 回答 2

2

GeoTools 使用 Java 服务提供接口 (SPI) 插件系统;这取决于每个 jar 文件 (META_INF/servies/) 中的魔法目录。该目录列出了 jar 中所有可用的插件类;在这种情况下是 MathTransformFactory 实现)。

问题在于,在某些环境(通常是 OSGi)中,对 Jar 中的文件(而不是类)的访问被认为是一种安全风险。

你能确保你的 glassfish 环境允许访问这些文件吗?Java 本身就是以这种方式连接起来的,因此为 Java 高级成像(使用这种机制注册新的图像格式)提出的解决方法并不罕见。

于 2011-04-09T03:45:17.873 回答
2

我在使用 GeoTools 的 JUnit 测试中遇到了这个问题。事实证明,我需要包含以下依赖项:vecmath 和 jsr-275。

于 2014-04-10T13:37:19.163 回答