Save files into deployed application folder with Openshift - java

I have an Java web application that uploads images and saves in a specific folder into main application folder:
- MyApplication
-- WEB-INF
-- META-INF
-- img_tmp
-- index.xhtml
...
My application saves images into img_tmp folder and the web pages get its. I'm using the getRealPath() method to get the root directory in local environment and it's working, but I've tried using the same method in Openshift environment and it doesn't work because I'm using WAR archives to deploy the application.
The question is: where Openshift unzips the WAR file and how can I access it? (OR) Is there an other way to deploy application in Openshift without using WAR files?
Thanks

In openshift you only can save files in a directory that is in an envirioment variable called $OPENSHIFT_DATA_DIR
And you can acess this value by
System.getenv("OPENSHIFT_DATA_DIR");
Heres a link to the openshift info about envirioment variables
https://developers.openshift.com/en/managing-environment-variables.html#directory-variables
Hope that helps.

Related

Tomcat Web Application Manager Not Listing Deployed App

I uploaded myapp.war file to server using Tomcat Web Application Manager
It upload myapp.war file but does not list in List of application.
myapp.war file and myapp (unzipped folder) is inside wepapps folder but also not listed in Application list. It only shows the default applications only.
Then i tried to upload again the same file and got error file already exists.
Why is it not listing the app though it is deployed?
Had the same issue. Even though tomcat manager says app is deployed successfully, you might be able to find the relevant issues in the catalina log.
<tomcat_home>/logs/catalina.xxxx-xx-xx.log

Eclipse Java Servlet access to higher level directory

I've installed Eclipse with web development and during download have installed Tomcat7 to dir E:\Eclipse\tomcat7.
When in Eclipse and trying to test the program I'm getting a realPath of
C:/Users/user/Documents/eclipseJEEWorkspace/javaWebPages/.metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/org.example.web/WEB-INF/classes/
as my real path and not what I expect which is E:\Eclipse\tomcat7\webapps\org.example.web/WEB-INF/classes/
1) how do I get the real path of the servlet rather than the temporary path...
or am I missing something with how Eclipse uses the installed server? If this is the way then do I have to continuously create the WAR and fiddle around recreating/deleting all the time?
The reason for this is I'm also trying to get a JAVA Servlet getting access to a file in a path higher than webapps. I'm new to servlets....
My development includes third party software that all reference an individual file our.properties so changing the structure is unfortunately not a option.
My directory structure is:
/tomcat
/mycompany
/properties
our.properties //the file we want to access
/*otherfiles
/html
/*not used in this context but to show usage
/javascript
/*not used in this context but to show usage
/webapps
/org.example01.web
/META-INF
/WEB-INF
/org.example02.web
/META-INF
/WEB-INF
/org.example03.web
/META-INF
/WEB-INF
How do I tell my Servlet to access the our.properties file?
I've tried getPath, getResource but without getting the first bit to work, I doubt I'll be getting anywhere fast.
Thanks
When you run Tomcat under Eclipse, via the Tomcat plugin, the webapps path is changed. Eclipse uses .metadata/.plugins/org.eclipse.wst.server.core/tmp0/wtpwebapps/ folder to deploy the project. That's not a temporary path, it's the actual path since your web application is deployed there.
If you run tomcat from command line, or as a service and deploy your web application, you'll see that the path of the servlet will be as you expected.
In order the change the default path to deploy for Eclipse, double click to your Tomcat under Servers view and modify Server locations section.

Website directory structure different from eclipse

I am coding a website using java servlets and am using eclipse and tomcat. When I test it using localhost, it works fine. But when I am deploying it on my actual website, the directory structure is messed up and the files are not called properly.
My eclipse directory structure on localhost is
Project Name
.src/packageName/java files
.WebContent/HTML files.
When I make a call from the html files, I use the relative location and tomcat automatically knows to look in the src/packageName folder. For example, from the /WebContent/login.html page makes a onClick call as follows,
. This will automatically trigger the java file in /src/packageName/welcome
When I am deploying it in my actual website, the WebContent/login.html is throwing an error WebContent/welcome file is not found. How do I tell my website to search in /src/packageName folder?
Hmm...have you been sure to package the application as a war for deployment.

Tomcat 404 for a folder in webapps

I have a folder called attachments in my webapps folder in my Apache Tomcat directory, in which I need to save some files and images. When I'm giving the local path i.e. in C:/ the files needed are being saved in the correct location.
However I need to load these images from the server at runtime so I'm trying to access the image by the localhost url /attachments/img.png. The image is not being found (404 error).
I tried opening Tomcat's manager to see if attachments is listed. It is there however when I click it a 404 error is being thrown too. Other deployed web applications are being found.
What could be the cause of this?
You cannot just create a folder in $CATALINA_HOME/webapps like this and access it from web browser.
webapps folder is supposed to be home for all web applications with proper J2EE web app like directory structure e.g. WEB-INF/web.xml, WEB-INF/classes, WEB-INF/lib, META-INF etc.
Read more about Web Application Directory Stricture

Deploy a .rar on cloudfoundry using eclipse plugin

I am currently using the cloudfoundry eclipse plugin to deploy my JSP/Servlet web application. My application is now using a Db (Sqlite). However I am having problem deploying the sqlitejdbc.rar to cloudfoundry (all i do to update the application is right click on my application under VMware Cloud-foundry server and select update. But that doesn't seem to work and i get an exception saying that it cant find the rar file.
In my local system i simply paste the sqlitejdb.rar to the lib directory of Tomcat and when i run the webapp locally it works
If you place the sqlitejdbc.rar file into your lib directory (inside your WEB-INF directory) that should get deployed as part of your application into cloudfoundry and become accessible.
You can also try to deploy your app using vmc push to see what errors you get from vmc.
I also recommend looking at the log files on cloudfoundry.com

Categories

Resources