Why does my jar file run wrong in docker? - spring-boot

I have a working jar that runs fine with java -jar my-file-jar-name.jar .
However, the problems start when I try to push it into a docker container.
The container is built successfully, but when I run the container itself at 8080, I only see "Whitelabel Error Page".
I suspect that the problem is that in addition to the jar file itself, additional resources are needed, such as web pages (jsp & css).
How can I do it?
My Dockerfile
FROM openjdk
ARG JAR_FILE=target/*.jar
COPY ${JAR_FILE} app.jar
CMD ["java","-jar","/app.jar"]
P.S. I saw in one thread that web applications need war packaging, but 100 other resources say that spring boot applications are packaging by jar. Where is the truth?
I tried to change the jdk version, the way to build the archive (jar to war). The most interesting thing is that with a zero project, like helloworld, everything works. And docker runs everything just fine. However, my application is much more complex and it is the one I need to package.

Related

How to redeploy WAR inside a JBoss WildFly container?

I am trying to make my local Java development environment more lighter.
Dockerfile multi-stage steps looks like this:
MAVEN CONTAINER
build app from source code
WILDFLY CONTAINER
prepare server (data sources, drivers)
copy WAR from MAVEN
start server and deploy application
This usually takes about 1-3 minutes, even with dependencies-offline-mode.
After making some code changes I have two options - build new image (1-3 minutes) or manually build WAR and redeploy app from WildFly Administration Panel. Is there any tool to automate this?
Maybe this basic approach will be enough:
0. start local env as always
1. make some code changes
2. build WAR in MAVEN conotainer
3. copy WAR into WILDFLY container
4. enter WILDFLY container bash and redeploy using JBOSS-CLI
Are you using some Maven plugins? Bash scripts? Thank you for hints!

How to manage custom common libraries built in maven for my Application in kubernetes

I need to understand how to deal with common libraries that i have created which my Application depends upon. When i create jar for this app using maven it creates a package. But how do we maintain or configure other common libraries which are listed in pom.xml of this application?
should we have maven also as an image in the docker file?
Please explain in detail.
My current progress is explained below: I have an Application A which has other dependencies like B and C libraries which i have specified in pom.xml. When i run application A in my local system it uses local repository that i have configured in user settings for maven. SO it works fine.
So how do we maintain this in kubenetes.
The images that you use to build the containers that run on Kubernetes should contain everything that's needed to run the application.
When you create the JAR file for your application, this JAR should contain the dependencies. There are different ways to achieve this, using both Maven or Gradle. This is an example using Maven and its Apache Maven Assembly Plugin. This is another good user guide on how to achieve it.
Then, you need to create a container image that can run that JAR file, something like
FROM openjdk:8-jdk-alpine
EXPOSE 8080
WORKDIR /opt/app
CMD ["java", "-jar", "app.jar"]
COPY build/libs/app.jar /opt/app
Once this container image is published on a registry, whenever Kubernetes needs to schedule and create a container, it will just use that image: there is no need to re-compile the application and its dependencies.

Docker | How to build and deploy war file in jboss container hosted in Docker

I have a jboss image hosted in Docker, along with several others. I am able to run the jboss image and use it as container to deploy webapps.
Currently using IntelliJ to configure a Docker configuration and deploy war files directly from IntelliJ and pointing to the docker configuration within IntelliJ.
I am looking for ways by which I can deploy this war file directly in my jboss image at Docker.
Basically looking at ways to deploy war file without any IntelliJ intervention, with the use of docker-compose to build jboss image along with added war targets successfully deployed.
What sort of changes need to be done in jboss.yml file and Dockerfile for jboss image?
If you want the .war file to be integral part of your image, then you just need to add it as a file resource to your jboss deployment dir during your image assembly via dockerfile. Say your docker file goes like this:
FROM jboss/wildfly
COPY myapp.war /opt/jboss/wildfly/standalone/deployments/
Of course you need to adjust the paths to match your setup and distribution, you can for example use maven docker plugin.
Other option is just to build your server without any deployments and use jboss cli or web admin interface to deploy it. Again you can automate it via maven or RUN command in dockerfile.

Hot deploy war maven project in embedded tomcat

I have maven war project.
I know inplace. it deploys to a given server. But i want to deploy on embedded tomcat and dont want to restart everytime. just say
for first time run deploy
Then change some java class and say redeploy. All in embedded tomcat.
Is this possible ?
Could the Tomcat Maven Plugin help with this?
You can use it by using the command tomcat:run
This page describes how to set up your POM/settings to make calling the plugin easier (using a prefix vs having to use full groupId/artifactId of plugin on the command line).
Maybe you can have a look at the executable war/jar feature see http://tomcat.apache.org/maven-plugin-2/executable-war-jar.html
So that will produce a simple jar which contains tomcat classes. You will be able to simply run: java -jar pathtofile.jar.

Maven Jetty Run from Jar

Here is want I want to do. I created a maven project and configured the jetty plugin for it in eclipse...
So from Eclipse if I do run and set the maven goal there to be jetty:run it runs my project in jetty on the port specified in web.xml. Now I want to build the jar file and when I do java -jar myapp.jar it will automatically call jetty:run.
How can I do this?
If you want to package your application so that you can hand it to someone and have them run it as a standalone application without having to go through deploying a war file into a web container, then that is a different concern from doing mvn jetty:run at development time, I will call that deployment time to avoid any confusion
At deployment time, we can't assume there will be maven on the machine, thus no mvn jetty:run, and even if there was, this would not work, unless we deliver the source code to run the build as in the development environment!
A standalone web application can be packaged by bundling the jetty jars in the application war along with a Main class to start jetty programmatically, and get it to run the application war. This relies on the fact that the file and directory structure of the WAR and JAR are different, and thus there is no significant overlap between the two, which is what makes this workaround possible, and it also leaves the option of deploying the war file in a web container possible
There is a maven plugin that embeds winstone which is another lightweight servlet container
For jetty, you may start by reading Embedded Jetty 7 webapp executable with Maven

Resources