Using azure to run java app but access not working - java

I just started to work with the azure platform and I have a Question.
I upload my app to azure and run it but when I try to access it, it does not work but returns a 404 not found.
Maybe I did something wrong?
This is the repo that I connected:
https://github.com/idanovadia/ServerAlgoSearchImplementation_v2
for example when I run it on local host :
http://localhost:8080/getMaze/prim
now I tried :
https://searchnow.azurewebsites.net/getMaze/prim

I see that you try to package your java app to a jar file, and run the jar with a web.config in web app. This is the old way to run spring boot application.
In fact, there is a common and better way. It is just to package your spring boot application to a war package. And then you can deploy it to Azure web app with tomcat container.
1. You need to choose to package as war when you initialize the spring boot project:
2. Set the packaged file name to ROOT.war
Open the pom.xml, add the following line:
Then you will get a ROOT.war file if you run mvn clean package
3. Create a web app with Tomcat
4. Deploy ROOT.war under \site\wwwroot\webapps folder in web app
5. Restart your web app.

Related

AWS Java - Referencing file included in my .War package not found

I need this file to authorize my API request to an external service. My app is deployed in Elastic Beanstalk with a WAR package and my file is stored in WEB-INF/lib but when I route my service to this address nothing is happening. My java classes are stored in WEB-INF/classes and its subfolders (due to packages). Should I use any absolute address instead of a relative one? Any ideas about what may be happening?
My build.xml file to generate War package with ant:
Looks like you are missing dependencies. I have never seen this issue when building a web app using Spring BOOT and Maven. As well, when building with Maven/Spring BOOT, I always ensure to use spring-boot-maven-plugin that builds an executable JAR file which includes the dependencies.
TO learn how to create a basic Java app with Dependencies and deploy to the Elastic Beanstalk, see this AWS tutorial.
Creating your first AWS Java web application

Jar via Tomcat in IntelliJ

I spended a few hours to resolve my problem with deploying jar file on tomcat but I lost all fights, and I must ask one question:
Is it possible to run the jar file via tomcat in intelliJ?
Best regards
It's not possible deploy a jar in Tomcat anywhere. You can only deploy war files.
Normally when you distribute a web application in a jar (like a spring boot app) you don't deploy it in a server, it's a standalone application you run from the command line.

How to deploy Java application to Tomcat 8 App Service using Azure DevOps release pipeline?

I have a Java application that can be deployed to a Tomcat 8 App Service from Eclipse using the Azure extensions.
I created a Build pipeline that creates artifacts with the .war file.
I then created a Release pipeline and set up a "Deploy WAR to Azure App Service". The pipeline deploys the war file and expands it, but some other configuration is not right because the app is not available on the Tomcat server.
Has anyone used this task to successfully deploy to a Tomcat 8 App Service?
If so, what else needs to be done to get the app to deploy successfully?
P.S. I have very little experience with Java or Tomcat so it's likely something I've missed.
Well, seems you deployed the WAR to Azure App Service (Azure Website) but not the Tomcat server.
You just need to deploy the WAR to Tomcat server instead of Azure Website.
Build the Java project first, please refer to Working with Azure
DevOps and Java and Build your code with Maven for details.
Install the extension Apache Tomcat Deployment
Deploy applications to a Tomcat server using the Deploy to Apache Tomcat task.
Reference below articles to do that:
Continuous Integration and Deployment of Java web apps to Azure with
VSTS
https://github.com/Microsoft/vsts-tomcat/blob/master/src/tomcat.md
The Answer by Andy is most of the solution but there was one additional piece required to get the deployment working. I found this response to some additional errors I was getting after switching to the Apache Tomcat Deployment.
I also added a bash script to rename my app to ROOT cp my-war-file-name.war ROOT.war so that the app was the default application.

Spring boot application in windows server

