English 中文(简体)
1. 与 Java建多克书,与《刑法》合写
原标题:Build Dockerfile with Java and maven with CodeArtifact dependency

我试图利用Docker建造我的项目,它拥有一些Java REST APIs,利用Maven和Punt Boot在一个多功能建筑上使用。 我有一个称为“共同使用”的“奴隶”模块,它拥有我所需要的所有通用实体和某些日历公用事业,这一模块被用作对我所有其他模块的依赖。

我遇到一个问题,即Docker的拖车是建起的,因为它没有发现自己的奴隶单元是依赖他人的,因为它在寻找Maven Central for it后发现,我可以人工复制这一依赖性密码<>.jar,以防cker建立.m2。 而对这种解决办法却不满意。 我然后发现,我可以把奴隶模块.jar<>/code>上载到一个私人存放处,尝试了Nexus,但由于我很快使用AWS,我转而采用AWS代码。

现在的问题是,如何把我<条码>设计书.xml<>/条码”需要从AWS以外的基础设施中打脚?

问题回答

After searching a lot I ve found a way to do this. I tried the RUN command but since it s execution can t save the result into an usable variable to be captured by settings.xml, I had to take another approach. This is my Dockerfile:

###############################################################
# Build stage
# Maven image to build the application
FROM maven:3.9.6-amazoncorretto-17-al2023 AS build-stage

# Creating the directory
RUN mkdir -p /usr/src/app
# Setting the working directory.
WORKDIR /usr/src/app
# Adding the source code to the build stage.
ADD . /usr/src/app

# And here comes the Amazon configuration step!
RUN yum install aws-cli -y
RUN aws configure set aws_access_key_id  YOUR KEY 
RUN aws configure set aws_secret_access_key  YOUR SECRET ACCESS KEY 
RUN aws configure set aws_region  YOUR REGION 
RUN aws configure set aws_output_format json

# Then I execute the command to get Code Artifact s token and save it into a file called "result" located in "./"
RUN aws codeartifact get-authorization-token --domain YOUR-DOMAIN --domain-owner YOUR-OWNER-ID --region YOUR-REGION --query authorizationToken --output text >> ./result

# So now I execute the maven install command passing the settings.xml WITH the property "token", which is a cat command to read from the file that has the token and to be used inside the XML file.
RUN mvn -Dtoken=${cat ./result} -s settings.xml install -U

###############################################################
# Production step. Now it s done, it works!
FROM openjdk:17-alpine AS production-stage
COPY --from=build-stage /usr/src/app/target/*.jar my-api.jar
EXPOSE 8788
ENTRYPOINT ["java", "-Dspring.profiles.active=prod", "-Xmx256m", "-Xms128m", "-jar", "my-api.jar"]

这是我的<代码>制定。

<?xml version="1.0" encoding="UTF-8"?>

<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0"
          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
          xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 
https://maven.apache.org/xsd/settings-1.2.0.xsd">
<servers>
  <server>
    <id>domain-name</id>
    <username>aws</username>
    <password>${token}</password>
  </server>
</servers>

<profiles>
  <profile>
  <id>domain-name</id>
  <activation>
  <activeByDefault>true</activeByDefault>
  </activation>
    <repositories>
      <repository>
           <id>domain-name</id>
           <url>repo-url</url>
      </repository>
    </repositories>
  </profile>
</profiles>
</settings>

我不敢肯定,它是否正确,但却发挥作用! 因此,我要与你分享这一信息,因为我 could爱我,想想想想如何这样做。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...