jboss 6 virtual directory - java

I cannot find a proper way to add a directory to my app context on jboss 6.
I'll use this mapping for static content. Can someone give me a hand on that?

There are no more 'virtual directories' in JBoss 6. Apparently this went out with JBoss 5. The only available options I've found are:
create a blank /WEB-INF/web.xml (so like just <web-app/>) in your static content directory and make a symlink with a .war extension in your jboss deploy directory. You can also copy the directory containing the static content to your deploy directory, but I find a symlink much more useful.
create a webapp with a servlet that serves static content from a configured directory (discussed here)
if you're using a web framework like spring mvc 3, you can use the 'resources' feature to serve content for you (discussed here)

The bad news is that you can serve static content only inside JBoss applications. The good news is that it is very easy to transform any folder into an application folder.
The easiest solution is to copy all your static content into your server\default\deploy\ROOT.war directory.
A more complex solution is the following.
Copy the ROOT.war folder in the position where you want to put your
static content.
Rename ROOT.war into any name you like but it must end with .war,
for instance my_static_content.war.
Put all your static content into that directory.
Enable external deploy to the folder that contains your static
content folder. External deploy with JBoss 6 and JBoss 5
Restart JBoss
Your content will be into the URI http:\\localhost:8080\my_static_content\. You have to specify the exact name of the files that you want to serve, because directory listing is not allowed.

this thread helped me get static content in an external directory served up on jboss eap 5.1 without the use of links and without moving or renaming the ROOT.war folder.
note that you still have to create a directory structure that tricks jboss into serving up your content. it's not as easy as adding a <Context> child element to the <Host name="localhost"> in the server.xml file. it seems like a hack but at least it works.

Related

How to change application deployment path in Tomcat

I have this directory structure in Tomcat: /webapps/webserver/warfile
When I try to start Tomcat, it can't look to the subfolder webserver and thus read the WarFile. If I change the directory structure like this: /webapps/warfile, everything works fine and I can access my application.
I know it would be easier if I just move the war file to the webapps directory, but it is a long story why I need in this way.
You can probably try changing base directory for deployment
Find server.xml at $CATALINA_BASE/conf/server.xml
Then, change appBase to your required path.
Please refer Apache Tomcat 8 Configuration Reference

Rename war file to change the context path of an webapplication

I am building a webapplication with maven. I want to change the name of the generated warfile to get a different context path.
To clarify misunderstandings: It is not about changing the name during development, it should be possible without touching any code (e.g. for customers). Also it should be possible to deploy those war on different servers (like WildFly, Tomcat etc.).
Example:
Hello.war = Hello.war -> URL: localhost:8080/Hello
stupid.war = stupid.war -> URL: localhost:8080/stupid
How can I achieve this? Is that even possible?
For popular servlet containers (JBoss, Tomcat, Jetty), WAR naming convention can drive context paths. Name of the war becomes the context path if no explicit context path is defined anywhere.
a.war > localhost:8080/a
b.war > localhost:8080/b
The problem then is just to rename the war into different names as per your clients.
https://docs.jboss.org/jbossas/guides/webguide/r2/en/html/ch06.html
https://tomcat.apache.org/tomcat-7.0-doc/config/context.html#Naming
http://www.eclipse.org/jetty/documentation/current/configuring-contexts.html
Overriding the default finalName element within the build element to the desired filename (without extension) may archive what you wish. You will then of course need to take care with versions. eg.
<build>
<finalName>YourName</finalName>
</build>
the easy way to do this is
to rename the file extension.war to .zip and expand it (double-click it)
drag out the web.xml to desktop
make changes to web.xml accordingly
drag the modified web.xml to its original location and replace the original
rename the file extension back to .war

web.xml configuration for JSP

