I
I
Ilya55272022-02-02 17:46:34
Java
Ilya5527, 2022-02-02 17:46:34

How to build a java project on maven into a jar file and put it on ubuntu server 18.04?

I'm interested in a number of questions:
1) How to properly build java on maven, taking into account all the nuances?
2) How to transfer jar file to ubuntu 18.04 server?
3) How to run jar file on server?
Thanks everyone for the replies!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
ky0, 2022-02-02
@ky0

1. The repository usually has all the necessary configs and bindings
2. Just like any other file
3.java -jar /path/to/your-file.jar

O
Orkhan, 2022-02-02
Hasanly @azerphoenix

Good afternoon.
You can deploy the application in different ways.
One possible way is docker or docker-compose.
Steps:
1 - create a Dockerfile, specify how the project should be built, what should be installed, etc.
For example,

FROM adoptopenjdk/openjdk11:jdk-11.0.10_9-alpine as build
COPY . /srv
RUN cd /srv && chmod +x mvnw && ./mvnw clean package
FROM adoptopenjdk/openjdk11:jdk-11.0.10_9-alpine
WORKDIR /srv
COPY --from=build /srv/target/{JAR_NAME}.jar /srv/{JAR_NAME}.jar
ENTRYPOINT exec java -jar /srv/{JAR_NAME}.jar

2 - upload the project to git
3 - make a git clone of this project on a remote server.
4 - run docker or docker-compose
Another simpler solution:
1 - compile the archive using maven
mvn clean package
2 - Upload the resulting archive from the target/(JAR_NAME).jar directory via scp to the server.
3 - Install jre of the appropriate version and run the project.
java -jar /srv/{JAR_NAME}.jar

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question