I have a situation here i have an application in jsf-2.1 which is deployed as http://localhost:8080/myWebApplication and in "META-INF" i have context.xml which has the following configuration
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/myWebApplication" />
Now i want to shorten the name without loosing context => 'myWebApplication' like '/mwp'
i tried to do the following but it did not work out as expected:
<?xml version="1.0" encoding="UTF-8"?>
<Context antiJARLocking="true" path="/myWebApplication" />
<Context antiJARLocking="true" path="/mwp" />
Please advise if it is possible or is there any workaround to achieve this.
Your application will (on your application server, not talking about vhosts or mod_rewrite on apache) only respond to:
The application name you have defined in your web.xml
If there is no such configuration in your web.xml, it will respond to the name of the war-file. If for example your application is called myWebApplication.war, it will respond to /myWebApplication.
Related
We deploy an application on tomcat 9 (apache-tomcat-9.0.22).
The official documentation (https://tomcat.apache.org/tomcat-9.0-doc/config/context.html) says it's possible to define default context elements but it's not working for us.
We need to define a datasource and a mail server. If we define this resources in conf/server.xml file in GlobalNamingResources it works.
<GlobalNamingResources>
<Resource name="mail" type="javax.mail.Session"... />
<Resource name="jdbc/mydb" type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"... />
</GlobalNamingResources>
But in production, we cannot modify server.xml file. So we need to define this resources in an other file.
If we define resources in $CATALINA_BASE/conf/[enginename]/[hostname]/ROOT.xml file with a war named ROOT.war, it works :
<?xml version="1.0" encoding="UTF-8"?>
<!-- Context configuration file for my web application -->
<Context>
<Resource name="mail" type="javax.mail.Session"... />
<Resource name="jdbc/mydb" type="javax.sql.DataSource" driverClassName="oracle.jdbc.OracleDriver"... />
</Context>
This solution could be satisfactory but our war file must have a different name than ROOT.war (like MyApp_v42.war) and it will change with every update. We cannot rename the xml file every time we update.
If we define resources in the $CATALINA_BASE/conf/context.xml file or in $CATALINA_BASE/conf/[enginename]/[hostname]/context.xml.default file like documentation says we obtain a javax.naming.NameNotFoundException.
Thanks in advance!
One solution is :
Define resources in conf/context.xml :
<?xml version="1.0" encoding="UTF-8"?>
<Context>
<Resource name="mail" type="javax.mail.Session"... />
<Resource name="jdbc/mydb" type="javax.sql.DataSource"... />
-->
<WatchedResource>WEB-INF/web.xml</WatchedResource>
<WatchedResource>WEB-INF/tomcat-web.xml</WatchedResource>
<WatchedResource>${catalina.base}/conf/web.xml</WatchedResource>
<Manager pathname="" />
</Context>
Use a deployment outside of the webapps directory, for example in wars/
Create an XML file ROOT.xml under the conf/Catalina/localhost/ that define the docBase attribute with a path relative to the webapps directory :
<?xml version="1.0" encoding="UTF-8"?>
<Context docBase="../wars/MyApp.war"></Context>
In this way :
the conf/server.xml file is not modify
the name of the war file is not necessary ROOT.xml
resources are defined in conf/context.xml
But :
you must have one file in conf/Catalina/localhost/ per .war
wars are not auto-deployed
if you change the name of the root war file, you must modify the docBase attribute in conf/Catalina/localhost/ROOT.xml file.
I'm trying to put my application on the root context to wildfly.
I put this files jboss-web.xml:
<?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>
and the empty file bean.xml at WEB-INF/
The welcome-content is still working at localhost:8080
If you put localhost:8080/index.xhtml my application appears.
I tried renaming the direcctory welcome-content but no works.
SOLVED: REFRESH CACHE OF THE BROWSER
I'm working on a project, that has to run on JBoss 4.2.3 and I need to have a .properties file as an external resource. I found a short description on how to do that with JBossAS 7 - custom JNDI resource of type java.util.Properties
But this tutorial uses a configuration file \configuration\standalone.xml, and this file does not exists in my jboss AS 4.2.3. Looking for any advice here, thanks!
jboss 4.2.3 supports deploying a properties object to jndi. todo so, you use the jndi binding service manger. you create a XX-service.xml file and put that in your deploy folder. an example jndi-service.xml is:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE server PUBLIC "-//JBoss//DTD MBean Service 4.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss-service_4_0.dtd">
<server>
<mbean code="org.jboss.naming.JNDIBindingServiceMgr"
name="jboss.tests:service=JNDIBindingServiceMgr">
<attribute name="BindingsConfig" serialDataType="jbxb">
<jndi:bindings
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xmlns:jndi="urn:jboss:jndi-binding-service:1.0"
xs:schemaLocation="urn:jboss:jndi-binding-service:1.0 resource:jndi-binding-service_1_0.xsd"
>
<jndi:binding name="urls/jboss-home">
<jndi:value type="java.net.URL">http://www.jboss.org</jndi:value>
</jndi:binding>
<jndi:binding name="hosts/localhost">
<jndi:value editor="org.jboss.util.propertyeditor.InetAddressEditor">
127.0.0.1
</jndi:value>
</jndi:binding>
<jndi:binding name="maps/testProps">
<java:properties xmlns:java="urn:jboss:java-properties"
xmlns:xs="http://www.w3.org/2001/XMLSchema-instance"
xs:schemaLocation="urn:jboss:java-properties resource:java-properties_1_0.xsd">
<java:property>
<java:key>key1</java:key>
<java:value>value1</java:value>
</java:property>
<java:property>
<java:key>key2</java:key>
<java:value>value2</java:value>
</java:property>
</java:properties>
</jndi:binding>
</jndi:bindings>
</attribute>
<depends>jboss:service=Naming</depends>
</mbean>
</server>
see also
https://developer.jboss.org/wiki/JNDIBindingServiceMgr
I dont know how to explain it but let me try :
I have a eclipse JSF project named web-gestao
I would like to call from URL : http://www.domainxxx/simplefile.html and NOT http://www.domainxxx/web-gestao/simplefile.html
I need this for google verification purposes.
In jboss-web.xml
<?xml version="1.0" encoding="UTF-8"?>
<jboss-web>
<!-- URL to access the web module -->
<context-root>/</context-root>
...
...
...
I've just unpacked and configured Tomcat 8.0.3 on Windows 7 with a virtual host. I've tested it successfully under the default webapps, however, my virtual host is not recognizing changes in JSP files or classes.
Here is my set up:
%CATALINA_HOME%\conf\server.xml
...
<Engine name="Catalina" defaultHost="localhost">
...
<Host name="ww.virtual.com" appBase="vapps" unpackWARs="true" autoDeploy="true">
</Host>
</Engine>
...
%SystemRoot%\system32\drivers\etc\hosts
...
127.0.0.1 ww.virtual.com
%CATALINA_HOME%\vapps\ROOT\META-INF\context.xml
<?xml version="1.0" encoding="UTF-8"?>
<Context antiResourceLocking="true" privileged="true" reloadable="true">
<Resource name="jdbc/INVENTORY" auth="Container" type="javax.sql.DataSource"
maxActive="100" maxIdle="30" maxWait="10000"
username="sqlusr" password="secret1" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver"
url="jdbc:sqlserver://127.0.0.1:1433;instanceName=SQLSERVER;DatabaseName=INVENTORY"/>
</Context>
%CATALINA_HOME%\vapps\ROOT\WEB-INF\web.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app 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/web-app_3_1.xsd"
version="3.1"
metadata-complete="true">
<display-name>Test Display</display-name>
<description>Test Description</description>
<resource-ref>
<description>Test DB Connection</description>
<res-ref-name>jdbc/INVENTORY</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</web-app>
I then have JSP files located in %CATALINA_HOME%\vapps\ROOT\ and classes in %CATALINA_HOME%\vapps\ROOT\WEB-INF\classes\MainPackage\ which are properly loaded when the server is started. But if I make any changes to the JSPs or .class files, the server does not recognize the update. What am I doing wrong?
This is happening because you have enabled anti-resource locking. With that option enable the web application is not deployed from the appBase but from a copy in the work directory. If you edit the copy in the work directory you'll see the changes.
Alternatively, remove the anti-resource locking options and fix whatever bug caused you to need them in the first place.