【问题标题】:Proper way to add folder to Classpath using Maven3使用 Maven3 将文件夹添加到 Classpath 的正确方法
【发布时间】:2013-09-20 18:18:42
【问题描述】:

所以我使用的是 WAS8.5,我需要在我的项目中包含 WAS 库。我试过这个...

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
      <archive>
          <manifest>
              <addDefaultImplementationEntries>true</addDefaultImplementationEntries>
              <addClasspath>true</addClasspath>
          </manifest>
          <manifestEntries>
              <Class-Path>C:\Program Files (x86)\IBM\WebSphere\AppServer\plugins</Class-Path>
              <Class-Path>C:\Program Files (x86)\IBM\WebSphere\AppServer\java\jre\lib</Class-Path>
          </manifestEntries>
      </archive>
    </configuration>
</plugin>

但我仍然看到...

错误:包 javax.jms 不存在

尽管...

二进制文件 ./plugins/javax.j2ee.jms.jar 匹配

但这似乎不适用于 mvn 包,所以我的问题是 2 折

1.) 我应该使用 mvn package 还是 mvn jar:jar,因为后者似乎无法识别我的类的存储位置。如果我应该使用 jar 如何包含源目录。

2.) 如果我使用包,如何将文件夹包含在类路径中?

【问题讨论】:

    标签: jar websphere maven-3 websphere-8


    【解决方案1】:

    我猜你说的是编译时问题而不是运行时问题。清单信息用于运行时,您正确配置它的方式使其仅对您的系统有用。 Apache Maven 是关于可预测的构建,这意味着您必须定义每个依赖项而不是定义库文件夹。 您应该“安装”所需的 jar 到您的本地存储库(安装实际上是一个副本)。 见http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html

    【讨论】:

    • 所以这就是我最终要做的,但很乏味是不是唯一的解决方案?
    • 这是最好的解决方案。所有其他技巧都是黑客,总有一天会咬你。我假设(或希望)您不会每天、每周或每月都切换到较新的版本。这是这些 jar 的一次性安装。您可以将您的情况与maven.apache.org/guides/mini/guide-coping-with-sun-jars.html进行比较
    【解决方案2】:

    我发现自动化构建而不用命令行打扰的最佳解决方案是使用 maven-install-plugin 从我的 pom.xml 安装:

            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-install-plugin</artifactId>
                <version>2.2</version>
                <executions>                    
                    <execution>
                        <id>proguard</id>
                        <inherited>false</inherited>
                        <phase>validate</phase>
                        <configuration>
                            <file>${pom.basedir}/lib/proguard-4.8.jar</file>
                            <repositoryLayout>default</repositoryLayout>
                            <groupId>net.sf.proguard</groupId>
                            <artifactId>proguard</artifactId>
                            <version>4.8</version>
                            <packaging>jar</packaging>
                            <generatePom>true</generatePom>
                        </configuration>
                        <goals>
                            <goal>install-file</goal>
                        </goals>
                    </execution>
               </plugin>
    

    所以我将我的 jar 放入 $PROJECT_HOME/lib 文件夹并将这个执行添加到验证阶段,以便在每个 maven 执行中安装它。

    这是很多文本,但它完全自动化了其他机器上的构建。

    【讨论】:

      猜你喜欢
      • 2022-12-23
      • 1970-01-01
      • 1970-01-01
      • 2013-07-04
      • 1970-01-01
      • 2021-06-27
      • 1970-01-01
      • 1970-01-01
      • 2016-07-17
      相关资源
      最近更新 更多