JBoss 7: how to change a WAR context root - jboss

I have an application that is to be deployed in a WAR file (app.war). After deployment it is available from
http://:8080/app
I would like to have it being made available as something like
http://:8080/secret/app
I searched the documentation and for JBoss'es 5 and 6 this seems to be able to do with a jboss-web.xml file. I have tried it but with no luck. It seems that JBoss 7 just ignores the element inside jboss-web.xml.
I don't know if this is relevant but this application has both JSF and PrettyFaces.
Does anyone know if this behavior is possible with JBoss 7? If so, how can it be done? I am still trying to find an answer for this.
Thank you.

this works in AS 7.0.1, WEB-INF/jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<context-root>/my_custom_root</context-root>
</jboss-web>
I don't think it is possible to have app root like "server/something/app", but you can simulate this behavior through application structure

Just for sharing a personal experience...if the context-root in jboss-web.xml seems to be ignored...try to see if it is (the context root) already declared in your application.xml

Related

How to config JBoss Eap 6.4 to serve images from an external folder outside webapps?

I have an application deployed on JBoss Eap 6.4 and I need to access to images that are located outside of my project in C:\AdminCont\Images, Is there any form to configure for JSP access to this images or any other form using NFS?
I´m trying using overlay in jboss-web.xml but I don´t know how is the correct implementation.
A portable way to implement this is to write a small servlet which simply maps the request URL to a filesystem location and sends the content out.
A not portable way, a JBoss specific way, is to declare an outside directory to <overlay> in jboss-web.xml in order to add non-existing files to your deployment. Here is an example:
<jboss-web version="7.0"
xmlns:jboss="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 jboss-web_7_0.xsd">
...
<overlay>/path/to/your/images/</overlay>
...
</jboss-web>

How can I deploy a war-file to a subdirectory of my JBoss server?

this has got to be a stupid question but my Google-fu fails me. I have a JBoss server (actually EAP 6.1) and a packaged web application, myapp.war.
By copying the file to .../standalone/deployments/ it gets deployed to <server>/myapp. Renaming the file to somename.war, it becomes <server>/somename, and ROOT.war gets deployed directly on <server.
So far so good.
But how do I get the application to appear under e.g. <server>/antares/myapp?
I tried simply making a subdirectory under deployments/ and placing my war file there, but that still gets deployed simply as <server>/myapp. I also read somewhere on a Tomcat forum to call my file antares#myapp.war, but that resulted in an error when the deployment scanner tried to run it.
Searching around on the web, I so far mostly found (a) descriptions of the folder and subfolder structure of a web project or (b) things about projects and sub-projects and how to handle dependencies.
I don't need all of that, I just want my perfectly fine war file to show up with a slightly deeper path. Preferably without having to touch many configuration files.
What am I missing?
You need to wrap your .war in to a .ear and add the following information in to the application.xml in order to achieve what you want.
<application xmlns="http://java.sun.com/xml/ns/j2ee" version="1.4"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com /xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/application_1_4.xsd">
<display-name>Your App name</display-name>
<module>
<ejb>a-ejb-module-if-you-have-one.jar</ejb>
</module>
<module>
<web>
<web-uri>myapp.war</web-uri>
<context-root>antares/myapp</context-root>
</web>
</module>
</application>
Please take a look at the documentation here: Setting the context root of a web application

How to customize JBoss AS7 404 page

