如果我在依赖关系树中看不到它,如何从 Maven 中排除它?

Posted

技术标签:

【中文标题】如果我在依赖关系树中看不到它,如何从 Maven 中排除它?【英文标题】:How to exclude the library from Maven if I do not see it in the dependency tree? 【发布时间】:2021-05-05 23:40:53 【问题描述】:

在我的项目中使用 jar 库时出现此错误:org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory。我的项目是 Maven,但库本身可能不是。我已将其安装到本地 Maven 存储库中并将其作为依赖项包含在内:

<dependency>
  <groupId>org.misclient</groupId>
  <artifactId>misclient</artifactId>
  <version>1.0</version> 
  <scope>compile</scope>
</dependency>

我的 Maven 依赖树:

[INFO] com.softgile:asan:atlassian-plugin:1.0.1-SNAPSHOT
[INFO] +- com.atlassian.jira:jira-api:jar:8.12.0:provided
[INFO] |  +- com.atlassian.annotations:atlassian-annotations:jar:2.1.0:provided
[INFO] |  |  \- com.google.code.findbugs:jsr305:jar:3.0.0:provided
[INFO] |  +- com.atlassian.ofbiz:entityengine-share:jar:1.5.0:provided
[INFO] |  |  \- xerces:xercesImpl:jar:2.12.0:provided
[INFO] |  |     \- xml-apis:xml-apis:jar:1.4.01:provided
[INFO] |  +- com.atlassian.ofbiz:entityengine:jar:1.5.0:provided
[INFO] |  |  \- jta:jta:jar:1.0.1:provided
[INFO] |  +- com.atlassian.collectors:atlassian-collectors-util:jar:1.1:provided
[INFO] |  +- opensymphony:webwork:jar:1.4-atlassian-30:provided
[INFO] |  |  \- com.atlassian.html:atlassian-html-encoder:jar:1.4:provided
[INFO] |  +- webwork:pell-multipart-request:jar:1.31.0:provided
[INFO] |  +- com.atlassian.core:atlassian-core:jar:7.0.2:provided
[INFO] |  |  +- dom4j:dom4j:jar:1.6.1-atlassian-2:provided
[INFO] |  |  \- com.atlassian.image:atlassian-image-consumer:jar:1.0.1:provided
[INFO] |  +- com.atlassian.core:atlassian-core-user:jar:7.0.2:provided
[INFO] |  +- com.atlassian.core:atlassian-core-thumbnail:jar:7.0.2:provided
[INFO] |  |  +- com.twelvemonkeys.imageio:imageio-jpeg:jar:3.4.1:provided
[INFO] |  |  |  +- com.twelvemonkeys.imageio:imageio-core:jar:3.4.1:provided
[INFO] |  |  |  +- com.twelvemonkeys.imageio:imageio-metadata:jar:3.4.1:provided
[INFO] |  |  |  +- com.twelvemonkeys.common:common-lang:jar:3.4.1:provided
[INFO] |  |  |  +- com.twelvemonkeys.common:common-io:jar:3.4.1:provided
[INFO] |  |  |  \- com.twelvemonkeys.common:common-image:jar:3.4.1:provided
[INFO] |  |  \- com.twelvemonkeys.imageio:imageio-tiff:jar:3.4.1:provided
[INFO] |  +- com.atlassian.extras:atlassian-extras:jar:3.2:provided
[INFO] |  +- com.atlassian.velocity:atlassian-velocity:jar:1.3:provided
[INFO] |  |  +- opensymphony:oscore:jar:2.2.7:provided
[INFO] |  |  \- org.apache.velocity:velocity:jar:1.6.4:provided
[INFO] |  +- osworkflow:osworkflow:jar:2.9.0-atlassian-1:provided
[INFO] |  +- opensymphony:propertyset:jar:1.5:provided
[INFO] |  +- com.atlassian.cache:atlassian-cache-api:jar:4.0.2:provided
[INFO] |  |  +- com.atlassian.instrumentation:atlassian-instrumentation-core:jar:3.0.0:provided
[INFO] |  |  \- io.atlassian.util.concurrent:atlassian-util-concurrent:jar:4.0.1:provided
[INFO] |  +- com.atlassian.beehive:beehive-api:jar:4.0.2:provided
[INFO] |  +- com.atlassian.tenancy:atlassian-tenancy-api:jar:3.0.1:provided
[INFO] |  |  \- com.atlassian.event:atlassian-event:jar:4.0.0:provided
[INFO] |  +- com.atlassian.upgrade:upgrade-task-framework-api:jar:2.0.2:provided
[INFO] |  +- com.atlassian.crowd:embedded-crowd-api:jar:4.0.2:provided
[INFO] |  +- com.google.guava:guava:jar:26.0-jre:provided
[INFO] |  |  +- org.checkerframework:checker-qual:jar:2.5.2:provided
[INFO] |  |  +- com.google.errorprone:error_prone_annotations:jar:2.1.3:provided
[INFO] |  |  +- com.google.j2objc:j2objc-annotations:jar:1.1:provided
[INFO] |  |  \- org.codehaus.mojo:animal-sniffer-annotations:jar:1.14:provided
[INFO] |  +- com.atlassian.fugue:fugue:jar:2.7.0:provided
[INFO] |  +- io.atlassian.fugue:fugue:jar:4.7.2:provided
[INFO] |  +- org.codehaus.jackson:jackson-core-asl:jar:1.9.13-atlassian-4:provided
[INFO] |  +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.13-atlassian-4:provided
[INFO] |  +- com.sun.mail:jakarta.mail:jar:1.6.5:provided
[INFO] |  |  \- com.sun.activation:jakarta.activation:jar:1.2.1:provided
[INFO] |  +- com.atlassian.mail:atlassian-mail:jar:5.0.3:provided
[INFO] |  |  +- commons-beanutils:commons-beanutils:jar:1.6.1:provided
[INFO] |  |  \- commons-digester:commons-digester:jar:1.4.1:provided
[INFO] |  +- oro:oro:jar:2.0.7:provided
[INFO] |  +- com.atlassian.threadlocal:atlassian-threadlocal:jar:1.3:provided
[INFO] |  +- com.atlassian.applinks:applinks-api:jar:8.0.0:provided
[INFO] |  +- com.google.javascript:closure-compiler-unshaded:jar:v20181008:provided
[INFO] |  |  +- com.google.javascript:closure-compiler-externs:jar:v20181008:provided
[INFO] |  |  +- args4j:args4j:jar:2.0.26:provided
[INFO] |  |  +- com.google.protobuf:protobuf-java:jar:3.0.2:provided
[INFO] |  |  \- com.google.jsinterop:jsinterop-annotations:jar:1.0.0:provided
[INFO] |  +- com.atlassian.velocity.htmlsafe:velocity-htmlsafe:jar:3.1.0:provided
[INFO] |  +- com.atlassian.plugins:atlassian-plugins-api:jar:5.3.7:provided
[INFO] |  +- com.atlassian.plugins:atlassian-plugins-webfragment:jar:5.0.0:provided
[INFO] |  +- com.atlassian.plugins:atlassian-plugins-webfragment-api:jar:5.0.0:provided
[INFO] |  +- com.atlassian.ozymandias:atlassian-plugin-point-safety:jar:1.0.0:provided
[INFO] |  +- jfree:jfreechart:jar:1.0.13:provided
[INFO] |  +- com.atlassian.plugins:atlassian-plugins-webresource:jar:4.1.3:provided
[INFO] |  |  +- com.atlassian.plugins:atlassian-plugins-webresource-spi:jar:4.1.3:provided
[INFO] |  |  +- com.atlassian.plugins:atlassian-plugins-webresource-api:jar:4.1.3:provided
[INFO] |  |  +- org.tuckey:urlrewritefilter:jar:4.0.4:provided
[INFO] |  |  \- com.atlassian.sourcemap:sourcemap:jar:1.7.6:provided
[INFO] |  +- com.atlassian.plugins:atlassian-plugins-webresource-compiler-gcc:jar:4.1.3:provided
[INFO] |  +- jfree:jcommon:jar:1.0.8:provided
[INFO] |  +- com.atlassian.gadgets:atlassian-gadgets-api:jar:5.0.0:provided
[INFO] |  +- com.atlassian.johnson:atlassian-johnson-core:jar:4.0.0:provided
[INFO] |  |  \- com.atlassian.plugins:atlassian-plugins-servlet:jar:5.0.0:provided
[INFO] |  +- joda-time:joda-time:jar:2.10.5:provided
[INFO] |  +- commons-lang:commons-lang:jar:2.6:provided
[INFO] |  +- org.apache.commons:commons-lang3:jar:3.8:provided
[INFO] |  +- commons-io:commons-io:jar:2.6:provided
[INFO] |  +- commons-httpclient:commons-httpclient:jar:3.1-atlassian-2:provided
[INFO] |  +- log4j:log4j:jar:1.2.17-atlassian-2:provided
[INFO] |  +- com.atlassian.profiling:atlassian-profiling:jar:3.2.0:provided
[INFO] |  +- com.atlassian.scheduler:atlassian-scheduler-api:jar:3.0.0:provided
[INFO] |  +- com.atlassian.analytics:analytics-api:jar:6.1.6:provided
[INFO] |  +- com.atlassian.application:atlassian-application-api:jar:2.0.0:provided
[INFO] |  +- javax.validation:validation-api:jar:2.0.1.Final:provided
[INFO] |  \- com.atlassian:lucene-extras:jar:7.3.1-atlassian-4:provided
[INFO] +- junit:junit:jar:4.10:test
[INFO] |  \- org.hamcrest:hamcrest-core:jar:1.1:test
[INFO] +- com.atlassian.plugin:atlassian-spring-scanner-annotation:jar:1.2.13:provided
[INFO] +- javax.inject:javax.inject:jar:1:provided
[INFO] +- com.atlassian.plugins:atlassian-plugins-osgi-testrunner:jar:2.0.1:test
[INFO] +- javax.ws.rs:jsr311-api:jar:1.1.1:provided
[INFO] +- com.google.code.gson:gson:jar:2.2.2-atlassian-1:compile
[INFO] +- org.mockito:mockito-all:jar:1.8.5:test
[INFO] +- javax.servlet:servlet-api:jar:2.4:provided
[INFO] +- javax.xml.bind:jaxb-api:jar:2.3.1:provided
[INFO] |  \- javax.activation:javax.activation-api:jar:1.2.0:provided
[INFO] +- com.atlassian.plugins.rest:atlassian-rest-common:jar:1.0.2:provided
[INFO] |  +- com.atlassian.plugins.rest:com.atlassian.jersey-library:pom:1.0.2:provided
[INFO] |  |  +- com.sun.jersey:jersey-server:jar:1.0.3:provided
[INFO] |  |  |  +- com.sun.jersey:jersey-core:jar:1.0.3:provided
[INFO] |  |  |  \- asm:asm:jar:3.1:provided
[INFO] |  |  +- com.sun.jersey:jersey-json:jar:1.0.3:provided
[INFO] |  |  |  +- org.codehaus.jettison:jettison:jar:1.0.1:provided
[INFO] |  |  |  \- org.codehaus.jackson:jackson-asl:jar:0.9.4:provided
[INFO] |  |  \- commons-fileupload:commons-fileupload:jar:1.2.1:provided
[INFO] |  \- net.sourceforge.findbugs:jsr305:jar:1.3.2:provided
[INFO] +- com.atlassian.sal:sal-api:jar:3.0.7:provided
[INFO] +- org.apache.wink:wink-client:jar:1.4:test
[INFO] |  +- org.apache.wink:wink-common:jar:1.4:test
[INFO] |  |  +- org.apache.geronimo.specs:geronimo-jaxrs_1.1_spec:jar:1.0:test
[INFO] |  |  \- org.apache.geronimo.specs:geronimo-annotation_1.1_spec:jar:1.0:test
[INFO] |  +- com.sun.xml.bind:jaxb-impl:jar:2.2.1.1:provided
[INFO] |  \- javax.activation:activation:jar:1.1:test
[INFO] +- org.slf4j:slf4j-api:jar:1.6.6:provided
[INFO] +- org.apache.httpcomponents:httpclient:jar:4.1.1:test
[INFO] |  +- org.apache.httpcomponents:httpcore:jar:4.1:test
[INFO] |  +- commons-logging:commons-logging:jar:1.1.1:test
[INFO] |  \- commons-codec:commons-codec:jar:1.4:provided
[INFO] +- com.atlassian.templaterenderer:atlassian-template-renderer-api:jar:2.0.0:provided
[INFO] |  \- commons-collections:commons-collections:jar:3.2.1:provided
[INFO] +- org.misclient:misclient:jar:1.0:compile
[INFO] +- com.atlassian.aui:auiplugin:jar:8.0.0:provided
[INFO] +- com.atlassian.upm:licensing-api:jar:2.21.4:provided
[INFO] \- com.atlassian.upm:upm-api:jar:2.21:provided

