Maven 依赖项 jar 不可用

发布于 2024-07-25 16:25:23 字数 1887 浏览 8 评论 0原文

编辑:

我基本上遇到了以下记录的问题。 我正在使用 Maven 程序集插件生成一个包含我的依赖项的 jar 文件,以便我的项目可以从单个文件运行。 然而,jar 文件似乎没有正确构建。 以下是尝试解决该问题的尝试。 以前有人遇到过这个吗?

因此,我尝试构建一个 jar 文件,其中包含所有已打包的依赖项以及已解压的项目工件 jar。

我尝试做一些事情,以达到

<assembly>
  <id>jar-with-dependencies-packed</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>true</unpack>
      <unpackOptions>
          <includes>
              <include>artifactname</include>
          </includes>
      </unpackOptions>
      <scope>runtime</scope>
      <outputDirectory>lib</outputDirectory>
    </dependencySet>
  </dependencySets>
</assembly>

然而,生成的 jar 文件仅包含 META-INF 目录... 当我说解包,但仅解包我的包含时,这是否意味着原始 jar 文件不包含在内?

当我运行 jar 时,我收到以下

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace http://www.springframework.org/schema/util
Offending resource: class path resource [applicationContext.xml]

at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.fac

tory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)

EDIT:

I am basically running into the following documented issue. I am using the maven assembly plugin to generate a jar file that includes my dependencies so that my project can be run from a single file. However, the jar file is not being built properly it seems. The below was an attempt to try and work around the issue. Has anyone run into this before?

So I am trying to build a jar file that includes all of my dependencies packed and my project artifact jar unpacked.

I tried doing something to the effect of

<assembly>
  <id>jar-with-dependencies-packed</id>
  <formats>
    <format>jar</format>
  </formats>
  <includeBaseDirectory>false</includeBaseDirectory>
  <dependencySets>
    <dependencySet>
      <unpack>true</unpack>
      <unpackOptions>
          <includes>
              <include>artifactname</include>
          </includes>
      </unpackOptions>
      <scope>runtime</scope>
      <outputDirectory>lib</outputDirectory>
    </dependencySet>
  </dependencySets>
</assembly>

However, the resulting jar file includes only the META-INF directory... When I say to unpack, but unpack only my includes, does that mean the original jar files aren't included?

When I run the jar I receive the following

Exception in thread "main" java.lang.ExceptionInInitializerError
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unable to locate Spring NamespaceHandler for XML schema namespace http://www.springframework.org/schema/util
Offending resource: class path resource [applicationContext.xml]

at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:68)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:80)
at org.springframework.beans.fac

tory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:281)

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

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

发布评论

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

评论(2

花间憩 2024-08-01 16:25:23

您是否查看过 onejar-maven-plugin。 它以一种简单的方式做你想做的事。

Had you take a look at onejar-maven-plugin. It does what you want in a straightforward way.

吻风 2024-08-01 16:25:23

问题是我在 applicationContext 中使用“spring-util”命名空间。 尽管我将 spring-beans 作为项目依赖项,因此将其添加到我的类路径中,但无法解析命名空间处理程序。 由于我只使用过 util:list 一次,因此我决定将其从上下文中删除。 从那里我可以毫无问题地构建我的罐子。 我不确定真正的问题是否出在 Maven 程序集生成 jar 文件的方式中,或者是否是 Spring 问题。 不管怎样,我有一个解决方法。

The problem was that I was using the "spring-util" namespace in my applicationContext. Although I had spring-beans as a project dependency and therefore it was added to my classpath, the namespace handler could not be resolved. Since I only use the util:list on one occasion I decided to remove it from the context. From there I was able to build my jar without issue. I am not sure if the real problem is somewhere in how maven assembly is generating the jar file or if it is a spring issue. Either way, I have a workaround.

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