8 Replies Latest reply on Apr 11, 2014 4:31 AM by Radoslav Husar

    Jboss as 7 virtual host

    Sam 顾 Newbie

        Now,my project's address is http://192.168.1.3/myapp. but i want to browse it using http://192.168.1.3, without /myapp.

        I have alread took the method of virtual host and dns ,look like this :

       

      jboss-web.xml

      <?xml version="1.0" encoding="UTF-8"?>

      <!DOCTYPE jboss-web>

      <jboss-web>

      <context-root>/</context-root>

      <virtual-host>myapp</virtual-host>

      </jboss-web>

       

      standalone.xml:

              <subsystem xmlns="urn:jboss:domain:web:1.4" default-virtual-server="default-host" native="false">

                  <connector name="http" protocol="HTTP/1.1" scheme="http" socket-binding="http"/>

                  <virtual-server name="default-host" enable-welcome-root="true">

                      <alias name="localhost"/>

                      <alias name="example.com"/>

                  </virtual-server>

                  <virtual-server name="myapp" default-web-module="myapp">

                      <alias name="myapp"/>

                  </virtual-server>

              </subsystem>

       

         Windows system hosts file

      c:\windows\system32\drivers\etc\hosts

      127.0.0.1  myapp

       

          I have browsed my app using http://myapp in local machine.this method is need the DNS support, But i don't know there is another method ?

        • 1. Re: Jboss as 7 virtual host
          Radoslav Husar Master

          Not sure what is the question, the process seems fine.

           

          For every translation from a domain name to an IP adress you will need to perform a DNS lookup from the DNS server. You need to add that DNS entry possibly to your intranet DNS server or to a TLD and publicly available DNS server. (Editing the local hosts file will not affect other clients trying to access myapp -- I hope that's clear.)

          • 2. Re: Jboss as 7 virtual host
            Sam 顾 Newbie

                 I means,in addition to the DNS look up, whether there is anohter method to realize browse my app using port directly,not ip:port/myapp  ?

            • 3. Re: Jboss as 7 virtual host
              Sam 顾 Newbie

              The major cause is that myapp's return code is 500 error when myapp is out of memory,my app's address is http://192.168.1.3/myapp.But then,the http://192.168.1.3 is ok, this address without /myapp return the welcome jboss html file.

                  So,i want to realize browse my app using ip:port,not including /myapp.

              • 4. Re: Re: Jboss as 7 virtual host
                Radoslav Husar Master

                The major cause is that myapp's return code is 500 error when myapp is out of memory,my app's address is http://192.168.1.3/myapp.But then,the http://192.168.1.3 is ok, this address without /myapp return the welcome jboss html file.


                You seem to be confusing lots of things into one, OOMs/DNS/context path.


                If you want to deploy the application and make it available at host[:port]/ instead of host[:port]/myapp you can do this 2 ways:


                Add jboss-web.xml file to WEB-INF directory and use context-root element:

                 

                <?xml version="1.0" encoding="UTF-8"?>
                <jboss-web version="8.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_8_0.xsd">
                  <context-root>/</context-root>
                </jboss-web>
                

                 

                This is JBoss specific.

                 

                Also you can use the EE way and bundle the WAR into an EAR in application.xml:

                 

                <?xml version="1.0" encoding="UTF-8"?>
                <application xmlns="http://xmlns.jcp.org/xml/ns/javaee"
                             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/application_7.xsd" version="7">
                  <display-name>example</display-name>
                  <module>
                    <web>
                      <web-uri>example.war</web-uri>
                      <context-root>/</context-root>
                    </web>
                  </module>
                  <library-directory>lib</library-directory>
                </application>
                

                 

                 

                To realize this via maven, use build step such as:

                 

                    <build>
                        <finalName>example</finalName>
                        <plugins>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-compiler-plugin</artifactId>
                                <version>3.1</version>
                                <configuration>
                                    <source>1.7</source>
                                    <target>1.7</target>
                                </configuration>
                            </plugin>
                            <plugin>
                                <groupId>org.apache.maven.plugins</groupId>
                                <artifactId>maven-ear-plugin</artifactId>
                                <version>2.9</version>
                                <configuration>
                                    <version>7</version>
                                    <defaultLibBundleDir>lib</defaultLibBundleDir>
                                    <modules>
                                        <webModule>
                                            <groupId>com.example</groupId>
                                            <artifactId>example-web</artifactId>
                                            <contextRoot>/</contextRoot>
                                        </webModule>
                                    </modules>
                                </configuration>
                            </plugin>
                        </plugins>
                    </build>
                
                1 of 1 people found this helpful
                • 5. Re: Re: Jboss as 7 virtual host
                  Sam 顾 Newbie

                        Thanks for your reply. Now i have put WAR into an EAR in application.xml,but there is a error when the jboss startup. the error is below:

                   

                  16:56:59,061 INFO  [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/]] (ServerService Thread Pool -- 67) No Spring WebApplicationInitializer types detected on classpath

                  16:56:59,537 INFO  [org.jboss.as.connector.subsystems.datasources] (MSC service thread 1-8) JBAS010409: 解除数据源 [java:jboss/datasources/ExampleDS] 的绑定

                  16:56:59,545 INFO  [org.apache.coyote.http11] (MSC service thread 1-3) JBWEB003075: Coyote HTTP/1.1 pausing on: http-/0.0.0.0:80

                  16:56:59,559 INFO  [org.apache.coyote.http11] (MSC service thread 1-3) JBWEB003077: Coyote HTTP/1.1 stopping on : http-/0.0.0.0:80

                        Coudle you please tell me what can i do??

                  • 6. Re: Re: Jboss as 7 virtual host
                    Radoslav Husar Master

                          Thanks for your reply. Now i have put WAR into an EAR in application.xml,but there is a error when the jboss startup. the error is below:

                    If the problem is bundling into EAR, use the first approach using jboss-web.xml.

                    • 7. Re: Re: Jboss as 7 virtual host
                      Sam 顾 Newbie

                      The jboss-web.xml  is need the  DNS support?

                      • 8. Re: Re: Jboss as 7 virtual host
                        Radoslav Husar Master

                        Sam 顾 wrote:

                         

                        The jboss-web.xml  is need the  DNS support?

                        Nothing to do with the dns, just the context so that you will be able to access http://example.com instead of http://example.com/myappcontext.