Reputation: 23
I have an application developed in java. I have exported it to an executable jar and I would like to upload it to azure so that it runs with a certain schedule. Until now it has been impossible for me to know how it is done. I have done a web service with eclipse and if it is easy to deploy it in azure and make it work but not executable. Can someone tell me how it is done?
Upvotes: 1
Views: 1406
Reputation: 24148
It sounds like you want to run an executable jar file with a time trigger on Azure. The simple way is to deploy your jar file as a WebJob on Azure WebApp. Here is the steps to do it as below.
Create a .bat
file named run.bat
and write the follow commands as below.
set JAVA_HOME=D:\Program Files (x86)\Java\jdk1.8.0_172
set CLASSPATH=.;%JAVA_HOME%\lib
set PATH=%JAVA_HOME%\bin;%PATH%
java -jar <your jar file name>.jar
Compress the run.bat
file and your jar file to a zip file, then to deploy it with Scheduled
trigger and a CRON Expression
value on Azure portal.
Then, you can start it on Azure portal, and to see the running logs via Logs
button.
Note: for more information about CRON Expression
or others, please see the section CRON expressions
of the offical tutorial Run Background tasks with WebJobs in Azure App Service
.
Upvotes: 2
Reputation: 14334
From your description, i think your project missing a web.config
which should be deployed at the wwwroot
path.
Here is a sample web.config file.
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" />
</handlers>
<httpPlatform processPath="%JAVA_HOME%\bin\java.exe"
arguments="-Djava.net.preferIPv4Stack=true -Dserver.port=%HTTP_PLATFORM_PORT% -jar "%HOME%\site\wwwroot\ROOT.jar"">
</httpPlatform>
</system.webServer>
</configuration>
And make sure upload your jar file to home\site\wwwroot\bin
folder. Further more information you could refer to this doc:Running java jar file to serve web requests on Azure App Service Web Apps.
Upvotes: 0