2017-04-19 9 views
0

大きなアプリケーションで作業しています.Mavemバンドルプラグインを使用してプロキシを小さくしました!私はPDFboxに必要な画像(jpeg2000とjbig2)を処理するために必要なライブラリをインポートする際に問題があります。ここでライブラリをロードしていないMavenバンドルプラグインを使用したOSGi

は私のポンポン(その一部)

<?xml version="1.0" encoding="UTF-8"?> 

    <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> 

<modelVersion>4.0.0</modelVersion> 

<parent> 
    <groupId>xxxx</groupId> 
    <artifactId>xxx</artifactId> 
    <version>2.0.7</version> 
</parent> 

<artifactId>proxy-bundle</artifactId> 
<name>Front-End Proxy Bundle</name> 
<version>${proxy.version}</version> 
<packaging>bundle</packaging> 

<properties> 
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> 
</properties> 

<profiles> 
    <profile> 
     <id>compile-entity-schemas</id> 
     <activation> 
      <activeByDefault>false</activeByDefault> 
     </activation> 
     <build> 
      <plugins> 
       <plugin> 
        <groupId>org.jvnet.jaxb2.maven2</groupId> 
        <artifactId>maven-jaxb2-plugin</artifactId> 
        <version>0.8.3</version> 
        <executions> 
         <execution> 
          <id>entity-schemas</id> 
          <goals> 
           <goal>generate</goal> 
          </goals> 
          <configuration> 
           <extension>true</extension> 
           <schemaDirectory>src/main/resources/schema</schemaDirectory> 
           <schemaIncludes> 
            <schemaInclude>text-form-configuration.xsd</schemaInclude> 
           </schemaIncludes> 
           <generateDirectory>src/main/java</generateDirectory> 
           <generatePackage>xxx</generatePackage> 
           <args> 
            <arg>-no-header</arg> 
            <arg>-extension</arg> 
           </args> 
           <plugins> 
            <plugin> 
             <groupId>org.jvnet.jaxb2_commons</groupId> 
             <artifactId>jaxb2-basics</artifactId> 
             <version>0.6.4</version> 
            </plugin> 
           </plugins> 
          </configuration> 
         </execution> 
        </executions> 
       </plugin> 
      </plugins> 
     </build> 
    </profile> 
</profiles> 

<build> 
    <finalName>proxy-bundle</finalName> 
    <resources> 
     <resource> 
      <directory>src/main/resources</directory> 
      <filtering>true</filtering> 
      <excludes> 
       <exclude>invalid_image.png</exclude> 
       <exclude>bfa_logo.png</exclude> 
       <exclude>footer_image.png</exclude> 
       <exclude>check-front-image-template.jpg</exclude> 
      </excludes> 
     </resource> 
     <resource> 
      <directory>src/main/resources</directory> 
      <filtering>false</filtering> 
      <includes> 
       <include>invalid_image.png</include> 
       <include>bfa_logo.png</include> 
       <include>footer_image.png</include> 
       <include>check-front-image-template.jpg</include> 
      </includes> 
     </resource> 
    </resources> 
    <plugins> 
     <plugin> 
      <artifactId>maven-compiler-plugin</artifactId> 
      <version>2.5.1</version> 
      <configuration> 
       <source>1.6</source> 
       <target>1.6</target> 
       <encoding>UTF-8</encoding> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-resources-plugin</artifactId> 
      <version>2.5</version> 
      <configuration> 
       <encoding>UTF-8</encoding> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.felix</groupId> 
      <artifactId>maven-bundle-plugin</artifactId> 
      <version>2.3.7</version> 
      <extensions>true</extensions> 
      <executions> 
       <execution> 
        <goals> 
         <goal>install</goal> 
        </goals> 
       </execution> 
      </executions> 
      <configuration> 
       <instructions> 
        <Import-Package> 
         org.apache.pdfbox;version="[0.0,3)", 
         org.apache.pdfbox.cos.*;version="[0.0,3)", 
         com.levigo.jbig2.*;version="[0.0,3)", 
         com.github.jaiimageio.jpeg2000.*;version="[0.0,3)", 
         com.github.jaiimageio.*;version="[0.0,3)", 
         org.apache.commons.configuration;version="[0.0,2)", 
         org.apache.commons.logging;version="[0.0,2)", 
         org.apache.commons.io.*;version="[0.0,3)", 
         org.slf4j;version="[0.0,2)", 
         org.apache.commons.jcs.*;version="[0.0,3)", 
         eu.bitwalker.useragentutils.*;version="[0.0,3)", 
         * 
        </Import-Package> 
        <Bundle-Activator>com.criticalsoftware.frontend.proxy.main.ProxyBundleActivator</Bundle-Activator> 
        <Bundle-ClassPath>.,{maven-dependencies}</Bundle-ClassPath> 
       </instructions> 
      </configuration> 
     </plugin> 
     <plugin> 
      <groupId>org.zeroturnaround</groupId> 
      <artifactId>jrebel-maven-plugin</artifactId> 
      <version>${jrebel-maven-plugin.version}</version> 
      <executions> 
       <execution> 
        <id>generate-rebel-xml</id> 
        <phase>process-resources</phase> 
        <goals> 
         <goal>generate</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>xxx</groupId> 
      <artifactId>jrebel-remote-maven-plugin</artifactId> 
      <version>1.0-SNAPSHOT</version> 
      <executions> 
       <execution> 
        <id>generate-rebel-remote-xml</id> 
        <phase>process-resources</phase> 
        <goals> 
         <goal>remote-generate</goal> 
        </goals> 
       </execution> 
      </executions> 
     </plugin> 
     <plugin> 
      <groupId>org.apache.maven.plugins</groupId> 
      <artifactId>maven-surefire-plugin</artifactId> 
      <version>2.17</version> 
      <configuration> 
       <skipTests>true</skipTests> 
      </configuration> 
     </plugin> 
    </plugins> 
    <pluginManagement> 
     <plugins> 
      <!--This plugin's configuration is used to store Eclipse m2e settings 
       only. It has no influence on the Maven build itself. --> 
      <plugin> 
       <groupId>org.eclipse.m2e</groupId> 
       <artifactId>lifecycle-mapping</artifactId> 
       <version>1.0.0</version> 
       <configuration> 
        <lifecycleMappingMetadata> 
         <pluginExecutions> 
          <pluginExecution> 
           <pluginExecutionFilter> 
            <groupId> 
             org.zeroturnaround 
            </groupId> 
            <artifactId>jrebel-maven-plugin</artifactId> 
            <versionRange> 
             [1.1.0,) 
            </versionRange> 
            <goals> 
             <goal>generate</goal> 
            </goals> 
           </pluginExecutionFilter> 
           <action> 
            <ignore /> 
           </action> 
          </pluginExecution> 
         </pluginExecutions> 
        </lifecycleMappingMetadata> 
       </configuration> 
      </plugin> 
     </plugins> 
    </pluginManagement> 
