How to change the path that jar files use in java Web Applications - apache

I have written a java Servlet web application, using NetBeans 7.2.1. The program have some jar file libraries that I have attached to the project. The application runs fine using NetBeans and Apache Tomcat 7.0.27.
My problem is that some of the jar file libraries that I am using in the project, need to access to some folders and files. I put these folder and files on the same directory as the whole NetBeans project is. but I got this exception:
Exception: java.lang.RuntimeException: java.io.FileNotFoundException
So I used these codes to find out where should I put them:
out.println("current directory: " + new File(".").getAbsolutePath());
out.println("current directory: " + System.getProperty("user.dir"));
out.println("current directory: " + getServletContext().getRealPath(("/")));
So I figured out that the current working directory is:
C:\Program Files\Apache Software Foundation\Apache Tomcat 7.0.27\bin
My question is that how can I set different directory address for each web application? I have many web applications and some of them use the same resource file names. I can't just put all of them in one directory.
Please note that I don't have access to the source code of jar files to change the. I just need a way to set the absolute path that the jar files use.
I have the same problem when I put the WAR file on the unix server. The extracted WAR file is in this location on the server:
/data02/tools/Apache/Tomcat/apache-tomcat-6.0.37/webapps/BANNEROnline
But I figure I should put the resource folders and files in this path (moosavi3 is my username!):
/home/moosavi3
How can I change the path?

The working directory is the directory from which java.[exe,bin] is started. I assume the bin directory is where the tomcat start-up script is? If the jars are all using this working directory I don't believe there is a way to make different web-apps have different working directory, they're all loaded on the same jvm (java.exe) from the same working directory.
A working directory is the directory from which a binary is started, it is not some arbitrary value that you can change.
I suspect these jar files where meant to be run as standalone applications and expected the filesystem resources they are trying to access to be in the same location as themselves.
Any filesystem resources would have to be moved to the location of your java.exe so that the correct file path resolution can result from your jars.

Standard Servlet project requires external libraries to be placed in the 'WEB-INF/lib' directory under project root. You can search google for 'servlet directory structure' and do your own research for more information. Shared libraries between web applications can be placed in the 'lib' directory under tomcat root, they should be picked up by tomcat jvm. My recommendation would be to keep the dependencies project specific, because you may need different versions in different projects in the future.
Update:
Read this page on the tomcat documentation, it will explain exactly how the project should be structured, and how to add a library that will be shared across all web applications:
http://tomcat.apache.org/tomcat-7.0-doc/appdev/deployment.html
Update 2:
The following Stackoverflow link explains several options how to add a static file to your web application, that will available at runtime.
https://stackoverflow.com/a/2161583/940754
Update 3:
Add a path to the classpath using the project's manifest:
http://docs.oracle.com/javase/tutorial/deployment/jar/downman.html

Related

unable to include external files in a project

I have created the default play application in IntelliJ in directory P. I have over-written the default index.scala.html with my own html code. The html code refers to some css and js files which are outside the directory P. To include these external files, I added the directory of these files using project configuration settings.
My webpage doesn't load properly as the server returns 404 for the css and js files. What am I doing wrong?
When you added your directory using project structure, you only say:
Hey, IDEA, please consider this folder part of my project, consider
its contents source code and display it when I open my project.
However, when you deploy or run your app, you only deploy the usual folders to the server, which contain the resources which will be available for clients to access.
The external directory is not part of these directories and will not be deployed.
What you can do is to copy the file from the external directory as a part of your build process before deploying the application.
EDIT: Detailed answer here: What is intellij's build process for play applications

Where should the files referred from GlassFish server 3.0 web app reside?

