# Maven and self-hosted Gitea - how can i deploy and run app?

**URL:** <https://forum.gitea.com/t/maven-and-self-hosted-gitea-how-can-i-deploy-and-run-app/10445>\
**Category:** Actions\
**Created:** [January 19, 2025, 1:14pm UTC](https://forum.gitea.com/t/maven-and-self-hosted-gitea-how-can-i-deploy-and-run-app/10445 "2025-01-19T13:14:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![edkuksa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/edkuksa/32/6571_2.png) [@edkuksa](https://forum.gitea.com/u/edkuksa)\
**Post date:** [January 19, 2025, 1:14pm UTC](https://forum.gitea.com/t/maven-and-self-hosted-gitea-how-can-i-deploy-and-run-app/10445/1 "2025-01-19T13:14:36Z")

</div>

On my home server installed Gitea and Gitea action runner in docker. I created a pipeline for a java application, the code of which is placed in Gitea repository, the application is built without problems. Here is the pipeline code:

`name: Gitea Action Maven build`  
``on:` ` push:` ` branches: ['testbranch']``  
`jobs:`  
` build:`  
` runs-on: ubuntu-latest`  
` steps:`  
` - name: Checkout the repo`  
` uses: actions/checkout@v4`  
` - name: Set up Maven`  
` uses: stCarolas/setup-maven@v5`  
` with:`  
` maven-version: '3.9.9'`  
` - name: Set up JDK 17`  
` uses: actions/setup-java@v4`  
` with:`  
` java-version: '17'`  
` distribution: 'oracle'`  
` cache: 'maven'`  
` - name: Build with Maven`  
` run: mvn -B package --file pom.xml`

But now the questions - where can I find the assembled jar in Gitea? And how can I deploy and run the assembled application in docker on my home server?

---

<div class="post-metadata">

**Author:** ![edkuksa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/edkuksa/32/6571_2.png) [@edkuksa](https://forum.gitea.com/u/edkuksa)\
**Post date:** [February 2, 2025, 4:22pm UTC](https://forum.gitea.com/t/maven-and-self-hosted-gitea-how-can-i-deploy-and-run-app/10445/2 "2025-02-02T16:22:38Z")

</div>

The problem has been successfully solved.

---

<div class="post-metadata">

**Author:** ![Angelfish6898](https://avatars.discourse-cdn.com/v4/letter/a/ec9cab/32.png) [@Angelfish6898](https://forum.gitea.com/u/Angelfish6898)\
**Post date:** [February 9, 2025, 4:29pm UTC](https://forum.gitea.com/t/maven-and-self-hosted-gitea-how-can-i-deploy-and-run-app/10445/3 "2025-02-09T16:29:20Z")

</div>

Nice! \<3 Maybe you could share how you solved it?

---

<div class="post-metadata">

**Author:** ![Akito](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/akito/32/4774_2.png) [@Akito](https://forum.gitea.com/u/Akito)\
**Post date:** [February 12, 2025, 4:34pm UTC](https://forum.gitea.com/t/maven-and-self-hosted-gitea-how-can-i-deploy-and-run-app/10445/4 "2025-02-12T16:34:14Z")

</div>

How’d you solve it?  
…  
…  
…

---

<div class="post-metadata">

**Author:** ![edkuksa](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.gitea.com/edkuksa/32/6571_2.png) [@edkuksa](https://forum.gitea.com/u/edkuksa)\
**Post date:** [February 13, 2025, 4:48pm UTC](https://forum.gitea.com/t/maven-and-self-hosted-gitea-how-can-i-deploy-and-run-app/10445/5 "2025-02-13T16:48:15Z")

</div>

Of course, sorry for the slight delay. To solve the issue, I wrote a small pipeline and docker files, the code is below:

**maven.yml**

```auto
name: Gitea Action Maven build

on:
  push:
    branches: ['master']

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Checkout the repo
        uses: actions/checkout@v4
      - name: Set up Maven
        uses: stCarolas/setup-maven@v5
        with:
          maven-version: 3.9.9
      - name: Set up JDK 21
        uses: actions/setup-java@v4
        with:
          java-version: 21
          distribution: 'oracle'
          cache: 'maven'
      - name: Build, Test and Package with Maven
        run: mvn -B verify --file pom.xml -e
      - name: Upload artifact
        uses: actions/upload-artifact@v3
        with:
          name: app-artifact
          path: |
            target/*.jar
            Dockerfile
            docker-compose.yml
      - name: Create Maven settings.xml
        run: |
          cat <<EOF > ~/.m2/settings.xml
          <settings>
            <servers>
              <server>
                <id>gitea</id>
                <username>${{ vars.OWNER }}</username>
                <password>${{ secrets.ACCESS_TOKEN }}</password>
              </server>
            </servers>
          </settings>
          EOF
      - name: Replace {owner} in pom.xml
        run: sed -i "s/{owner}/${{ vars.OWNER }}/g" pom.xml
      - name: Deploy to Gitea Packages
        run: mvn deploy
  deploy:
    runs-on: ubuntu-latest
    needs: build
    steps:
      - name: Download artifact
        uses: actions/download-artifact@v3
        with:
          name: app-artifact
          path: artifact
      - name: Install SSH Key
        uses: shimataro/ssh-key-action@v2
        with:
          key: ${{ secrets.SSH_PRIVATE_KEY }}
          known_hosts: ${{ secrets.KNOWN_HOSTS }}
      - name: Deploy to Local Server
        run: scp -r artifact/* ${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }}:${{ vars.DEPLOY_PATH }}
      - name: Build and Run Docker Image with Docker Compose
        run: |
          ssh -T ${{ vars.DEPLOY_USER }}@${{ vars.DEPLOY_HOST }} << EOF
          cd ${{ vars.DEPLOY_PATH }}
          docker compose down
          docker compose up -d --build
          EOF

```

**Dockerfile**

```auto
FROM openjdk:21-jdk-slim
WORKDIR /app
COPY target/spring-app-*.jar spring-app.jar
EXPOSE 8080
CMD ["java", "-jar", "spring-app.jar"]

```

**docker-compose.yml**

```auto
services:
  app:
    build:
      context: .
      dockerfile: Dockerfile
    image: spring-app
    container_name: spring-app
    ports:
      - "8080:8080"
    restart: always

```

fragment of the **pom.xml**

```auto
<repositories>
        <repository>
            <id>gitea</id>
            <url>https://git.example.com/api/packages/{owner}/maven</url>
        </repository>
    </repositories>

    <distributionManagement>
        <repository>
            <id>gitea</id>
            <url>https://git.example.com/api/packages/{owner}/maven</url>
        </repository>
        <snapshotRepository>
            <id>gitea</id>
            <url>https://git.example.com/api/packages/{owner}/maven</url>
        </snapshotRepository>
    </distributionManagement>

```
