SpringBoot application path.

Corral Gomez-Calcerrada Alberto 1 Reputation point
2022-02-16T12:31:45.647+00:00

Hi.

I have a SpringBoot application running in an App Service (Azure) using a web.config to start. The JAR containing the project runs ok in my machine and is able to read files properties under a folder created in the same level of the JAR. Also the log file is written in this folder.

The problem is when I executed the applicaction in Azure the log is written in root folder (/) and I can´t read the properties under my folder unless I move the folder to the root (/)

The application is ubicated in /home/site/wwwroot but when starts it seems that is executing in / directory.

Any help?

P.D. I have tried to include in my webconfig add configurations like:

<environmentVariables>
<environmentVariable name="CLASSPATH" value="/home/site/wwwroot/keys;%CLASSPATH%" />
</environmentVariables>

or

<httpPlatform processPath="%JAVA_HOME%\bin\java.exe" arguments="-Djava.net.preferIPv4Stack=true
-Dserver.port=%HTTP_PLATFORM_PORT% -Dloader.path=/home/site/wwwroot -jar "D:\home\site\wwwroot\app.jar"">

but nothing works.

Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,748 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Ryan Hill 28,106 Reputation points Microsoft Employee
    2022-03-04T17:18:29.353+00:00

    Hi @Corral Gomez-Calcerrada Alberto ,

    Apologies for the delayed response. You may have success with using -Duser.dir system property:

    <httpPlatform processPath="%JAVA_HOME%\bin\java.exe" arguments="-Djava.net.preferIPv4Stack=true \-Dserver.port=%HTTP_PLATFORM_PORT% -Duser.dir=/home/site/wwwroot -jar &quot;D:\home\site\wwwroot\app.jar&quot;">

    However, I've been informed that modifying web.config isn't the best experience, and it would be best to move to managed offering. See this quickstart for an example. That way, you can use JAVA_OPTS=-Duser.dir=/home/site/wwwroot and it will be passed to JVM.

    0 comments No comments

  2. Corral Gomez-Calcerrada Alberto 1 Reputation point
    2022-03-07T08:20:14.377+00:00

    Hi ryanchill. Thank you for your response. I have tried the solution you gave to me but I´m afraid it doesn´t work. The behavior is still the same. However i tried another solution that works as I want.

    I have used -Dloader.path=/home/site/wwwroot/ in th startup command of App service, but is neccesary to make a little change in the pom of the project. You need to include this configuration in build plugin section

    <build>
    <plugins>
    <plugin>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-maven-plugin</artifactId>
    <version>${project.parent.version}</version>
    <configuration>
    <layout>ZIP</layout>
    </configuration>
    </plugin>
    ...........

    With this change it is possible to specify the property loader.path.

    I have another question for you. Is there any way to automatize taking the name of the jar. I would like name was not app.jar. I would like name was the name of the jar that I´m going to deploy using Azure Devops.

    Thank you.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.