我正在使用并给出错误的库是org.misclient:misclient:jar:1.0:compile


2021-02-01 18:59:05,017+0100 http-nio-8080-exec-12 ERROR seyid.a 1139x8875x1 7rxlsq 5.197.138.80,127.0.0.1 /rest/asanrest/1.0/message/getAdocInfo [c.a.p.r.c.error.jersey.ThrowableExceptionMapper] Uncaught exception thrown by REST service: Exception from underlying library
ee.cyber.asanimza.toolkit.MisServiceException: Exception from underlying library
        at ee.cyber.asanimza.toolkit.SignedContainer.loadFromBytesArray(SignedContainer.java:202)
        at com.softgile.misclient.MisServiceMethods.getInfoFromContainer(MisServiceMethods.java:229)
        at com.softgile.rest.AsanRest.getAdocInfo(AsanRest.java:141)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
        ... 1 filtered
        at java.lang.reflect.Method.invoke(Method.java:498)
        ... 19 filtered
        at com.atlassian.plugins.rest.module.RestDelegatingServletFilter$JerseyOsgiServletContainer.doFilter(RestDelegatingServletFilter.java:160)
        ... 1 filtered
        at com.atlassian.plugins.rest.module.RestDelegatingServletFilter.doFilter(RestDelegatingServletFilter.java:70)
        ... 32 filtered
        at com.atlassian.servicedesk.internal.web.ExternalCustomerLockoutFilter.doFilter(ExternalCustomerLockoutFilter.java:55)
        ... 8 filtered
        at com.atlassian.jira.plugin.mobile.web.filter.MobileAppRequestFilter.doFilter(MobileAppRequestFilter.java:59)
        ... 4 filtered
        at com.atlassian.jira.plugin.mobile.login.MobileLoginSuccessFilter.doFilter(MobileLoginSuccessFilter.java:54)
        ... 3 filtered
        at com.atlassian.diagnostics.internal.platform.monitor.http.HttpRequestMonitoringFilter.doFilter(HttpRequestMonitoringFilter.java:55)
        ... 8 filtered
        at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
        ... 43 filtered
        at com.atlassian.ratelimiting.internal.filter.RateLimitFilter.doFilter(RateLimitFilter.java:73)
        ... 17 filtered
        at com.atlassian.jira.security.JiraSecurityFilter.lambda$doFilter$0(JiraSecurityFilter.java:66)
        ... 1 filtered
        at com.atlassian.jira.security.JiraSecurityFilter.doFilter(JiraSecurityFilter.java:64)
        ... 16 filtered
        at com.atlassian.plugins.rest.module.servlet.RestSeraphFilter.doFilter(RestSeraphFilter.java:38)
        ... 19 filtered
        at com.atlassian.jira.servermetrics.CorrelationIdPopulatorFilter.doFilter(CorrelationIdPopulatorFilter.java:30)
        ... 5 filtered
        at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.lambda$invokeFilterChain$0(CustomerContextSettingFilter.java:215)
        at com.atlassian.servicedesk.internal.api.util.context.ReentrantThreadLocalBasedCodeContext.rteInvoke(ReentrantThreadLocalBasedCodeContext.java:136)
        at com.atlassian.servicedesk.internal.api.util.context.ReentrantThreadLocalBasedCodeContext.runOutOfContext(ReentrantThreadLocalBasedCodeContext.java:89)
        at com.atlassian.servicedesk.internal.utils.context.CustomerContextServiceImpl.runOutOfCustomerContext(CustomerContextServiceImpl.java:47)
        at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.outOfCustomerContext(CustomerContextSettingFilter.java:206)
        at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilterImpl(CustomerContextSettingFilter.java:134)
        at com.atlassian.servicedesk.internal.web.CustomerContextSettingFilter.doFilter(CustomerContextSettingFilter.java:123)
        ... 4 filtered
        at com.atlassian.jwt.internal.servlet.JwtAuthFilter.doFilter(JwtAuthFilter.java:37)
        ... 8 filtered
        at com.atlassian.ratelimiting.internal.filter.RateLimitPreAuthFilter.doFilter(RateLimitPreAuthFilter.java:71)
        ... 3 filtered
        at com.atlassian.web.servlet.plugin.request.RedirectInterceptingFilter.doFilter(RedirectInterceptingFilter.java:21)
        ... 4 filtered
        at com.atlassian.web.servlet.plugin.LocationCleanerFilter.doFilter(LocationCleanerFilter.java:36)
        ... 7 filtered
        at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:239)
        at net.bull.javamelody.MonitoringFilter.doFilter(MonitoringFilter.java:215)
        at net.bull.javamelody.PluginMonitoringFilter.doFilter(PluginMonitoringFilter.java:88)
        at net.bull.javamelody.JiraMonitoringFilter.doFilter(JiraMonitoringFilter.java:137)
        ... 22 filtered
        at com.atlassian.jira.servermetrics.MetricsCollectorFilter.doFilter(MetricsCollectorFilter.java:25)
        ... 25 filtered
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
        at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.ClassCastException: org.apache.xerces.jaxp.SAXParserFactoryImpl cannot be cast to javax.xml.parsers.SAXParserFactory
        at javax.xml.parsers.SAXParserFactory.newInstance(Unknown Source)
        at ee.sk.digidoc.factory.SAXDigiDocFactory.readSignedDocOfType(SAXDigiDocFactory.java:342)
        at ee.sk.digidoc.factory.SAXDigiDocFactory.readSignedDocOfType(SAXDigiDocFactory.java:489)
        at ee.cyber.asanimza.toolkit.SignedContainer.loadFromBytesArray(SignedContainer.java:197)
        ... 287 more

