【问题标题】:Compiling classes with dependent jar files in maven在 maven 中编译具有依赖 jar 文件的类
【发布时间】:2018-04-05 20:00:38
【问题描述】:

我想编译一些具有多个依赖 jar 的 java 文件并制作一个 jar 文件。我将所有依赖的 jar 保存在 src/main/lib 下。运行 mvn clean install 后,我得到类的编译失败。依赖的 jar 似乎没有被复制到类路径中。任何人都可以告诉她出了什么问题。

<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>test</groupId>
    <artifactId>test</artifactId>
    <version>1.0</version>
    <repositories>
        <repository>
            <id>external-jars</id>
            <name>external-jars</name>
            <url>file://${project.basedir}\src\main\lib\</url>
        </repository>
    </repositories>
    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>jars</groupId>
                <artifactId>jars</artifactId>
                <version>1.0</version>
                <scope>system</scope>
                <systemPath>${project.basedir}/src/main/lib/*</systemPath>
            </dependency>
        </dependencies>
    </dependencyManagement>
    <build>
        <finalName>finaljar</finalName>
        <sourceDirectory></sourceDirectory>
    </build>    
</project>

【问题讨论】:

  • 你创建了 pom.xml 吗?请添加你的 pom.xml
  • Maven 不喜欢存储库之外的依赖 jar。只能使用工件形式的 jar 文件!

标签: maven jar


【解决方案1】:

你建设

<dependency>
      <groupId>jars</groupId>
      <artifactId>jars</artifactId>
      <version>1.0</version>
      <scope>system</scope>
      <systemPath>${project.basedir}/src/main/lib/*</systemPath>
</dependency>

不起作用。在 Maven 中,每个工件都通过 groupId、artifactId 和 version 寻址。您不能添加目录,只能添加单独的 jar。

虽然可以通过系统路径添加 jar,但最好使用存储库。看看

中的可能性

How to add local jar files to a Maven project?

【讨论】:

    猜你喜欢
    • 2019-05-02
    • 1970-01-01
    • 1970-01-01
    • 2011-11-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-01-03
    • 1970-01-01
    相关资源
    最近更新 更多