</build> 
<dependencies> 
    <!-- Dev Model --> 
    <dependency> 
     <groupId>xxx</groupId> 
     <artifactId>jcc-core-common</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>xxx</groupId> 
     <artifactId>jcu-core-utils-common</artifactId> 
    </dependency> 

    <!-- Web Server --> 
    <dependency> 
     <groupId>org.simpleframework</groupId> 
     <artifactId>simple</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>com.google.zxing</groupId> 
     <artifactId>javase</artifactId> 
    </dependency> 

    <!-- Logging --> 
    <dependency> 
     <groupId>ch.qos.logback</groupId> 
     <artifactId>logback-core</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>ch.qos.logback</groupId> 
     <artifactId>logback-classic</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.slf4j</groupId> 
     <artifactId>slf4j-api</artifactId> 
    </dependency> 

    <!-- Apache Commons --> 
    <dependency> 
     <groupId>commons-io</groupId> 
     <artifactId>commons-io</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-lang3</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>commons-collections</groupId> 
     <artifactId>commons-collections</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>commons-configuration</groupId> 
     <artifactId>commons-configuration</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>commons-logging</groupId> 
       <artifactId>commons-logging</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>commons-codec</groupId> 
     <artifactId>commons-codec</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpclient</artifactId> 
     <exclusions> 
      <exclusion> 
       <groupId>commons-logging</groupId> 
       <artifactId>commons-logging</artifactId> 
      </exclusion> 
     </exclusions> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpmime</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.httpcomponents</groupId> 
     <artifactId>httpclient-cache</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>commons-beanutils</groupId> 
     <artifactId>commons-beanutils</artifactId> 
    </dependency> 

    <!-- Serialization --> 
    <dependency> 
     <groupId>com.google.code.gson</groupId> 
     <artifactId>gson</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.thoughtworks.xstream</groupId> 
     <artifactId>xstream</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.jvnet.jaxb2_commons</groupId> 
     <artifactId>jaxb2-basics-runtime</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.json</groupId> 
     <artifactId>json</artifactId> 
    </dependency> 

    <!-- Image Editing --> 
    <dependency> 
     <groupId>com.jhlabs</groupId> 
     <artifactId>filters</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>xxx</groupId> 
     <artifactId>image-detector-api</artifactId> 
    </dependency> 

    <!-- PDF --> 
    <dependency> 
     <groupId>com.itextpdf</groupId> 
     <artifactId>itextpdf</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.pdfbox</groupId> 
     <artifactId>pdfbox</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>org.apache.pdfbox</groupId> 
     <artifactId>pdfbox-tools</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.levigo.jbig2</groupId> 
     <artifactId>levigo-jbig2-imageio</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.github.jai-imageio</groupId> 
     <artifactId>jai-imageio-core</artifactId> 
    </dependency> 
    <dependency> 
     <groupId>com.github.jai-imageio</groupId> 
     <artifactId>jai-imageio-jpeg2000</artifactId> 
    </dependency> 

    <!-- OSGi --> 
    <dependency> 
     <groupId>org.apache.felix</groupId> 
     <artifactId>org.osgi.core</artifactId> 
    </dependency> 

    <!-- Others --> 
    <dependency> 
     <groupId>com.sun.jna</groupId> 
     <artifactId>jna</artifactId> 
    </dependency> 

    <dependency> 
     <groupId>org.apache.commons</groupId> 
     <artifactId>commons-jcs-core</artifactId> 
    </dependency> 
    <!-- Necessary to fix parallel build when the maven repository is empty --> 
    <dependency> 
     <groupId>xxxs</groupId> 
     <artifactId>xxx</artifactId> 
     <version>${project.version}</version> 
     <scope>compile</scope> 
     <type>pom</type> 
    </dependency> 

    <!-- UA Utils --> 
    <dependency> 
     <groupId>eu.bitwalker</groupId> 
     <artifactId>UserAgentUtils</artifactId> 
    </dependency> 

    <!-- test --> 
    <dependency> 
     <groupId>org.testng</groupId> 
     <artifactId>testng</artifactId> 
     <scope>test</scope> 
    </dependency> 