我添加了 2 个排除项来摆脱 xerces:xercesImpl 和 xml-apis:xml-apis,

            <exclusions>
                <exclusion>
                    <groupId>xerces</groupId>
                    <artifactId>xercesImpl</artifactId>
                </exclusion>
                <exclusion>
                    <groupId>xml-apis</groupId>
                    <artifactId>xml-apis</artifactId>
                </exclusion>
            </exclusions>

但仍然得到同样的错误。还有什么与 SAXParserFactory 相关的吗?

谁能帮我解决这个问题?

【问题讨论】:

你能提供图书馆的链接吗? xerces.apache.org/xerces-j/apiDocs/org/apache/xerces/jaxp/… 这个类实际上实现了 javax.xml.parsers.SAXParserFactory,所以你的错误似乎是由于 OSGi 规则造成的。这个问题似乎很相似:***.com/questions/45638091/… 是的,很相似,但是现在应该怎么解决呢?我应该导入哪些包以及排除哪些包? 【参考方案1】:

我认为您不应该排除 SAXParser 并尝试将它包含在您的库中(因为您使用提供的库 xerces:xercesImpl:jar:2.12.0:provided)。如果您可以访问它的代码,则可以将 SAXParser 类包含(组装)到 misclient jar 中,或者更改 xerces 的版本。您也可以将所有库组装在一起 misclient + xerces + yourone。

