I have a Spring Boot application and I'm runnig it java -jar command on CMD. But I need to use external config file that is application.properties in C:\ folder. To do this I'm running the application with this command:
java -jar app.jar --spring.config.name=application --spring.config.location=file:///C:/
But command doesn't cares the spring.config.location property and application.properties file can't be found. Because of this the application not working.
How can I run the app with spring.config.name and spring.config.location parameters in Windows CMD?
On Linux you should use file://sample-app/application.yml
On Windows you should use file:///C:/sample-app/application.yml
You try placing the jar and application.properties files in same folder and run java -jar yourapplication.jar
See if it works.
Related
I have an application in spring-boot 2.2.4
When I launch the application like this :
java -jar ../batch-pj-clean-nas/target/batch-pj-clean-nas-1.0.0-SNAPSHOT.jar -Dconfig.location=application.properties
Everything is ok.
When I try like that :
su - sbert -c "java -jar /home/sbert/workspace/pj/batch-pj-clean-nas/target/batch-pj-clean-nas-1.0.0-SNAPSHOT.jar -Dconfig.location=application.properties"
the properties is not loaded
Could not resolve placeholder 'nas.base.directory' in value "${nas.base.directory}"
I try with OS ubuntu, RH8
and spring-boot 2.2.4 or 2.1.3
and replace -Dconfig.location by --spring.config.location
Give full path of your application.properties file if you want to load it from outside the Jar
I finally found the reason :
I have to use :
su sbert -c
instead of
su - sbert -c
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
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).
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!
I created a command line program in java that will be deployed. Since it has no windows it can't be run by double clicking. I then created a batch file that will run the jar but since the program will be deployed they will have a different path than me.
How do I go from:
java -jar E:\Projects\Java\SystemFileQuery\SFSQ.jar
to:
java -jar ...\SFSQ.jar
Just deploy the SFSQ.jar file to the same directory as your batch file and then you can use
java -jar SFSQ.jar