使用 java 启动时 JAI I/O 工具缺失,而使用 Maven 运行时则存在

发布于 2025-01-10 00:21:25 字数 5814 浏览 0 评论 0原文

我的java程序涉及PDF。其中一些嵌入了 JPEG2000 图像。因此,我将以下几行添加到我的 pom.xml 中:

    <groupId>org.apache.tika</groupId>
    <artifactId>tika-core</artifactId>
    <version>1.26</version>
</dependency>

<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-parsers</artifactId>
    <version>1.26</version>         
</dependency>

<!--Please note the absence of jai imageio core 
to make the program work. It will be provided by tika parser -->        
<dependency>
    <groupId>com.github.jai-imageio</groupId>
    <artifactId>jai-imageio-jpeg2000</artifactId>
    <version>1.4.0</version>
</dependency>  
    
<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>jbig2-imageio</artifactId>
    <version>3.0.2</version>
</dependency>
...
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>11.0.2</version>
    <type>jar</type>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11.0.2</version>
    <type>jar</type>
</dependency>

...

<build>
   <plugins>
      <plugin>
         <groupId>org.openjfx</groupId>
         <artifactId>javafx-maven-plugin</artifactId>
         <version>0.0.8</version>
         <configuration>
            <mainClass>${mainClass}</mainClass>
         </configuration>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-enforcer-plugin</artifactId>
         <version>3.0.0</version>
         <executions>
            <execution>
               <id>enforce-maven</id>
               <goals>
                  <goal>enforce</goal>
               </goals>
               <configuration>
                  <rules>
                     <requireMavenVersion>
                        <version>3.3.9</version>
                     </requireMavenVersion>
                  </rules>
               </configuration>
            </execution>
         </executions>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-assembly-plugin</artifactId>
         <version>3.3.0</version>
         <executions>
            <execution>
               <phase>package</phase>
               <goals>
                  <goal>single</goal>
               </goals>
               <configuration>
                  <archive>
                     <manifest>
                        <mainClass>${mainClass}</mainClass>
                     </manifest>
                  </archive>
                  <descriptorRefs>
                     <descriptorRef>jar-with-dependencies</descriptorRef>
                  </descriptorRefs>
               </configuration>
            </execution>
         </executions>
      </plugin>
      <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>exec-maven-plugin</artifactId>
         <version>3.0.0</version>
         <configuration>
            <mainClass>${mainClass}</mainClass>
         </configuration>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>3.10.0</version>
         <configuration>
            <release>11</release>
            <source>${javaVersion}</source>
            <target>${javaVersion}</target>
         </configuration>
      </plugin>
   </plugins>
</build>

现在,如果我使用 Maven 运行程序(从项目目录): /pathTo/netbeans/java/maven/bin/mvn "-Dexec.args=-classpath %classpath" -DOMP_THREAD_LIMIT=1 -DskipTests=true exec:java JPEG2000 依赖项已加载,程序按预期工作。

但是,如果我使用 Java 运行程序(从项目目录): java -Dprism.order=sw --module-path /home/user/pathTo/lib/javafx-sdk-11.0.2/lib -- add-modules ALL-MODULE-PATH -verbose:class -jar target/myBig-jar-with-dependency.jar 我得到“org.apache.pdfbox.filter.MissingImageReaderException:无法读取 JPEG2000 图像:未安装 Java 高级成像 (JAI) 图像 I/O 工具”,尽管 JAI 和 JPEG2000 确实出现在加载的类中(请参阅 -verbose:class):

[7,434s][信息][类,加载] com.github.jaiimageio.jpeg2000.impl.J2KImageReader 源:file://path/to/project/target/myJar_with_dependency.jar [7,434s][信息] [类,加载] javax.imageio.ImageReadParam 来源:jrt:/java.desktop [7,435s][info][class,load] com.github.jaiimageio.jpeg2000.J2KImageReadParam 源:file://path/to/project/target/myJar_with_dependency.jar [7,435s][info][class,load] com.github.jaiimageio.jpeg2000.impl.J2KImageReadParamJava 源: file://path/to/project/target/myJar_with_dependency.jar [7,435s][info][class,load] com.github.jaiimageio.jpeg2000.impl.J2K元数据源:file://path/to/project/目标/myJar_with_dependency.jar

使程序按预期工作 java 我必须将 JPEG2000 jar 放在提供给 --module-path 参数的 lib 路径中。但我宁愿只在 pom.xml 中具有明确的依赖关系,以便将来轻松维护代码,而不是在用户目录中的 JavaFX lib 文件夹中也具有依赖关系。

所以我的问题是与上面显示的 maven 命令等效的 java 命令是什么?

任何帮助表示赞赏

My java program involves PDFs. Some of them have JPEG2000 images embedded. So I added the following lines to my pom.xml :

    <groupId>org.apache.tika</groupId>
    <artifactId>tika-core</artifactId>
    <version>1.26</version>
</dependency>

<dependency>
    <groupId>org.apache.tika</groupId>
    <artifactId>tika-parsers</artifactId>
    <version>1.26</version>         
