【问题标题】:Maven will not export runable JARMaven 不会导出可运行的 JAR
【发布时间】:2016-03-23 01:08:39
【问题描述】:

所以我在eclipse中有一个小型maven项目,如果我导出一个可运行的JAR并选择:

  • 将所需的库打包到生成的 JAR 中

它工作正常。

我应该注意,我的一个 JAR 是 maven 控制的(Univocity),另一个是本地 Oracle JDBC JAR。我想将这两个都包含在我的可运行 JAR 包中,这样我就可以将单个 JAR 部署到生产环境并使用单个命令执行它。

在我的 POM 中,我添加了 ma​​ven-assembly-plugin,当我使用 mvn 包时,我得到了一个带有 Univocity 库的 JAR,但它跳过了 Oracle JAR。

如何将 Oracle JAR 捆绑到最终输出中?

这是 POM:

<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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>
  <groupId>au.com.myco</groupId>
  <artifactId>MyCoOracleExtractor</artifactId>
  <version>0.0.4</version>
  <packaging>jar</packaging>

  <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.8</maven.compiler.source>
        <maven.compiler.target>1.8</maven.compiler.target>
        <univocity.version>2.0.0</univocity.version>
  </properties>  

  <dependencies>
    <dependency>
      <groupId>oracle.jdbc</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0.4</version>
      <type>jar</type>
      <scope>system</scope>
      <systemPath>${project.basedir}/lib/ojdbc6-11.2.0.4.jar</systemPath>
    </dependency>
    <dependency>
      <groupId>com.univocity</groupId>
      <artifactId>univocity-parsers</artifactId>
      <version>${univocity.version}</version>
      <type>jar</type>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>4.12</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.3</version>
        <configuration>
          <source>${maven.compiler.source}</source>
          <target>${maven.compiler.target}</target>
        </configuration>
      </plugin>
        <plugin>
          <artifactId>maven-assembly-plugin</artifactId>
        <executions>
                <execution>
                  <id>assembly:package</id>
                  <phase>package</phase>
                  <goals>
                <goal>single</goal>
            </goals>
                  <configuration>
                    <archive>
                      <manifest>
                        <mainClass>au.com.myco.MyCoOracleExtractor</mainClass>
                      </manifest>
                    </archive>
                    <descriptorRefs>
                      <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                  </configuration>
          </execution>
        </executions>
        </plugin>
    </plugins>
  </build>
</project>

我确实尝试过使用 ma​​ven-dependency-plugin,但它没有解决将它们捆绑到单个 JAR 中的问题。

【问题讨论】:

标签: eclipse maven executable-jar


【解决方案1】:

您必须手动安装它,因为 Oracle 没有让 maven 获得他们的任何 jar:所以您必须使用命令 mvn install:install -Dfile=&lt;path to file&gt; ... 手动安装它,并将其放入您的 pom.xml 中,就像没有 @ 的任何其他依赖项一样987654322@这样的:

<dependencies>
    <dependency>
      <groupId>oracle.jdbc</groupId>
      <artifactId>ojdbc6</artifactId>
      <version>11.2.0.4</version>
    </dependency>
</dependecies>

在我的情况下:当我想在 tomcat 中部署我的应用程序时:我必须将 jar ojdbc6 直接放在 tomcat 的文件夹 lib 中。

【讨论】:

    猜你喜欢
    • 2017-08-15
    • 2014-04-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-17
    • 2015-12-21
    • 2012-11-23
    • 2013-02-21
    相关资源
    最近更新 更多