16

I've used the following code to set the Context Path in tomcat where I can access my application directly using localhost:8080 by overriding the tomcat's default path.

<Context path="" docBase="G:\bitbucket\projectpath\project\build\libs\project-1.0" workDir="G:\bitbucket\projectpath\project\build\libs\project-1.0\work"  debug="0" reloadable="false" autoDeploy="true" unpackWARs="true" crossContext="true"/>

Now I'm going to use wildfly-8.2.0 as runtime environment. I tried by directly pasting the .war file into G:\wildfly-8.2.0.Final\standalone\deployments and I can access my project in browser like localhost:8080/project-1.0.

I need to setup the same configuration to wildfly like I've done in tomcat to access my project in localhost:8080 by overriding the wildfly's default welcome page. I tried to do the same in wildfly but I'm stuck where to do that. There are lot of .xml files in wildfly folder (when comparing with tomcat's simple server.xml file) which I get confused on where to start with. I searched using "How to set Context Path in Wildfly", but got no success. Can anyone help me on how to do it..? If it's related to coding, then I can do lot of searches and atleast I can get some Ideas, but I'm stuck here at configuration. Thanks in Advance.

Pratik Singhal
  • 5,566
  • 7
  • 48
  • 88
The Coder
  • 2,349
  • 5
  • 31
  • 55

2 Answers2

38

You can do this in the by adding a /WEB-INF/jboss-web.xml file in the application that you deploy:

<?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>/</context-root>
</jboss-web>
deleze
  • 581
  • 4
  • 5
  • Got it working.. Thanks.. Btw I'm experiencing a wierd problem, I've started the wildfly using this command, `./standalone.sh -b xxx.xx.xx.xxx > $HOME/web.log 2>1 &` and for stopping it, I used `./jboss-cli.sh --connect command=:shutdown` .. Everything works fine, if I start the server, I can access the respective website, If I stop the server access the website, chrome tells me "No Response from Server".. But something wierd happened once I laid my hand on sqlserver. – The Coder Feb 12 '15 at 11:38
  • I have created a db using dump in sqlserver, then after that whenever I deploy my .war file, it keeps coming as deploy failed, I tried a lot. Even after I use the shutdown command, I can access the site which gives me 404 not found message. I think one process is running in the bacground which is not stoppoing even after shutdon command. Do you know how can i resolve it? – The Coder Feb 12 '15 at 11:38
  • When you start the process is it not a good way to use the stdout to redirect the log. It is better to remove the console appender from the logging configuration to avoid fillup the filesystem in `$HOME/web.log`. Just remove console handler from the root-logger. You can add it again without restarting on your server using boss-cli. – deleze Feb 17 '15 at 00:54
  • 6
    If anybody is wondering: The current schemaLocation of the xml namespace is `xsi:schemaLocation="http://www.jboss.com/xml/ns/javaee http://www.jboss.org/j2ee/schema/jboss-web_7_2.xsd"` – Stefan Haberl Nov 23 '16 at 08:20
  • you might also have to remove the welcome-content folder of your wildfly distribution if you want to use /. – user1050755 Sep 09 '17 at 10:58
  • soooo I have to put server configuration stuif into a webapp? wtf? Why do all the DI/IoC stuff in JavaEE if I end up doing such nonsense then.,... lol – user1050755 Sep 09 '17 at 10:59
  • In production you will for sure use automated tool (like Ansible) to deploy applications and configurations. Therefore, you should use JBoos CLI and deployment overlay for your environment dependents settings: [Creating a deployment overlay](https://docs.jboss.org/author/display/WFLY10/Application+deployment?_sscc=t#Applicationdeployment-Creatingadeploymentoverlay) – deleze Sep 10 '17 at 10:31
0

Change context-root directly in WebService class with annotation.

import org.jboss.ws.api.annotation.WebContext;

@Stateless
@WebService(portName = "SampleWSPort", serviceName = "SampleWS")
@SOAPBinding(style = Style.DOCUMENT)
@WebContext(contextRoot = "/SWS", urlPattern = "/SampleWS")
public class SampleWS implements SampleWSInterface {

org.jboss.ws.api.annotation.WebContext is in MAVEN artifact:

<dependency>
   <groupId>org.jboss.ws</groupId>
   <artifactId>jbossws-api</artifactId>
   <version>1.1.2.Final</version>
</dependency>