I have deployed my web application in GlassFish server 3.0. When I execute it, I get an error: The system cannot find the file specified (MobileOntologyRev1.owl) , which is a file from which I read in my code (I haven't specified the absolute path for this file in my code, and simply refer it using the file name without any addtional path) . Where should this file be kept in order to access it? I have presently tried keeping it inside the WEB-INF/Classes folder and in the root dir of the application inside glassfish/domains/domain1/
Where should I place this file??
You may consider taking advantage of the FaceContext as mentioned below.
You can create a folder (repors) inside your WEB-INF for example.
String pathToFile=
FacesContext.getCurrentInstance().getExternalContext().getRealPath("/WEB-INF/reports/MobileOntologyRev1.owl");

Eclipse project root equivalent to Axis2.war

I have multiple non-jar resources to load within an aar file of Axis2.war.
Most of them are successfully loaded using configuration table where absolute path of
each resource(text files) is specified.
But I have an open-source-based jar that loads resource at the root path(??)
of Eclipse project which is at the same level of "src" folder.
When the classes of the project above are jarred into a lib of aar,
the resources has no way of being read by the class that needs it.
I've put them just outside of aar, within the lib of aar or at the same level of the lib.
They just don't work.
Please remember that this is the case where getResourceStream or something like that
can't be used, because the jar has hard coded the path to be located at the root path of
a project of Eclipse.
Then my question is where the Eclipse-project-root-path-equivalent in Axis2.war which is
deployed in JBoss 5.1.
I am not sure if this question is understood, but please give a bit of advice.
//
Referential images that describe the situation above can be found at
https://community.jboss.org/thread/221937
I used System.getProperty("user.dir") to find exactly where the jar refers to the resources and in
my case C:\Users\MYUSERACCOUNT\Development\server\jboss5.1\server\default\deploy\axis2.wβ€Œβ€‹β€Œβ€‹ar\WEB-
INF\services MYUSERACCOUNT is the root of an AAR in Axis2.war service folder. So I placed the
required resource folder within my account folder ( Windows 7 ) and it worked

What is the file structure of the Share Webscript extensions for Alfresco 4.0.3+

I've been reading David Drapers' blog on the new feature - the extension of share webscripts, but I didn't find any working examples. What is the file naming and structure convention?
From what I gather, I have a module configuration file, and I don't know how to name it or where to put it (share/WEB-INF/classes/alfresco?)
Also, I understood that my custom client side resources (.js and .css files) go to META-INF/custom-dashlet/extension/ in the JAR file. Is this correct? Finally, the *.get.js and *.get.html.ftl go to webscripts/com/mycompany/mypackage/*?
So I have now:
*share/WEB-INF/lib/mypackage.jar*
and in it:
*META-INF/mypackage/extension/myfile.js
webscripts/com/mycompany/mypackage/myfile.get.js
webscripts/com/mycompany/mypackage/myfile.get.html.ftl
*
and the
*share/WEB-INF/classes/alfresco/something.xml*
This question was also posted to the Alfresco forums here: https://forums.alfresco.com/en/viewtopic.php?f=48&t=46438
The answer provided was as follows:
An extension module a Surf configuration object so you should place XML files containing module configuration in any of the locations where Surf config gets picked up... e.g. <web-server>/webapps/share/WEB-INF/classes/alfresco/site-data (there are lots of places where Surf configuration gets picked up, but alfresco/site-data on the classpath is the most common). Extension config files should be placed in the extensions folder within the directory. So you could place an extension config file in: alfresco/site-data/extensions or alfresco/web-extension/site-data/extensions, for example.
You could create a JAR file containing this folder structure. Everything that the extension refers to (e.g. WebScripts, other Surf config objects such as Pages, Template-Instances, Components, etc) should just be placed in their normal location. These can also be built into a JAR file.
If you want to access resources (e.g. CSS, images, JS) from a JAR file then place them in the META-INF folder of the JAR. You should place your JAR file in the <web-server>/webapps/share/WEB-INF/lib directory (obviously your server will need to be restarted to pick up new JAR contents).
WebScripts should be in (on the classpath):
alfresco/site-webscripts
alfresco/web-extension/site-webscripts
webscripts
You can also configure other locations in the Surf configuration from which to load Surf config objects/WebScripts. It's pretty much endlessly customizable but you should probably just stick to the default locations configured for Share.

Loading property files in weblogic 10.3

I have an application which acesses a lot of property files. In jboss 5.1 we can load this from the conf directory. I would like to know if there is any such way of loading the property files in weblogic 10.3 .
I don't want to include it in an jar and place in the lib,since these property files are configurable files. The user needs to configure certain properties of the application.
Also placing the property files in the domain directory is not very good and I also would like to know if there is any other way of achieving the same .
Regards
Raj
You can place the properties files needed by your application(s) to the classpath of Weblogic and then remove the files from your WAR/JAR/EAR.
If you choose a specific folder that is not yet in your classpath, just log on the Weblogic console, and navigate through Environment -> Servers -> [Your server name] -> Configuration -> Server Start
Now it is just about adding the folder containing your properties file(s) to the classpath.