Maven - 使用 maven- assembly-plug 构建的 jar 并不总是可部署的

发布于 2024-08-05 13:53:48 字数 997 浏览 5 评论 0原文

我可以在本地计算机上很好地构建一个可部署的 jar,但是当尝试使用从我们的服务器构建的 jar 时,即使我手动显式调用该命令,该 jar 也不会运行。起初,它似乎不包含我在 classpath/Resources 目录中的文件,但在添加构建器帮助程序插件后,它现在正确包含它们。但是,它仍然无法运行。我想更多地了解如何调试此问题,如何识别差异以了解本地与服务器发生的情况。这是插件的相关 POM 部分

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<executions>
 <execution>
  <goals>
   <goal>attached</goal>
  </goals>
  <phase>package</phase>
  <configuration>
   <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
   </descriptorRefs>
   <archive>
    <manifest>

     <mainClass>com.medialets.service.PostEC</mainClass>
    </manifest>
   </archive>
  </configuration>
 </execution>
</executions>

如果这是一个非常简单的问题,请原谅;我对 Maven 比较陌生,在任何地方都没有找到好的答案。可能是因为它比我意识到的更基本。谢谢。

I can build a deployable jar just fine on my local machine, but when trying to use jar built off our server, even if I explicitly invoke the command by hand, the jar will not run. At first, it appeared that it wasn't including files I'd had in my classpath/Resources directory, but after adding the builder-helper plug in, it's now including them properly. However, it still won't run. I'd like to know more about how to debug this, how to identify the differences in an effort to see what's happening locally versus the server. Here's the relevant POM section for the plug in

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2-beta-4</version>
<executions>
 <execution>
  <goals>
   <goal>attached</goal>
  </goals>
  <phase>package</phase>
  <configuration>
   <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
   </descriptorRefs>
   <archive>
    <manifest>

     <mainClass>com.medialets.service.PostEC</mainClass>
    </manifest>
   </archive>
  </configuration>
 </execution>
</executions>

Pardon if this is a really simple question; I'm relatively new to maven and haven't found a good answer anywhere. Possibly because it's more fundamental than I'm realizing. Thanks.

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

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

发布评论

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

评论(2

泪之魂 2024-08-12 13:53:48

这是基于我的类似经验的猜测,如果这不是解决方案,您可以发布您的 POM 吗?它可能有助于诊断问题。

您的服务器是 *nix 机器,而您的本地计算机是 Windows 吗?如果是这样,请注意,在指定其他资源文件夹时,您应该使用斜杠而不是反斜杠作为路径分隔符。斜杠在 Windows 和 *nix 上都有效,而反斜杠在 *nix 盒子上会被默默地忽略。

因此,您的 buildhelper 配置应如下所示:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
      <execution>
        <id>add-resource</id>
        <phase>generate-resources</phase>
        <goals>
          <goal>add-resource</goal>
        </goals>
        <configuration>
          <resources>
            <resource>
              <directory>classpath/Resources</directory>
              <targetPath>/</targetPath>
            </resource>
          </resources>
        </configuration>
      </execution>
    </executions>
  </plugin>

顺便说一句,如果您可以遵循 Maven 约定,那么这样做是值得的。默认情况下,资源应位于 src/main/resources 中。某些插件无法正确处理 build-helpr 插件添加的资源。

This is a guess based on a similar experience of mine, if this is not the solution can you post your POM? it may help diagnose the issue.

Is you server a *nix box and your local machine Windows? If so be aware that when specifying the additional resources folder you should use slashes rather than backslashes for the path separator. Slashes work on both Windows and *nix, whereas backslashes are silently ignored on *nix boxes.

So your buildhelper configuration should look like this:

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>build-helper-maven-plugin</artifactId>
    <version>1.3</version>
    <executions>
      <execution>
        <id>add-resource</id>
        <phase>generate-resources</phase>
        <goals>
          <goal>add-resource</goal>
        </goals>
        <configuration>
          <resources>
            <resource>
              <directory>classpath/Resources</directory>
              <targetPath>/</targetPath>
            </resource>
          </resources>
        </configuration>
      </execution>
    </executions>
  </plugin>

As an aside, if you can follow the Maven conventions, it is worthwhile to do so. By default resources should be located in src/main/resources. Some plugins won't process resources added by the build-helpr plugin properly.

撩人痒 2024-08-12 13:53:48

You might also try running the help:effective-pom plugin to see if there are any differences in the POM that maven resolves.

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