Spring Maven rest web service - What is the URL when deploying on real web server? - spring

I followed this tutorial https://spring.io/guides/gs/rest-service/ by creating maven project in intellij, addind pom.xml etc. Then I run on localhost exactly as written in the tutorial and all works:
http://localhost:8080/greeting
When greeting came from the annotation of method in the controller #RequestMapping("/greeting").
Then I made JAR artifact & deployed it to Tomact on 'real server' (Elastic beanstalk environment running EC2 instance on AWS).
I got from AWS the base URL of my webserver running Tomact. What is now the suffix to my service? This is NOT working:
http://someEnvironmentName.elasticbeanstalk.com/greeting
EDIT: How I made the artifact JAR
In intellij I can compile & run maven project and then test it in localhost. So what I did:
Right click on the project name->Open Module Settings->Artifacts->Add->Jar
Build->Build Artifacts->Selecting the Jar from above
Maybe I need to build WAR? And how to deal with the POM.xml? Now my pom is exactly as in the linked tutorial.
Thanks,

If you use spring-boot, you donĀ“t need a tomcat because spring include an embedded tomcat. Only you run the application with Maven. So, the advantage of spring-boot is not dependent on an application server and using other containers such as Docker.
Do you put the port in the call to your webserver?
On the other hand, check your server logs to see if there are any problem.

Solution (Thanks to #JBNizet suggestion):
Follow this link http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-create-a-deployable-war-file
Modify the Application.java file
Modify the pom.xml (By adding one more dependency)
Then if you are using Intellij IDE under Build->Build Artifacts will be automatically option for WAR file.
Just deploy to AWS elasticbeanstalk instance running EC2 in the usual way. The URL is:
http://someEnvironmentName.elasticbeanstalk.com/greeting

Related

How do I go from a Maven Dynamic web project to some executable

I have a Maven Dynamic web project in Spring - I can run this in eclipse with a tomcat server and serve all my code a web page via localhost.
I am looking to create an executable which can be ran locally on a machine with no internet connection and when ran will serve the web project to a specified localhost URL.
If you have included an embedded server (like tomcat) as a dependency in you POM.xml file, then you have to Right Click on your Project -> Run as -> Maven Install. This will build a Maven Executable Jar file in the target folder of your Maven Application.
Take the Jar file and Run it from command line using
java -jar <jarfilename>.jar
After building project you will have <project_name>.war file created in target folder inside the project.
You should deploy it to a J2EE application server, like: Glassfish, JBoss Wildfly, etc.

Maven JBOSS application deployment

I followed this tutorial http://www.mastertheboss.com/jboss-maven/jboss-maven-example-building-a-java-ee-6-application/ in order to have a simple web application to better understand Java EE and JBOSS. I set up the example project (by archetype) and compiled it.
However, I am stuck after running mvn compile. I want to deploy my application as a war file to my JBOSS webroot directory (in my case /usr/share/jboss-as/standalone/deployments/).
I think mvn package and mvn install must be executed. Where can I specify that I want a war file and that it should be copied to my deployment location on JBOSS?
Obviously, I can use the jboss maven plugin http://docs.jboss.org/jbossas/7/plugins/maven/latest/, which is addressed via console
jboss-as:deploy
Configuration is read from the POM file.

Weblogic Maven Plugin Deployment Issue

I'm using eclipse Kepler, Weblogic 10.3.5 and Maven 3.0.5 with the Weblogic-Maven-Plugin. When I deploy my application using eclipse Run As...Run On Server, this is what I get:
When I deploy this way, you see the application on the Weblogic Server and I'm able to reach my application through my localhost link.
When I use the Weblogic-Maven-Plugin, this is what I get:
You see the application has been placed under the adminServer and I get an error when I try to reach the application through my localhost link (Yes, I even ran the start-app command).
I have few questions:
Why is it that when I use the weblogic-maven-plugin, it deploys under the adminServer?
Is there a way to have the weblogic-maven-plugin deploy in a similar fashion as the Run As option in eclipse?
Why can I not reach the application with my localhost link after deploying with the plugin?
Any help is greatly appreciated.
I face this problem some weeks ago but in another environment Jdeveloper 12c with Maven and OJMake and OJDeploy.
The deployment is the last step on your way to run our application on WLS(WebLogic Server)
How do i solve the issue?
I create an Maven Ear projet
I create also Maven War project
I add the war project in the ear project also dependency and later also web_module
My deploy(to WLS) Configuration is in the pom from Ear project.
I you use run as from Eclipse or Jdeveloper there is a complex mechanism which do the work for us. If we want maven to do the job for us, then we must tell him what to do. We must also know what type of archive file we suppose to send/deploy to WLS

How do I deploy a maven created webapp to tomcat

So I was following http://www.mkyong.com/jsf2/jsf-2-0-hello-world-example/ for a simple tutorial on how to use maven and jsf. I created a maven project by running mvn archetype:generate -Dfilter=org.apache:maven-archetype-webapp in my command prompt. Then I continued with the tutorial, I wound up creating all necessary files, but then when I got to the end, I realized I did have a server created. So I created one real quick, but when it came to the point of adding files to the server (from the add or remove dialog box), no projects or files showed up. I am not on my computer where the project is located so I can't copy/paste the .pom file in, but it looks practically exactly like the pom in the tutorial (only difference is groupId, artifact, ect.) No additional plugins, dependencies, or configs.
Do you want to deploy the webapp within Eclipse to Tomcat? Or as some sort of automatic/continuous deployment?
Within Eclipse you often need to add the Dynamic Web project and JSF facets to your project so Eclipse recognizes the project as deployment capable. If you are using m2eclipse make sure to install the m2eclipse wtp add on so this is done automatically.
If you want to add auto-deployment to the pom.xml I recommend using the maven cargo plugin: http://cargo.codehaus.org/Maven2+plugin - it supports the major containers.
For tomcat you need to modify the tomcat-users.xml to allow auto-deployment and leave the tomcat-manager application in place. If you have startet tomcat and pointing your browser to http://localhost:8080/manager/html/list it should either tell you to login or what to add to that file.
The configured user is then used in the configuration to deploy the war file via the tomcat-manager using the mvn cargo:deploy goal. The configuration has to be added to the pom.xml using war as packaging, not to the parent-pom.xml

Hot deploy war maven project in embedded tomcat

I have maven war project.
I know inplace. it deploys to a given server. But i want to deploy on embedded tomcat and dont want to restart everytime. just say
for first time run deploy
Then change some java class and say redeploy. All in embedded tomcat.
Is this possible ?
Could the Tomcat Maven Plugin help with this?
You can use it by using the command tomcat:run
This page describes how to set up your POM/settings to make calling the plugin easier (using a prefix vs having to use full groupId/artifactId of plugin on the command line).
Maybe you can have a look at the executable war/jar feature see http://tomcat.apache.org/maven-plugin-2/executable-war-jar.html
So that will produce a simple jar which contains tomcat classes. You will be able to simply run: java -jar pathtofile.jar.

Resources