How to force the dependency to include an artifact with a specific version number

    <dependencyManagement>
     <dependencies>
      <dependency>
        <groupId>com.google.gwt</groupId>
        <artifactId>gwt</artifactId>
        <version>2.7.0</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
     </dependencies>
    </dependencyManagement>

也许你可以通过这个包含所需的库

【讨论】:

很遗憾,我们无权修改 misclient jar 的代码。我尝试使用该解决方案强制依赖项包含具有特定版本号的工件:&lt;dependencyManagement&gt; &lt;dependencies&gt; &lt;dependency&gt; &lt;groupId&gt;xerces&lt;/groupId&gt; &lt;artifactId&gt;xercesImpl&lt;/artifactId&gt; &lt;version&gt;2.12.0&lt;/version&gt; &lt;type&gt;pom&lt;/type&gt; &lt;scope&gt;import&lt;/scope&gt; &lt;/dependency&gt; &lt;/dependencies&gt; &lt;/dependencyManagement&gt; 也不起作用,同样的错误 但是为什么您使用与(由应用程序服务器)提供的相同版本的 xerces 呢?据我了解,它不适用于错误客户?我会尝试使用 javax.xml.parsers.SAXParserFactory 类/包来查找 xerces 版本 是的,我只是不知道我需要使用的版本。我怎么知道 misclient 的版本?我在那个 jar 文件中找不到任何版本信息。

以上是关于如果我在依赖关系树中看不到它,如何从 Maven 中排除它?的主要内容,如果未能解决你的问题,请参考以下文章

为啥我在 Dev-C++ 中看不到项目文件?

如何理解 Maven 依赖树

如何从maven存储库中清除旧的依赖项?

Maven查看JAR包的依赖关系

在 Maven 中查看依赖树?

一文带你弄懂 Maven 拉包原理