I am using Java / Play Framework 2.1.3.
In production, I build a war using the plugin, serve it in tomcat, and tell apache to redirect /myapp to my tomcat app.
In development, I start the server with:
play debug run
And the root for my dev instance is "/".
Now I would like to specify the context for my development instance. For example, I'd like the route to be /myapp but in the routes file I'd like root to still be "/", etc.
How do I do this?
In Play 2.1.x you can specify the context in your application.conf file.
application.context="/myapp"
...or you can do what I do and just run a local Apache instance and do the same thing as you do in prod :)
Related
I want to deploy a Spring boot application in an external Tomcat server version 9. I am able to deploy it and working the endpoints also. But properties I have set in application.properties file those are not working. Like server.servlet.context-path=/myapp is is not working instead the context path which I am getting is http://localhost:8080/myapp-0.0.1-SNAPSHOT/api/ping.
I am using 2.3.10.RELEASE and Java 1.8 and Tomcat version 9.0.46 Can anyone please help me out with this.
But everything is perfectly working on embedded tomcat. Thanks in advance and any suggestion, comment is highly appreciated.
Can anyone please help me with how I can do this - My war file name would be myapp-0.1.war but the context path of the application would be like this localhost:8080/myapp/api/ping
Use finalName property in your build file (pom.xml for maven)
<finalName>myapp</finalName>
When you run a Spring Boot application in an external servlet container, the server.* properties do not apply.
If you are willing to change the naming convention you can drop a WAR file named myapp##0.1.war in the $CATALINA_BASE/webapps directory and benefit from parallel deployment (cf. parallel deployment).
If you want to stick to your naming convention, you can create a folder for your WAR files (e.g. $CATALINA_BASE/webapps-available) and create a deployment descriptor $CATALINA_BASE/conf/<engine_name>/<host_name>/<context_path>.xml (in your case probably $CATALINA_BASE/conf/Catalina/localhost/myapp.xml) with the following content:
<Context docBase="${catalina.base}/webapps-available/myapp-0.1.war" />
I have a Tomcat 8 instance which is used to publish multiple web applications.
As today, I have a Spring architecture which produces 2 .war:
Front-end
Back-end
And the result is the following:
http://localhost:8080/my-front-end
http://localhost:8080/my-back-end
What I would like to achieve is to have a common root path for both these wars. Is this something I can do in Tomcat? In JBOSS or IIS I can use the concept of "Virtual Directory" to achieve that.
My intended result is the following:
http://localhost:8080/my-app/my-front-end (my-front-end.war)
http://localhost:8080/my-app/my-back-end (my-back-end.war)
The Tomcat documentation says to use # in the name.
Context Name Base File Name Example File Names
/foo foo foo.xml, foo.war, foo
/foo/bar foo#bar foo#bar.xml, foo#bar.war, foo#bar
So use these names for your war files:
my-app#my-front-end.war
my-app#my-back-end.war
Set the context paths: /my-app/my-front-end and /my-app/my-back-end respectively.
For example, if you are using Spring Boot, then put:
server.contextPath=/my-app/my-front-end
and
server.contextPath=/my-app/my-back-end
in application.properties file.
If you cannot modify the application's source code, here you can find out how to configure Tomcat to get the same result.
I have been testing Spring Boot with embedded Tomcat for about a month now to build a REST API. Everything was working fine. We now want to deploy the API in a separate development environment which has a couple of other (non-Spring) applications running on a Tomcat container.
I made the changes specified in Converting a Spring Boot JAR Application to a WAR using Maven and Spring Boot Docs.
The deployment goes well (logs are fine, no errors) and looking at Tomcat management i see my application deployed. However, when I attempt to access http://localhost:8080/sophia/users in curl I get 404.
Any help is much appreciated.
UPDATE:
Here are my logs:
Netbeans:
NetBeans: Deploying on Apache Tomcat 8.0.17
profile mode: false
debug mode: false
force redeploy: true
In-place deployment at /home/bugz/workspace/pdcore/sophiaserver/target/sophia-server-1.0.0-SNAPSHOT
Deployment is in progress...
deploy?config=file%3A%2Ftmp%2Fcontext1845402702541504208.xml&path=/sophia
OK - Deployed application at context path /sophia
Start is in progress...
start?path=/sophia
OK - Started application at context path /sophia
Tomcat:
INFO 10:47:52:703 org.springframework.boot.context.embedded.ServletRegistrationBean - Mapping servlet: 'dispatcherServlet' to [/sophia/*]
INFO 10:47:54:042 org.springframework.boot.SpringApplication - Started application in 8.285 seconds (JVM running for 12087.301)
22-Jan-2015 10:47:54.060 INFO [http-nio-8080-exec-99] org.apache.catalina.startup.HostConfig.deployDescriptor Deployment of configuration descriptor /home/bugz/workspace/server/apache-tomcat-8.0.17/conf/Catalina/localhost/sophia.xml has finished in 12,091 ms
And in sophia.xml for Catalina localhost:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" docBase="/home/bugz/workspace/pdcore/sophiaserver/target/sophia-server-1.0.0-SNAPSHOT" path="/sophia"/>
I've tried accessing
http://localhost:8080/sophia/users
http://localhost:8080/sophia-server-1.0.0-SNAPSHOT/users (name of WAR)
The first returns a 404 but with the CORS information from my CORS filter bean. The second return 404 without CORS information (which indicates the application has started and is configured but I do not seem to have access to the Controllers).
When running an application the path to call consists of a couple of parts.
The first is the base URL on which the application is deployed, in your case that is /sophia.
The second is the servlet mapping of the DispatcherServlet in your case that is /sohpia/*.
The third is the mapping of the controller inside the DispatcherServlet, in your example that is /users.
All those things combined create the URL /sophia/sophia/users.
The difference between the deployment as a WAR is that you included a separate URL to deploy on, when running as a jar it, by default, is deployed to / (the root).
You could fix it by putting /sophia as the server.context-path in the application.properties and map the DispatcherServlet to /* or /. That will in both situations give you the URL you want (and expected).
check java -version means the if you complied war in java 8 and tomcat is running on java 7 then it doesn't work.
Have you tried extending the SpringBootServletInitializer and overriding the configure method? As stated here
The entry point for jar file is different [Main Class] when compared to running your app as war file inside a container.
Hope this helps.
check the java version
version that exists in pom.xml must be the same that the version installed on the server
openjdk 11 works fine for me
https://adoptopenjdk.net/
With grails you change the rootContext of the application when running it using grails run-app by using the grails.app.context variable. However, when generating a war grails allows the servlet container to set the context by leaving the configuration out of web.xml. Is there any way to preserve the config in web.xml?
No, there is no way. As said earlier, grails.app.context is used for run-app where we know the embedded servlet container is either Tomcat or Jetty.
In case of a war, the application will not know which container will the war be deployed. It is upto the container to set the context root which vary from one to another.
I m trying to deploy a web application using netbeans to glassfish 3.01 but i m not able to do so
Glassfish says
Inconsistent Module State
the web app has some jars and a ejb jar for a local ejb
Open the domain.xml file that you will find in this folder:
"your glassfish installation"/domains/"your domain"/config
In this file look for your application deployment configuration to manually remove it:
1) Remove the web-module tag
<applications>
...
<web-module availability-enabled="false" context-root="yourapplicatoinContext" ... />
...
</applications>
2) Also remove the application-ref to your application:
<server config-ref="server-config" lb-weight="100" name="server">
...
<application-ref ... ref="your application name" ... />
...
</server>
Just try this:
undeploy
stop Glassfish
start Glassfish
deploy
If you can't undeploy, try the other steps anyway. If you don't have any luck, you could try it this way:
stop Glassfish
edit domain.xml (probably in domains/domain1/config)- back it up first; remove all references to your app (probably under application / application-ref); just make sure it's still valid xml
start Glassfish
deploy
It should have solved it. If still no luck anyway, remove every file or directory related to your app, probably under domains/domain1/generated and domains/domain1/applications/....
You could always recreate a new domain, but above steps will solve your problem.
You could be in such a situation after stopping Glassfish middle in a deploiyment, for example.
The other answers are really extreme. There is no need to create a new domain or re-install if you cannot redeploy your web application during development.
If you app is very complex, then consider scripting any clean up needed in a Production environment. The below steps will keep you up and working in the short term.
To re-deploy a web app to a single domain on Glassfish 3.1, do the following:
Stop Glassfish from the command line.
Delete all the files in the following directories:
glassfish\domains\domain1\generated
glassfish\domains\domain1\applications
Start Glassfish from the command line.
Deploy your app via the Admin Tool or command line.
In Glassfish 5, I searched for my app name in the domain.xml and deleted all the tags mentioning it. There was one occurence in the beginning (<system-applications>) and one at the end at approx. line 460 (<applications>). Then redeploy worked!