gpt4 book ai didi

java - Maven:自动安装外部JAR

转载 作者:行者123 更新时间:2023-12-02 19:48:05 26 4
gpt4 key购买 nike

我的项目依赖oracle jar来连接到它的数据库。由于它是一个外部jar,因此我从oracle网站下载了它,并使用

mvn install:install-file -Dfile=ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar

在本地运行 maven clean package可以正常运行,因为已经安装了 ojdbc.jar

但是,现在我将 build步骤移到 Docker图片。
from alpine/git as clone
workdir /app
run git clone --single-branch -b master https://github.com/xxxxxxxx

from maven:3.5-jdk-8-alpine
workdir /app
copy --from=0 /app/idot/idot-backend /app
run mvn clean install -T 1C -DskipTests

from openjdk:8-jre-alpine
workdir /app
copy --from=build /app/target/idot-0.0.1-SNAPSHOT.jar /app
cmd ["java -jar idot-0.0.1-SNAPSHOT.jar"]

由于不存在外部jar,因此此步骤在 build期间明显失败。因此,为了删除依赖项,我编辑了 pom.xml以包括
<repositories>
<repository>
<id>local-maven-repo</id>
<url>file://${project.basedir}/libs</url>
</repository>
</repositories>

和下面的依赖仍然像以前一样
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc8</artifactId>
<version>12.2.0.1</version>
</dependency>

然后使用以下命令部署jar文件
 mvn deploy:deploy-file -Dfile=ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Durl=file:./libs/ -DrepositoryId=local-maven-repo

这将创建一个 libs文件夹,其中包含 ojdbc8-12.2.0.1.jar和其他元信息。我在 github中检查此文件夹

现在,当尝试构建 docker图像时,它会失败,并显示以下错误消息。

...
...



Downloaded from central: https://repo.maven.apache.org/maven2/org/liquibase/liquibase-parent/3.6.3/liquibase-parent-3.6.3.pom (31 kB at 39 kB/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/oracle/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.pom
[WARNING] The POM for com.oracle:ojdbc8:jar:12.2.0.1 is missing, no dependency information available
Downloading from central: https://repo.maven.apache.org/maven2/org/modelmapper/modelmapper/2.3.2/modelmapper-2.3.2.pom




  Downloaded from central: https://repo.maven.apache.org/maven2/org/atteo/evo-inflector/1.2.2/evo-inflector-1.2.2.jar (13 kB at 138 B/s)
Downloading from central: https://repo.maven.apache.org/maven2/com/oracle/ojdbc8/12.2.0.1/ojdbc8-12.2.0.1.jar
Downloading from central: https://repo.maven.apache.org/maven2/org/modelmapper/modelmapper/2.3.2/modelmapper-2.3.2.jar




  Downloaded from central: https://repo.maven.apache.org/maven2/com/google/guava/guava/20.0/guava-20.0.jar (2.4 MB at 12 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/io/springfox/springfox-swagger-ui/2.9.2/springfox-swagger-ui-2.9.2.jar (2.9 MB at 14 kB/s)
Downloaded from central: https://repo.maven.apache.org/maven2/net/bytebuddy/byte-buddy/1.9.12/byte-buddy-1.9.12.jar (3.3 MB at 14 kB/s)
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 07:13 min (Wall Clock)
[INFO] Finished at: 2020-06-17T11:19:56Z
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal on project idot: Could not resolve dependencies for project com.novartis:idot:jar:0.0.1-SNAPSHOT: Could not find artifact com.oracle:ojdbc8:jar:12.2.0.1 in local-maven-repo (file:///app/libs) -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/DependencyResolutionException
The command '/bin/sh -c mvn clean install -T 1C -DskipTests' returned a non-zero code: 1

最佳答案

除了麻烦之外,我还在docker文件中添加了相同的安装命令。现在可以正常工作了。

from alpine/git as clone
workdir /app
run git clone --single-branch -b master https://@github.com/xxxx

from maven:3.5-jdk-8-alpine
workdir /app
copy --from=0 /app/idot/idot-backend /app
run mvn install:install-file -Dfile=/app/ojdbc8.jar -DgroupId=com.oracle -DartifactId=ojdbc8 -Dversion=12.2.0.1 -Dpackaging=jar
run mvn clean install -T 1C -DskipTests

from openjdk:8-jre-alpine
workdir /app
copy --from=build /app/target/idot-0.0.1-SNAPSHOT.jar /app
cmd ["java -jar idot-0.0.1-SNAPSHOT.jar"]

关于java - Maven:自动安装外部JAR,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62428045/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com