</dependencies> 

である私は、インポート・パッケージを固定し、私はもう警告を持っていけません!

> [INFO] ---のmaven-バンドルプラグイン:2.3.7:!バンドル(デフォルトバンドル)@プロキシ・バンドル> --- [WARNING]バンドルcom.criticalsoftware.frontend:proxy-bundle:bundle:2.0.7:!!com.github.jai-imageioの照合参照が見つかりませんでした。* [WARNING]バンドルcom.criticalsoftware.frontend:proxy-bundle:bundle: 2.0.7:com.levigo.jbig2にマッチする参照を見つけられませんでした。* [警告] com.criticalsoftware.frontend:proxy-bundle:bundle:2.0.7:!は一致するorgを参照しませんでした。 apache.pdfbox.cos。*

ここでは、pdfBoxがこれらのライブラリを使用する私の方法です私はtry/catchブロックで例外が発生します!

private static boolean checkPDFImagesSize(PDDocument document) { 
PDPageTree list = document.getPages(); 
PDXObject o; 
for (PDPage page : list) { 
    PDResources pdResources = page.getResources(); 
    for (COSName cosName : pdResources.getXObjectNames()) { 
     try { 
      o = pdResources.getXObject(cosName); 
     } catch (IOException e) { 
      throw ProxyRuntimeException.of(ExceptionCodes.ERROR_GENERATING_PDF_IMAGES); 
     } 
     if (o instanceof org.apache.pdfbox.pdmodel.graphics.image.PDImageXObject) { 
      if (((PDImageXObject) o).getHeight() * ((PDImageXObject) o).getWidth() * ((PDImageXObject) o) 
        .getBitsPerComponent() * 3.0 > ALERT_IMAGE_SIZE_INSIDE_PDF) { 
       return false; 
      } 
     } 
    } 
} 
return true; 

}

のIntelliJでデバッグのとき、私はこれを得ました!

org.apache.pdfbox.filter.MissingImageReaderException:JPEG2000画像を読み取ることができません:Javaの拡張イメージング(JAI)の画像I/O Toolsが

+0

Apache Felix Console( '/ system/console/bundles')にインポートエラーがありますか?マニフェストで定義したインポートが満たされていますか? – Jens

+0

どこでそれをチェックできますか?しかし、私はコンパイル時にエラーを出すことはありませんが、実行時には、私はその例外を取得します! : – PcS

+0

http:// /system/console/bundles'にあるApache Felix Consoleで確認できます。バンドルをクリックすると、必要なクラスをすべてインポートできるかどうかを確認できます。それはあなたに表示されません。この質問の画像を見てください。これは多くのように見えるはずです:http://stackoverflow.com/q/43242977/190823あなたはおそらく非常に似た問題があります。 – Jens

答えて

1

にインストールされていない、私は間違って問題を見ていました!問題はJPEG2000/JBIG2の依存関係ではなく、OSGiのServiceLoderに問題がなく、PDFBoxから呼び出されるjavax.imageio.spi.ServiceRegistryにあります。ここに記載されているように:OSGi java.Util.ServiceLoader

私はこのソリューションを実装する必要がありました。 OSGi Aries spi-fly

関連する問題