This is the structure of the JSP app on eclipse.Once I run it on eclipse using tomcat server(localhost:8090/index4.html) it works.On the index page i have to add details,this details are uploaded via the servlet as you can see above Java Resources->src->FileUPloadDBServlet(Also I am not sure if it uses this or it uses WEB-INF->src->FileUploadServlet below.)
In my index4.html the action is action=uploadServlet(no address given for it).This everything works on using eclipse.
But once I put the QMS folder(not WAR) from eclipse worskspace to tomcat ROOT,the index4.html works but the following action,i.e uploadServlet doesnt work(here I use the address localhost:8090/WebContent/index4.html)I dont have a web.xml.
Is that creating a problem?
Please provide me help.
You need to put your project folder or .war file in the
webapps folder of Tomcat directly not in ROOT folder under webapps.
Try to follow directory structure as follows
Photo Courtesy http://www.studytonight.com/servlet/steps-to-create-servlet-using-tomcat-server.php (Here you can also find more details on Servlet and JSP, as well as project structure)
Where you have your web.xml put into the WEB-INF folder under your application folder.
For java files you don't need the source files, the classes folder will have all the source folder (src) files compiled and ready to execute.
The lib will contain all the .jar files you need for your application to run.
Make sure you put web.xml file at proper place, because without it, application will not be able to run. Because as they say web.xml is Heart of the application.
Let me explain you the problem.
When we configure a dynamic java project to run on eclipse the server takes the just the stuff from webcontent folder and deploy it the wbcontent folder contains web.xml file which defines the url descriptor for servlet.
now when you copy the whole folder the server can not find the web.xml file which is a descriptor where it expects the file to be.
hope its clear comment for clarification

Preventing access to war file without using .htaccess / apache conf

Currently when I deploy a war file to Tomcat it can be downloaded from the URL via something like foo.com/myapp.war.
Most places recommend that you put an entry in a .htaccess file to prevent public access to any war files, or failing that an equivalent entry in your Apache config.
Unfortunately, my host does not provide access to the Apache config (although I can access Tomcat confs) and .htaccess files do not work for all Tomcat/Java related hosting environments. Pretty disappointing. They have been rather unhelpful in this respect.
Without resorting to something like "finding another host" (other than this issue they are fine - I'd rather stay here until my app grows too big), is there anything else I can do to prevent public users accessing my war files, yet still allow Tomcat to deploy the apps when it scans them?
For example, is it possible to specify one directory for Tomcat to scan for war files yet have it deploy the war into the public directories?
Thanks.
It is probably better to ask at https://serverfault.com/. It all boils down to how Tomcat is setup.
The vanilla setup will have a folder called webapps under CATALINE_HOME. You put your WAR archives there (they get auto-extracted and deployed). These folders will not be accessible from HTTP (you cannot download WAR archives from some URL like /webapps/my-test.war). These apps in webapps folder are deployed to some context roots. For example an application my-test.war will by default get deployed as yourhost.com/my-test/.
If you can download your WAR archives from foo.com/myapp.war maybe you can check out what does the CATALINA_HOME/webapp/ROOT app is doing. By default this is deployed under the foo.com. Ask from the host the Tomcat configuration files to figure what kind of custom configurations are they using.
You can place your .war files in any location Tomcat has access to. But you will have to tell Tomcat about it, so it picks them up. You can do this by placing a configuration XML file in
<CATALINA_HOME>/conf/Catalina/localhost/myWebapp.xml
There are samples on what to put into that file myWebapp.xml, e. g. here, step "4)". And of course, the official documentation.

Java web application context

I have a Java web application. Inside the WAR I have a folder containing configuration files for the application. I need to know the path of the folder in order to load the files at runtime.
I also need the solution to work in Tomcat and in WebSphere.
Thanks.
I would suggest placing the files under WEB-INF/classes and simplying loading them from the classpath, not from the filesystem. This way, the path is always the same.
You can use something like:
InputStream stream = Thread.currentThread().getContextClassLoader().getResourceAsStream("path");

Categories