</dependency>

<!--Please note the absence of jai imageio core 
to make the program work. It will be provided by tika parser -->        
<dependency>
    <groupId>com.github.jai-imageio</groupId>
    <artifactId>jai-imageio-jpeg2000</artifactId>
    <version>1.4.0</version>
</dependency>  
    
<dependency>
    <groupId>org.apache.pdfbox</groupId>
    <artifactId>jbig2-imageio</artifactId>
    <version>3.0.2</version>
</dependency>
...
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-fxml</artifactId>
    <version>11.0.2</version>
    <type>jar</type>
</dependency>
<dependency>
    <groupId>org.openjfx</groupId>
    <artifactId>javafx-controls</artifactId>
    <version>11.0.2</version>
    <type>jar</type>
</dependency>

...

<build>
   <plugins>
      <plugin>
         <groupId>org.openjfx</groupId>
         <artifactId>javafx-maven-plugin</artifactId>
         <version>0.0.8</version>
         <configuration>
            <mainClass>${mainClass}</mainClass>
         </configuration>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-enforcer-plugin</artifactId>
         <version>3.0.0</version>
         <executions>
            <execution>
               <id>enforce-maven</id>
               <goals>
                  <goal>enforce</goal>
               </goals>
               <configuration>
                  <rules>
                     <requireMavenVersion>
                        <version>3.3.9</version>
                     </requireMavenVersion>
                  </rules>
               </configuration>
            </execution>
         </executions>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-assembly-plugin</artifactId>
         <version>3.3.0</version>
         <executions>
            <execution>
               <phase>package</phase>
               <goals>
                  <goal>single</goal>
               </goals>
               <configuration>
                  <archive>
                     <manifest>
                        <mainClass>${mainClass}</mainClass>
                     </manifest>
                  </archive>
                  <descriptorRefs>
                     <descriptorRef>jar-with-dependencies</descriptorRef>
                  </descriptorRefs>
               </configuration>
            </execution>
         </executions>
      </plugin>
      <plugin>
         <groupId>org.codehaus.mojo</groupId>
         <artifactId>exec-maven-plugin</artifactId>
         <version>3.0.0</version>
         <configuration>
            <mainClass>${mainClass}</mainClass>
         </configuration>
      </plugin>
      <plugin>
         <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>3.10.0</version>
         <configuration>
            <release>11</release>
            <source>${javaVersion}</source>
            <target>${javaVersion}</target>
         </configuration>
      </plugin>
   </plugins>
</build>

Now if I run the program (from the project directory) with Maven : /pathTo/netbeans/java/maven/bin/mvn "-Dexec.args=-classpath %classpath" -DOMP_THREAD_LIMIT=1 -DskipTests=true exec:java the JPEG2000 dependency is loaded and the program works as expected.

However if I run the program (from the project directory) with Java : java -Dprism.order=sw --module-path /home/user/pathTo/lib/javafx-sdk-11.0.2/lib --add-modules ALL-MODULE-PATH -verbose:class -jar target/myBig-jar-with-dependencies.jar I get "org.apache.pdfbox.filter.MissingImageReaderException: Cannot read JPEG2000 image: Java Advanced Imaging (JAI) Image I/O Tools are not installed" although JAI and JPEG2000 do appear in loaded classes (see -verbose:class) :

[7,434s][info][class,load] com.github.jaiimageio.jpeg2000.impl.J2KImageReader source: file://path/to/project/target/myJar_with_dependencies.jar [7,434s][info][class,load] javax.imageio.ImageReadParam source: jrt:/java.desktop [7,435s][info][class,load] com.github.jaiimageio.jpeg2000.J2KImageReadParam source: file://path/to/project/target/myJar_with_dependencies.jar [7,435s][info][class,load] com.github.jaiimageio.jpeg2000.impl.J2KImageReadParamJava source: file://path/to/project/target/myJar_with_dependencies.jar [7,435s][info][class,load] com.github.jaiimageio.jpeg2000.impl.J2KMetadata source: file://path/to/project/target/myJar_with_dependencies.jar

To make the program work as expected with java I have to put the JPEG2000 jar in the lib path provided to the --module-path argument. But I'd rather only have clear dependencies in pom.xml to ease maintain the code in the future, instead of having also dependencies in the JavaFX lib folder in user directory.

So my question is what is the equivalent java command to the maven command shown above ?

Any help appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

暗恋未遂 2025-01-17 00:21:25

不确定这是否有帮助,因为这听起来更像是巫术!我更新到 Tika 2.3(将 tika-parser 依赖项移至 tika-parsers-standard-package),并且我得到“package org.apache.tika.config 不存在” “(尽管确实如此),我最终重新启动了 Netbeans,构建了 jar,通过 java 命令启动了它,它现在按预期工作。

Not sure this could help since it sounds more like wizardry! I updated to Tika 2.3 (moved tika-parser dependency to tika-parsers-standard-package) and as I got "package org.apache.tika.config does not exist" (although it does), I finally restarted Netbeans, built the jar, launched it via javacommand and it is now working as expected.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文