How to redirect application path in wildfly? - java

Excuse me, I'm new to this. I have developed an application with maven, and when I run the application in my wildfly it opens the following path: "127.0.0.1:8080/myapp-1.0.0" and everything runs perfect, but I simply want that:
x.x.x.x/ point to: x.x.x.x:8080/myapp-x.x.x
I do not know if it is a configuration in standalone.xml as it redirects or something more complicated.

If you only have a single web application, the simplest way is to have jboss-web.xml file in your web application. Put a file like:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="10.0"
xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_10_0.xsd">
<context-root>/</context-root>
</jboss-web>
in your WEB-INF directory. This will make your application run at the / context. Note that this isn't redirection - it's permanently there. Additionally, if you have many webapps running on your Wildfly server they will all need a unique context root.

Related

Context root "/" set URL to localhost:8080//

I have a java spring web application running on a local widlfly. Until now it was always the case that I called the webapp via the URL "localhost:8080/myapp". Now I have set my context root in the jboss-web.xml to "/". My assumption would be that I can now call the website via localhost:8080/. But this redirects me to the Widlfly welcome content. I can only call my webapp via "localhost:8080//". Can I set the context root so that I reach the webapp via "localhost:8080"?
Thanks for your help.
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web version="10.0"
xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_10_0.xsd">
<context-root>/</context-root>
</jboss-web>
You need to disable the default welcome app

404 error when I redeploy a war on Wildfly

I tried to deploy a war file on Wildfly (commandline) by changing the name of the old file (say app.war to appOld.war) and copying a new file with the name app.war to the deployment folder.
On my other terminal, I can see the auto deploy scanner running and deploying the new file but when I try to access the app via URL, I get a 404.
No error shows up in the logs so I don't realize what is happening or what to do.
Thanks.
I think there is problem with your context root.
Because if you don’t set context root wildfly takes filename as your context root.
When you deploy file you just renamed try access <hostname>:<port>/appOld instead of <hostname>:<port>/app
Context root can be manually set set in /WEB-INF/jboss-web.xml
Here is the example of jboss-web.xml whit context root:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/my-web-app</context-root>
</jboss-web>
So when you set it you should be able to access yout app at: <hostname>:<port>/my-web-app
Hope it helps.

How to set the context root in java ee 7 application

I've seen this link and this one but I can't find the sun-web.xml anymore. I am going through the java ee 7 tutorial, specifically the hello1 application. I don't understand how the application knows that /hello1 is the context root, I mean, I don't see it specified anywhere in the web.xml file under /WEB-INF/web.xml. How does glassfish know, and how can we change it to, perhaps, /abc for example.
By default, context root is the same as package name.
If you use wildfly or jboss, you can add jboss-web.xml to webapp/WEB-INF/ to change context root, content like:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web xmlns="http://www.jboss.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.jboss.com/xml/ns/javaee
http://www.jboss.org/j2ee/schema/jboss-web_5_1.xsd">
<context-root>yourownroot</context-root>
</jboss-web>

Java configure context root of web application

I have a Java web application using Wicket 6, Spring 3.2 and WildFly 8.2.0. Right now i'm setting the context root of my web application in the jboss-web.xml file like this:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss-web PUBLIC "-//JBoss//DTD Web Application 5.0//EN" "http://www.jboss.org/j2ee/dtd/jboss-web_5_0.dtd">
<jboss-web>
<context-root>/myCustomContextRoot</context-root>
</jboss-web>
The jboss-web.xml file is compiled into the war. Now some clients want to change this context root to an empty context root. So i hace to recompile a version of my app per different context root. Is there a way to set the context root of my application from outside .war, programatically from a .properties file, or any other way for example in standalone.xml of WildFly 8.2.0?
Set the runtime name when deploying your web application. Suppose your WAR is called myapp-1.0.0-SNAPSHOT.war. Using a runtime name of foo.war, the context root will be /foo.
Using a runtime name of ROOT.war, the context root will be /.
The runtime name can be set when deploying via the Web Console or via the CLI.
Thanks for your Answer Harald Wellmann. It answers the question and pointed me into the right direction!
Some things I had to find out on my own and which may help others:
the exact syntax in jboss-cli to specify a runtime-name is:
deploy path_to_war_file --runtime-name=wantedName.war
This leads to a context-root of /wantedName/ for the webapp.
The runtime-name does not have any effect on the context-root, if the war file contains a jboss-web.xml in WEB-INF which in turn contains a context-root tag.
That is, if you want to control the context-root of your web-app in WildFly at deployment time, you must not specify any context-root in jboss-web.xml.
It is ok to have a jboss-web.xml without a context-root tag if you want to take advantage of the runtime-name to control the context-root.
I tested this on WildFly 9.0.1 and 9.0.2:
Hope this helps!

Redirect war to main domain?

I have a RichFaces WAR file that deploys itself to http://mytestserver:8080/mywarapp/index.jsp. I deploy it on the Wildfly Application Server.
Now I would like to access the WAR file not through this long http-address, but through the main server address: http://mytestserver/
How would I have to do that?
You should change context path of your application.
To do this you need to create file jboss-web.xml and place it in WEB-INF directory. jboss-web.xml should contain:
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/</context-root>
</jboss-web>
If you want to change port of your application from 8080 to 80 you can do this in few ways.
1) [not recommended] change port in your standalone/domain.xml from 8080 to 80 and run wildfly as a root/administrator
2) run nginx/apache or any other webserver and create there proxy redirect eg. in nginx you need to add to your configuration file something like this proxy_pass http://mytestserver:8080/; (if you didn't add jboss-web.xml you need append here mywarapp to this URL ) and your application will be available via URL http://mytestserver/

Categories

Resources