In npm we have the option to define project specific scripts in the package.json file as described here.
What is the best tool/approach to this with maven? I'd like a way to write cross-platform, reproducible scripts with minimal setup.
Example scripts and the raw commands:
Build the project into a JAR file, skipping tests, and then deploy as part of a docker-compose deployment
mvn package -Dmaven.test.skip=true
docker-compose up --build -d
Rebuild and replace the running container in the docker-compose deployment
mvn package -Dmaven.test.skip=true
docker-compose up -d --no-deps --build spring
Build the project and run tests without deploying
mvn clean install
These commands can be a pain to remember and this is a project that will be used by many students with limited maven and docker experience. So a tool that's easy to install and makes creating scripts that 'just work' when pulling the repository would be great.
Related
I am working on Spring Boot 3 project and trying to build a native image using GraalVM native build tool. I have added the native image plugin (org.graalvm.buildtools:native-maven-plugin) in pom.xml. I am confused about which of the below two commands to use to build a native jar.
mvn -f ./pom.xml -Pnative package
or
mvn -f ./pom.xml -Pnative native:compile
Both are generating the jars in the target directory and adding the graalvm-reachabilty metadata. I want to know how these 2 goals differ and which one should be used to build a native jar.
I'm new to google cloud and I need to deploy my java application there.
Currently it consists of 1 one web-module and directory structure looks like this:
clinic_project
acms-frontend
pom.xml
pom.xml
And start script:
#!/bin/bash
nohup mvn clean install
serv=acms-frontend
cd $serv
nohup mvn spring-boot:run -Dspring.profiles.active="dev" -DAUTH0_CLIENT_ID=".." -DAUTH0_CLIENT_SECRET=".." -DACMS_CRYPTO_KEY=".." -DACMS_NODE_NAME="n/a" -DACMS_POD_IP="n/a" -DACMS_POD_NAMESPACE="n/a" -DACMS_POD_NAME="n/a"
Inside web-module I have .yml file with default port and other variables.
I've installed gcloud SDK and understand how I can deploy single module application.
But how can I tell google cloud to deploy my multi-module project with commands sequence from script?
If you want to deploy multiple modules, you can do so with the following command: gcloud app deploy ~/my_app/app.yaml ~/my_app/another_service.yaml as mentioned in the gcloud app deploy documentation examples.
Make sure to add the module/service name in the app.yaml files as mentioned in this other document, otherwise you may run into some naming issues with them.
Hope you find this useful!
I have a Java Spring Boot web application that I'd like to containerize using Docker. I'm having trouble getting the mvn install command to work during the Docker build process because my project depends on some other Maven projects I've written that are installed in my local /.m2 folder but aren't available in the Maven central repository. I'd like to avoid adding these local projects to the public Maven central repository because they exist specifically to support this Spring Boot application and I'd like to keep them private.
If I wasn't using Docker, I could get around this problem by building a JAR with dependencies then deploying that .jar file. Is there any way for me to include these local dependencies in my Docker build process?
Here's the simple Dockerfile I'm trying to run:
# Step 1: Build with Maven
FROM maven:3.5-jdk-8-alpine
COPY . /usr/src/myapp
WORKDIR /usr/src/myapp
RUN mvn clean install
# Step 2: Run jar file with Java
FROM openjdk:8-alpine
WORKDIR /usr/src/myapp
COPY --from=0 /usr/src/myapp/target/myapp-1.0-SNAPSHOT.jar ./myapp.jar
ENTRYPOINT ["java", "-jar", "myapp.jar"]
I run this build command:
docker build -t myspringapp .
And it errors with the following message:
[ERROR] Failed to execute goal on project server: Could not resolve dependencies for project
com.website:myapp:jar:1.0-SNAPSHOT: The following artifacts could not be resolved:
com.website:dependency1:jar:0.1.0, com.website:dependency2:jar:0.1.0,
com.website:dependency3:jar:0.1.0:
Could not find artifact com.website:dependency1:jar:0.1.0 in central
(https://repo.maven.apache.org/maven2) -> [Help 1]
As an alternative question, can I just run the mvn clean install command on my development machine to produce the jar file then skip the whole Maven build part of the Docker image? Will my container still be able to replicate itself in an auto-scaling scenario? Do I lose anything by building the project separately from its Docker image/container?
Easiest thing to do would be to just put your .m2 directory in the Docker build context, and make sure the build stage of the Dockerfile does a COPY of .m2 to wherever the base maven image is expecting it to be. That way, the build stage doesn't need to download your private JAR files.
To answer your alternative question, yes. It's not very 12-factor, but it's definitely doable to do the JAR build outside of the Docker ecosystem, then just COPY the pre-built JAR file into the image.
I have a Spring project and a corresponding JAR file.
After i change something in one of my Java class files and run mvn package, building my Docker image of that project later is using the cached JAR.
Only if i run mvn clean package, my Docker build process does not use the cached JAR:
Step 4/6 : COPY app/target/app-${VERSION}.jar app.jar
---> 19987e6dda16
Is that expected?
Do i always have to run mvn clean package instead of mvn package after changing some code?
Setting: I inherited a project that I need to update the UI for
I have a spring boot application that has an angular front end.
If I make UI changes in the front end, code at src/main/web/, they do not appear in the application that launches when I run mvn spring-boot:run
The application refers to files in the src/main/resources/static/ instead. This folder seems to contain 'compiled` front end scripts.
Question
I am trying to recompile src/main/web/ files into the src/main/resources/static/, how do I do that?
Notes
I have tried
bower install
npm install
mvn install
mvn clean
They have grunt here. Running the grunt serve command will show my updated front end files, this, in a sense "works", but mvn spring boot runs the full application and it is necessary that this command works.
An ls of the main directory shows:
Gruntfile.js bower_components package-lock.json pom.xml src
README.md package.json swagger.json
bower.json node_modules packageOld.json target
The code is being compiled by grunt, not bower or npm or mvn.
grunt clean build