I already created a custom 404 page inside my web app deployed in JBoss AS 7.1.
So if my app is at fubar dot com :8080/Myapp and I go to fubar dot com :8080/Myapp/xyzzy, I get the custom error page (defined in the web app's web.xml file).
However, when I go to fubar dot com :8080/xyzzy, JBoss displays the default 404 page which discloses that it's JBoss and which JBoss version.
I need to replace this page in order to hide this information.
Please advise.
If you want to customize the error pages for all the other contexts in JBoss 7, a part of the configuration you have in your Myapp application, you'll also have:
to disable JBoss welcome page: in the file standalone/configuration/standalone.xml (or domain/configuration/domain.xml), set the attribute enable-welcome-root as false (by default it's true)
Then you'll have to deploy a simple war file setting its context-root to '/', and define the error page for this war (using the same method you've used for Myapp). So, the war structure should be similar to (the error.war name is arbitrary):
error.war
|
|- META-INF
|- WEB-INF
| |
| |- web.xml
| |- jboss-web.xml
|
|- error
|- 404.html
where The web.xml file is:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>yourcompanyname</display-name>
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
</web-app>
And in the jboss-web.xml define the context-root as '/', so it would be:
<jboss-web>
<context-root>/</context-root>
</jboss-web>
The file 404.html is your customized html error page that Jboss will show instead of the 404 default error. That's all, deploy this application in JBoss 7, and you'll have your custom 404 error page when you'll visit fubar dot com:8080/yzyqqa or whatever other root context. Remember that you'll have to keep the error configuration in your Myapp web.xml as well (and in all the other applications you may the deploy in the server).
By the way, have you considered making your app Myapp accessible directly from fubar dot com:8080? Or even better, making the jboss server only accessible from a proxy (for example Apache)?.This way you'd avoid this problem as well.
I hope it helps!
Your problem : You defined the custom error page in web.xml of Myapp. Now if you access any resource with root as Myapp and the request throws a 404 it returns the custom error page.
Now you want that if you access any other root , here xxyzzzz you want to return the custom error page.
Now logically, if you configured a file for other project you cant expect it to be same for other project
Unless
either you configure the same thing for other project , i.e. xxxyzzz as well. i.e. place the 404 config in its web.xml aswell.
or you need to do something at the server scope.
the 1st solution is fairly simple and easy in case there are less number of projects and you not expecting a URL that does not match any of the project.
if you want to go with 1st solution, you know how to do it
Regarding the 2nd approach.
I could find some posts that should be helpful to you
refer these
with jboss as7, the custom of global web.xml is gone.
I could find only one way to configure a global 404 error page. refer here. IT WORKS :D
Custom error pages in Apache for JBoss AS7
I believe you will have to create your own page. JBoss uses Tomcat for serving the web requests.
In Tomcat the way to define your own 404 response page is having the following snippet in your web.xml
(Ref - http://wiki.apache.org/tomcat/FAQ/Miscellaneous#Q6)
<error-page>
<error-code>404</error-code>
<location>/error/404.html</location>
</error-page>
A detailed page on how to do this with struts is created by mykong # http://www.mkyong.com/struts/how-to-handle-404-error-in-struts/.
If you are using any other framework than struts you should have a equivalent.

how to change Jboss default page to the home page of my application?

I have an application deployed in JBOSS and it is accessed as: localhost/appname
When i enter only the IP address i get redirected to the JBOSS default page.
Is there a way to go to the application's homepage with no need to give /appname ?
I hope the question is clear.
Thanks in advance.
A part of the solution given by Nightsorrow, you can also define the context root of your web application using the context-root tag of the WEB-INF/jboss-web.xml file. So defining it as '/', you can keep your original file name. This way you override the default behaviour of JBoss, which is defining the context root of web apps as the file name of the application (unless the app name is ROOT.war, which its default context is '/').
So the jboss-web.xml file would look like something similar to:
<jboss-web>
... other tags ...
<context-root>/</context-root>
... other tags ...
</jboss-web>
Notice that there can't be two applications with the same context root, so first you will have to remove ROOT.war, or change its context root following the same procedure:
adding the context-root tag to jboss-web.xml (for example: <context-root>/oldRoot</context-root>, which would make the old ROOT.war application available through localhost/oldRoot),or
just changing its file name.
In case you want to deploy an EAR file with a web module (war) inside (instead of just a plain war file), you've to use the META-INF/application.xml of the EAR. Defining the web module this way:
<application>
... other tags and other modules (ejb, web ...) ...
<module>
<web>
<web-uri>nameOfYourWarFile.war</web-uri>
<context-root>/</context-root>
</web>
</module>
... other tags and other modules (ejb, web ...) ...
</application>
You have to deploy your application in file named "ROOT.war". Also you have to delete existing ROOT.war in deploy directory.
I am using eap6. This is my first time to use jboss. I don't see that I have $JBOSS_HOME/server. I see $JBOSS_HOME/domain/server. I have searched all the files under $JBOSS_HOME. I cannot find any WEB-INF and jboss-web.xml

How do I change the context path of my Enterprise Project

So my enterprise project name TestProject, which contain TestProject-ejb and TestProject-war, so when I run the project the url is like this locahost:8080/TestProject-war. How can I change this url to localhost:8080/testproject. I use netbean 6.9, I try to right click on TestProject-war folder in netbean, and specify the context-path there under Run, but it still load locahost:8080/TestProject-war
You need to check that the context-root element for the web module in the application.xml file that's in the META-INF directory of your EAR has been correctly changed.
An example would look like this:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:application="http://java.sun.com/xml/ns/javaee/application_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
id="Application_ID" version="6">
<display-name>TestProject</display-name>
<module>
<web>
<web-uri>TestProjectWeb.war</web-uri>
<context-root>testproject</context-root>
</web>
</module>
<module>
<ejb>TestProjectEJB.jar</ejb>
</module>
</application>
In this example the web module should be available under /testproject of the server you deploy to, so in your case http://localhost:8080/testproject.
(In case you would like to deploy to the root of your server, you can leave the context-root element empty: <context-root></context-root>.)
If you indeed see that your action in Netbeans has correctly changed this file, it may be a deployment problem like BalusC indicated. Check the location the EAR is deployed to and manually inspect whether the deployed version also has the correct value.
As Harry pointed out the default project template doesn't create an application.xml file, so you have to create it by hand at $ENTERPRISE_APP_PATH/src/conf (tested with NB 6.9.1)
Just ran into this question in the course of figuring out the same thing. Since the OP was asking about doing this in Netbeans, let me add to previous answers by describing specifically how to do this using the Netbeans IDE.
With Netbeans 8 (and possibly also with earlier versions) you can tell the IDE to create the application.xml file for you, as follows. Right-click the enterprise application project (in the OP's example this would be "TestProject"), select "New" then "Standard Deployment Descriptor...". This will create an "application.xml" file and put it in the appropriate place in your Netbeans project. Then you can easily edit this file to set the context-root element to be whatever you want.