Apache FOP:在添加Apache FOP Maven依赖后出现的错误列表

huangapple go评论67阅读模式
英文:

Apache FOP: List of errors after adding Apache FOP Maven dependency

问题

现在我正在处理一个调用SOAP Web服务的JDK-14应用程序,接收到XML结果后,必须调用一个方法来使用Apache FOP库生成PDF文档。请注意,对于此项目,我没有使用module-info.java

这是我Maven中当前的依赖项列表。在添加了两个Apache FOP依赖项(请参见下文)之后,项目无法再编译和运行,尽管之前整个项目都没有问题。

错误消息各种各样,如下所示:

import javax.xml.namespace.QName;
The package javax.xml.namespace is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.transform.Result;
The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.transform.sax.SAXResult;
The package javax.xml.transform.sax is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.transform.stream.StreamSource;
The package javax.xml.transform.stream is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.parsers.DocumentBuilderFactory;
The package javax.xml.parsers is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

我想知道如何解决这个问题。也许可以在冲突的特定依赖项内部使用exclusion标签来处理?

附:最终可以通过直接从命令行调用Apache FOP jar来生成PDF文档。

java -jar fop.jar -r -xml <xml_path> -xsl <xsl_path> -param name1 value1 -param name2 value2 ... myPDF.pdf

但我想知道以下两点:(1)是否仍然可以通过代码配置。(2)为什么现在会出现这种情况。在迁移到JDK-14之前,该项目在JDK-11和JDK-13上运行正常。

英文:

Now I'm working on a JDK-14 application which calls to a SOAP Web Service, and after receiving a XML result next it must call a method to generate a PDF document via Apache FOP library. Please note that I'm not using module-info.java for this project.

This is my current list of dependencies in Maven. All the project was running without problems. But after adding the two Apache FOP dependencies (see below), it is not possible to compile and run the application anymore.

<dependencies>
		<!-- Dependencies for XML marshaling and more -->
		<dependency>
			<groupId>jakarta.xml.bind</groupId>
			<artifactId>jakarta.xml.bind-api</artifactId>
			<version>2.3.3</version>
		</dependency>
		<!-- Runtime -->
		<dependency>
			<groupId>org.glassfish.jaxb</groupId>
			<artifactId>jaxb-runtime</artifactId>
			<version>2.3.3</version>
			<scope>runtime</scope>
		</dependency>
		<!-- Dependencies for Web Service -->
		<dependency>
			<groupId>jakarta.xml.ws</groupId>
			<artifactId>jakarta.xml.ws-api</artifactId>
			<version>2.3.3</version>
		</dependency>
		<dependency>
			<groupId>jakarta.jws</groupId>
			<artifactId>jakarta.jws-api</artifactId>
			<version>2.1.0</version>
		</dependency>
		<dependency>
			<groupId>com.sun.xml.ws</groupId>
			<artifactId>rt</artifactId>
			<version>2.3.3</version>
		</dependency>
		<!-- Dependencies for Apache PDF -->
		<dependency>
			<groupId>org.apache.xmlgraphics</groupId>
			<artifactId>xmlgraphics-commons</artifactId>
			<version>2.4</version>
		</dependency>
		<dependency>
			<groupId>org.apache.xmlgraphics</groupId>
			<artifactId>fop</artifactId>
			<version>2.5</version>
		</dependency>
		<!--Dependencies for QR Code-->
		<dependency>
			<groupId>com.google.zxing</groupId>
			<artifactId>core</artifactId>
			<version>3.4.0</version>
		</dependency>
		<dependency>
			<groupId>com.google.zxing</groupId>
			<artifactId>javase</artifactId>
			<version>3.4.0</version>
		</dependency>
</dependencies>

The error messages varies from:

import javax.xml.namespace.QName;
The package javax.xml.namespace is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.transform.Result;
The package javax.xml.transform is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.transform.sax.SAXResult;
The package javax.xml.transform.sax is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.transform.stream.StreamSource;
The package javax.xml.transform.stream is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

import javax.xml.parsers.DocumentBuilderFactory;
The package javax.xml.parsers is accessible from more than one module: <unnamed>, java.xmlJava(8390063)

I want to know how can I deal with this problem. Maybe using an exclusion tag inside the specific dependency in conflict?

PD. At the end it is possible to generate the PDF document, just by calling directly the Apache FOP jar from the command line.

java -jar fop.jar -r -xml <xml_path> -xsl <xsl_path> -param name1 value1 -param name2 value2 ... myPDF.pdf

But I want to know (1) if is still possible to configure via code. And (2) why this is happening now. The project was running with JDK-11 and JDK-13 before migration to JDK-14.

答案1

得分: 1

我不太确定为什么最近的JDK会出现这个问题。

使用JDK-8时,一切正常。

当然,javax.xml包在apache-fopxml-apis依赖项中以及JDK-14中都存在,但以前也是这样。

但无论如何,以下的dependency-exclusion对我在JDK-14下使用Eclipse-2020-06解决了问题:

<!DOCTYPE xml>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">

	<modelVersion>4.0.0</modelVersion>
	<groupId>com.stackoverflow</groupId>
	<artifactId>apache.fop.jdk14.exclude.xml-apis</artifactId>
	<version>0.0.1-SNAPSHOT</version>

	<properties>
		<maven.compiler.target>14</maven.compiler.target>
		<maven.compiler.source>14</maven.compiler.source>
	</properties>

	<dependencies>
		<dependency>
			<groupId>org.apache.xmlgraphics</groupId>
			<artifactId>fop</artifactId>
			<version>2.5</version>
			<exclusions><exclusion><groupId>xml-apis</groupId><artifactId>*</artifactId></exclusion></exclusions>
		</dependency>
	</dependencies>
</project>
英文:

I'm not too certain quite why this problem occurs with recent JDK's.

With JDK-8, it's ok.

Of course, the javax.xml package is in the xml-apis dependency of apache-fop and in JDK-14, but that was also the case previously.

But anyway, the following dependency-exclusion solved the problem for me under JDK-14 using Eclipse-2020-06:

&lt;!DOCTYPE xml&gt;
&lt;project
		xmlns=&quot;http://maven.apache.org/POM/4.0.0&quot;
		xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;
		xsi:schemaLocation=&quot;http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd&quot;&gt;

	&lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
	&lt;groupId&gt;com.stackoverflow&lt;/groupId&gt;
	&lt;artifactId&gt;apache.fop.jdk14.exclude.xml-apis&lt;/artifactId&gt;
	&lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;

	&lt;properties&gt;
		&lt;maven.compiler.target&gt;14&lt;/maven.compiler.target&gt;
		&lt;maven.compiler.source&gt;14&lt;/maven.compiler.source&gt;
	&lt;/properties&gt;

	&lt;dependencies&gt;
		&lt;dependency&gt;
			&lt;groupId&gt;org.apache.xmlgraphics&lt;/groupId&gt;
			&lt;artifactId&gt;fop&lt;/artifactId&gt;
			&lt;version&gt;2.5&lt;/version&gt;
			&lt;exclusions&gt;&lt;exclusion&gt;&lt;groupId&gt;xml-apis&lt;/groupId&gt;&lt;artifactId&gt;*&lt;/artifactId&gt;&lt;/exclusion&gt;&lt;/exclusions&gt;
		&lt;/dependency&gt;
	&lt;/dependencies&gt;
&lt;/project&gt;

huangapple
  • 本文由 发表于 2020年8月11日 10:38:25
  • 转载请务必保留本文链接:https://go.coder-hub.com/63350707.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定