I am having big issues deploying my web app to Tomcat 5.5
My server side code must access files found under a directory parallel to my WEB-INF folder.
When on developement mode, a simple relative path (mydirectory/myfile) works prefectly.
When deployed, the sayed path does not work anymore I dont know why.
Is there a way to make it work without using any absolute path?
Here is my War directory
War
WEB-INF
Mydirectory
Myfile
Mywebbapp.html
Obtain your root folder relative to contextRoot by calling javax.servlet.ServletContext.getRealPath("/"). Then proceed with this path...
Using relative path will work, but you need to be aware of what the containers considers to be the root directory and base your relative path from there. If you specify your directory structure better, I can help you with the path - Basically try using the .. operator to move from the container root to the needed directory
Related
We run JBoss 6 in standalone mode. We do have a folder (content.war/) in deployments that contains a symlink to a different folder (let's call it docs). Symlinking is enabled in jboss-web.xml with <symbolic-linking-enabled>true</symbolic-linking-enabled>. Our scenario is to use this to serve static files via this app context.
We do deploy the folder using touch content.war.dodeploy. It all works fine when the docs folder contains just few files. When the docs folder points to actual folder that has around 30GB the deployment seems to be stuck (the folder is not deployed and no other deployment works afterwards).
I believe that JBoss tries to somehow traverse or scan the whole folder. Is it possible to somehow disable this behaviour?
One workaround seems to do the trick. I can deploy an empty exploded war folder and once it is deployed I create the symlink to the huge folder.
Disadvantage: When JBoss is restarted it gets stuck again. I'd need to remove the link and create it again after deployment.
Another option is to use welcome-content that JBoss uses to serve static content. I can remove the original welcome-content folder and create a symlink to my folder instead.
ln ‐sv /home/mypath/my-static-content ${JBOSS_HOME}/welcome‐content
Disadvantage: This doesn't allow you to use any symlinks inside your folder or subfolders.
I have the following site directory structure (on a shared hosting):
/home/username/
public_html/
index.html
resources/
config.php
I am trying to set up a new project using the remote deployment in PhpStorm. I'd like to have both public_html and resources folders accessible, since both contain PHP files. I am confused by what should be the Project Root. Logic suggests that my project root is the top level directory containing all my files, i.e. /home/username/.
However if I mark it such in PhpStorm, the next screen (Specify Web Path) automatically maps my web root folder to the project root.
As the result, if I run /home/username/public_html/index.html from PhpStorm, it tries browsing to https://webroot/public_html/index.html. This is wrong. The web root should be mapped to /home/username/public_html. Actually, the very question ("Web path for project root '/home/username'") is invalid, since there is no web path to folders above public_html, that's the whole point of putting resources there. How should I properly configure folders in PhpStorm?
Such setup is definitely possible -- its very common to have website root folder as a sub-folder of the actual project.
As far as I'm aware it is not possible to create such setup right from New Project Wizard -- it has to be done at later stage when project creation was completed.
You need to go into Settings/Preferences | Build, Execution, Deployment | Deployment and add new mapping. Here is an example:
Here my website root is located in web folder -- you will have to change that to yours public_html. This way when you use Open in Browser on file inside your web root folder it will be opened with correct URL.
I am trying to use relative paths in a Dynamic Web Project in Eclipse. I am NOT using them in the Servlet, but in another class that is called by the Servlet. The file I am trying to access to is a property file located in
MyProject/WebContent/WEB-INF/propertyFile.properties
I have tried almost every relative path...
WebContent/WEB-INF/propertyFile.properties
/WebContent/WEB-INF/propertyFile.properties
./WebContent/WEB-INF/propertyFile.properties
MyProject/WebContent/WEB-INF/propertyFile.properties
/MyProject/WebContent/WEB-INF/propertyFile.properties
WEB-INF/propertyFile.properties
/WEB-INF/propertyFile.properties
./WEB-INF/propertyFile.properties
...and so on...what can I do?
Thanks in advance!
You nee to understand that file IO read files, from the filesystem, and relative to the directory from which the JVM (i.e. your web container) is started.
Remember that, once your app is deployed to production, there won't be any MyProject or WebContent folder. That's what exists on your development machine. The only thing that will exist in production is the war file deployed in the application server.
What you actually want is to load a resource, located in the deployed web application (i.e. which is inside your war file).
To do that, you must use ServletContext.getResourceAsStream():
InputStream in = servletContext.getResourceAsStream("/WEB-INF/propertyFile.properties");
In Tomcat 7, I want my welcome page (index.html) to load when I access localhost:8080/. Right now, I have to go to the webapp context, localhost:8080/MyWebApp.
Is there a folder in Tomcat to place pages that are not part of a webapp? I'm confused how this works...
EDIT: I notice that the web.xml for the Server in Eclipse has a servlet called "default" which is mapped to "/"... I wonder if I have to change something here?
EDIT2: I found this: http://wiki.apache.org/tomcat/HowTo#How_do_I_override_the_default_home_page_loaded_by_Tomcat.3F
But, I already have an index.html in my ROOT folder, and still getting 404 from the root URL. If I start the server without using Eclipse, it works. What's going on here? What exactly does Eclipse do when you start the server through it? Obviously it's not reproducing the ROOT folder of my installation.
You are missing ROOT folder from 'webapps' - maybe it was deleted during installation of the other app. ROOT folder has config files for 'Welcome' page for tomcat. You can copy it from the other tar file into ../webapps folder and you'll be good.
In Apache Tomcat, all websites are deployed as individual web applications. You can verify this with the Tomcat configuration manager, where you are able to start/stop/reload certain web applications.
I believe you would like to place the welcome page in path tomcat/webapps/index.html - all files located here not in a webapp of subfolders should be viewable as the root of the url.
It's only anything above webapps in tomcat that's protected from web browsing. maybe you can try putting the file in index.html, and setup a link preceded by ../ to indicate "go a directory level above in the tree" to fetch this required file, or try listing the directory of the url root to see in which context you're in actually.
Hope this helps clarify something at least.
Solved!
http://wiki.eclipse.org/WTP_Tomcat_FAQ#If_I_start_my_Tomcat_server_and_try_to_display_Tomcat.27s_default_page.2C_why_do_I_see_a_directory_listing_or_404_error_page.3F
how can i find which folder is the jboss root dir?
where can i find the root folder variable mentioned in a war file
IF you are looking for root folder that is right option. It would be
/opt/jboss/jboss-as
But if you want to access anything (xml, file) at root directory say using 'http://ip:port/abc.xml' url you want to open abc.xml or any file, put that file in
/opt/jboss/jboss-as/server/default/deploy/jboss-web.deployer/ROOT.war
The root folder of a JBoss AS installation is generally considered to be the ../jboss-as folder...
For example if your deploy folder would be
/opt/jboss/jboss-as/server/default/deploy
the root folder would be
/opt/jboss/jboss-as
I don't know what you mean by the variable mentioned in a .war file.
Somehow the maven-war-plugin , can solve this issue very easily. If web.xml context-root didn't work the plugin could move the application to the root of deployments on tomcat. Everything that isn't captured by a more specialized service is delegated to the application from web root /* to the web-app, :)
source : https://developers.openshift.com/servers/jbossas/deployment-options.html