I am planning to deploy a web application built on spring boot in windows server.
I want to use tomcat container.
Can I deploy the spring boot fat jar directly or is it recommended to deploy the war file.
please suggest how to deploy and the preferred method?
As Josh Long likes to say "Make Jar not War!" It really allows an application to have flexibility on where it can be run and allows for everything to be packaged as one artifact. Windows has no issue running the embedded Tomcat that is part of Spring Boot and that is exactly what it is doing when running it in your IDE. The one edge case to this is keeping the process running on the server. Normally in Windows you would do that by setting up a service and having that service run java -jar myapp.jar. I haven't personally seen it done so might take some playing around but it is possible.
A simple way to run a spring application in Windows Server is to run it as a service. You can do it using the winsw, that you download its .bin file here
winws download
Then, rename it to something like my-app.exe and create a XML file like this:
<service>
<id>my-app-service</id>
<name>my-app-service</name>
<description>Back end service for app</description>
<env name="HOME" value="YOUR_JAR_FILE_PATH"/>
<executable>java</executable>
<arguments>-Xrs -Xmx256m -jar "YOUR_JAR_FILE_PATH\YOUR_JAR_FILE.jar"</arguments>
<logmode>rotate</logmode>
</service>
Then, using the terminal, run:
my-app.exe install service
Your application is now a windows service and you can start\stop it in the tasks manager on the services tab.
Starting from the latest Windows versions, you could also deploy your Spring Boot app inside a Docker Windows Container. I wrote a complete guide: https://blog.codecentric.de/en/2017/04/ansible-docker-windows-containers-spring-boot/ (as already mentioned, Tomcat is already embedded in Spring Boot).
Spring boot internally has a tomcat server.
If you want to deploy it on tomcat then while building with maven build it as war.
If you want to deploy it has inependent application then build has jar and then place it in some folder and run it using below commands java -jar yourjarname.
Apache tomcat is a web container you cannot deploy a jar in tomcat server. If you created a web application then export your application as war file and put it in tomcat webapp directory, start the server and your war will be deployed.
How to deploy created .jar file in Apache Tomcat server in Eclipse IDE?

Deploy Java application with Rest web services in Openshift server

I´m trying to deploy java application in OpenShift server. My application is divided in four projects: BBDD, Bussiness, Web Services and Web. When I create the application with openshift, it´s created this structure: src(this one has java, resources and webapp folders), webapps and pom.xml. I don´t know how to organize my projects into that structure to upload to the server.
I have put my web structure on webapp folder inside src. Then, I put the other projects on java folder. When I executed the application I can see my web pages and I can navigate for all of them but, when I call to a webservice I have the following error:
Http/1.1 404 not found
Thanks in advance,
Iban
Openshift is expecting to compile the application on their server using the pom.xml then run the application it built. To do that your project needs to be a maven webapplication project. Only when you have tested it locally would you expect that committing the code to your openshift server (using git) would it be able to compile and run the app successfully.
This means that you should not be uploading files using an SCP upload tool; you should be committing your source using git to your openshift server for it to compile then run your app.
The way I typically work with maven and openshift is to add a fragment of xml into the pom.xml to enable the jetty-maven-plugin to be able to use mvn jetty:run to build and launch the project to test it locally. If-and-only-if it works locally do I try to deploy it. That command is 'zero install' as maven downloads the jetty jars and runs them over your project.
Redhat openshift tends to promote redhat jboss AS application server as a Java solution so if you go down that route you should try mvn packageto make the war file and test it against a local jboss install before expecting it to work on the server. There is an approach where rather than committing code for the server to build and run you can build an EAR file locally and have that pushed to the server.
At the bottom of this answer I have a link to a demo I wrote which shows my preferred approach. I create my apps as a DIY cartridge which is an empty shell then customise the scripts in the .openshift folder to start the Java server of my choice. I use maven to build my webapp which I run using the jetty-maven-plugin to debug locally in Eclipse (maven IDE plugin lets me "debug as... > maven > "jetty:run"). Then I configure the pom.xml to build my whole app plus the jetty Java webserver into one huge runnable jar. Then I edit the start script to use "java -jar" to run my full app.
If you are using a DYI cartridge you don't need to use maven; I have used sbt as the build tool to create a runnable jar. You simply have to modify the scripts in the .openshift folder to download and run the tools you choose.
The demo I made GitHub at the link below has instructions on how to deploy it on openshift. So you may want to get that running then after you can both debug it locally and push it to your openshift server then rip out my code and add in all yours:
https://github.com/simbo1905/zkmongomaps

Categories

Resources