Azure - Startup command - Unable to access jarfile app.jar - java

I have a Java Spring Boot application which is deployed on an Azure Webservice, it's all working. What I really want to do at this moment is the following:
"java -jar -Dspring.profiles.active=test app.jar", I want to run the application based on that command via the imput field (startup command) on Azure Cloud, see next image:
The problem is that it gives me the following error: Unable to access jarfile app.jar, I find this information in the logs.

I had to set the Startup Command to
java -jar /home/site/wwwroot/app.jar --server.port=80
for my Linux based WebApp service to pick up the jar properly and start my Spring Boot 2.2 application. Note the path is absolute and starts from /home, I found that info here: https://learn.microsoft.com/en-us/azure/app-service/faq-app-service-linux#built-in-images.

Related

Unable to deploy EAR file to Azure App Service using JBOSS EAP 7

I am unable to deploy EAR file into Azure App Service with JBOSS EAP 7.3.6.
I tried following steps as described in the documentation found at this link.
Out of given 4 options, allowed to use either Azure CLI or Kudu API since EAR is not supported by Azure Powershell and Kudu UI not supporting any.
Using Azure CLI, tried executing following command.,
az webapp deploy --resource-group test-rg --name dmap --src-path C:\Users\HP\Desktop\DMAP.ear
Getting error as
CommandNotFoundError: 'deploy' is misspelled or not recognized by the system.
Did you mean 'deployment' ?
Still stuck? Run 'az webapp --help' to view all commands or go to
'https://learn.microsoft.com/en-us/cli/azure/reference-index?view=azure-cli-latest' to learn
more
Using Kudu API, tried executing following command.,
curl -X POST -u dmap --data-binary #"C:\Users\HP\Desktop\DMAP.ear" https://dmap.scm.azurewebsites.net/api/publish&type=ear
Getting response as
The system cannot find the file specified.
Searching for this response, I found this link where it comes for successful deployment too. Assuming it I tried to access my application using link https://dmap.azurewebsites.net/DMAPWeb. But it shows nothing found.
To verify the deployment, I checked folder /site/wwwroot using FTP but I don't see any files deployed.
Could you please guide me here and clarify where I am wrong.
We have tested this in our local environment it is working fine. Below statements are based on our analysis.
Using the Below Azure CLI cmdlet , we have tried deploying the .ear file from local machine to web app (deployed in azure ) operation got succeeded without any issues.
Here is the cmdlet we have used :
az webapp deploy --resource-group <rgName> --name <webAppName> --src-path c:\Users\Downloads\<fileName>.ear ##Path of .ear file
Here is the Sample output for reference:
Note:
If you are deploying from local machine run the az.cmd(AzureCLI) in admin mode. By default az.cmd will be under the path c:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin in your local machine.

Springboot standalone application deploy in production

I am trying to deploy my springboot standalone application in production in linux server.I am trying to use the out of the box tomcat server.
'java -jar jarname.jar'
This works fine , but if I close my putty session the application is unistalled.
Now I used
'nohup java -jar jarname.jar &'
this works good and my application is not shutdown even if my putty session is closed.But the logs will not roll correctly(I have configured log4j to create a new log file for each day) in this case. So was wondering if this is the right way to do this.
I have searched several documentation but was not able to find a correct solution for this problem.
Please help.
Thanks
Well I think it's better to use Linux services for running application, you can read here for example
And if you want to collect logs - better write them to the file.
Spring provides build-in me mechanics to do that
logging:
level:
root: INFO
file:
clean-history-on-start: false
max-history: 7
max-size: 10MB
name: some-name
path: /path/log/dir
total-size-cap: 0B
Why not package it into a Docker image and run that on the server?
Here are a few ideas:
https://medium.com/swlh/deploying-spring-boot-applications-15e14db25ff0
You can run your spring boot application as jar, but you need to create a service so you can execute your spring boot as daemon.
https://dzone.com/articles/run-your-java-application-as-a-service-on-ubuntu
With this, you can start or stop your application like
$ sudo service myspringbootapp stop
$ sudo service myspringbootapp start

How to start executable spring boot jar file with external *.ampl on Linux?

I have spring boot application with executable jar-file
So, I tried to start to from cmd in windows by command
java -jar -Dspring.config.location="application.yaml" MyService.jar
and it sucessfully started
(I try to use external application.yaml to start my application)
In my application all properties.yaml like datebase mocked like this
url: ${DATA_BASE_URL}
and external yaml contains all values.
But, when I try to start application using this command on centOS (or other linux), there is fail when try to start, spring boot used ${DATA_BASE_URL} instead external application.yaml values.
How to fix it?
On linux I used
nohup java -jar -Dspring.config.location="application.yaml" MyService.jar
According to the official documentation https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-features-external-config-application-property-files
you should use double dashes
nohup java -jar --spring.config.location="application.yaml" MyService.jar

How to link custom script to spring boot jar?

I have created a symlink for a spring boot executable jar and i am able to start the application. I want to customize the logs path, pid folder etc.
Went through the customizing the startup of this script.
But I could not find where to store the custom script and how it can be linked to executable application jar. Could you please assist?
Create a script with name your-app.service, place this script in /etc/systemd/system directory.
Installation as a systemd Service, using Java System Properties (VM Arguments):
[Unit]
Description= Spring Boot App
After=syslog.target
[Service]
User=myapp
ExecStart=java -Dspring.application.name=example -Dlogging.file=/opt/spring-boot-app/log/app.log -Dspring.pid.file=/opt/spring-boot-app/app.pid -jar /opt/spring-boot-app/app.jar
SuccessExitStatus=200
[Install]
WantedBy=multi-user.target
Or pass throught via program arguments:
java -jar /opt/spring-boot-app/app.jar --spring.application.name=example --logging.file=/opt/spring-boot-app/log/app.log --spring.pid.file=/opt/spring-boot-app/app.pid
References in here and here.
logging.file= # Log file name (for instance, myapp.log). Names can
be an exact location or relative to the current directory.
spring.pid.file= # Location of the PID file to write (if
ApplicationPidFileWriter is used).

Sprin Boot apps no log dir created by running it throgh a remote ssh command

I try to deploy the sprin boot jar file into a remote Linux server and run it throw java -jar command.
The command was much like below:
ssh root#xxx.com:/myjdk_path/bin/java -jar /tmp/target.jar
The problem is that there was no any log dir been created while i running the command.
The sprin boot app was created by the spring.io site,it's a normal app then i put one single line "logging.file=./log/my.log" into application.properties.
But it works(the log dir can be created) when i just logged into the target server and type the command in the ssh console.
The sprin boot version is 2.05 and i've test version 1.5.16 still the same.
And i aslo test it in both Ubuntu and Centos servers,nothing haapens too.
Really appreciate if you can give a clue on this!
Thanks all you guys , it turns out my fault, the reason is that I am using a relative log path ,and I run that java -jar command out side the shell directory.
old command:ssh root#xxx.com:/myjdk_path/bin/java -jar /tmp/target.jar
new command:ssh root#xxx.com:cd /tmp; /myjdk_path/bin/java -jar target.jar
the log dir was been created for the old command ,but it in the user home path(for this command is the ROOT user),but not in the /tmp path.
so my stupid check steps missing that point,and thought there is no log dir been created!

Categories