How to get the physical path of my web app root context ?
Hi,
I used this code to initialize my LOG4J logger.
System.out.println(Version + "Servlet context path : " + sctx .getContextPath());
String path = sctx .getRealPath("/");
fullyqualifiedlog4jpath = path + "log4j.xml";
File locallogxml = new File(fullyqualifiedlog4jpath);
if (locallogxml.exists()) {
initialized = true;
DOMConfigurator.configure(fullyqualifiedlog4jpath);
log = Logger.getLogger(Log4j.class.getName());
log.info(Version + "Logger initialized");
else {
System.out.println(Version + "Unable to locate the log4j.xml file");
}It works perfectly when running the application with the embedded Jdev11 WLS.
When deploying the application on a standalone WLS server the path is not returned ;-( I get a null value.
Does someone has three lines of code which get the physical path of my web app root context?
Yves
Changed the methiod used to access log4j.xml.
FacesContext ctx = FacesContext.getCurrentInstance();
ServletContext sctx = (ServletContext) ctx.getExternalContext().getContext();
String contextPath = sctx.getContextPath();
HttpServletRequest hsr = (HttpServletRequest)ctx.getExternalContext().getRequest();
String host = hsr.getServerName();
int port = hsr.getServerPort();
try
String urlstring = "http://" + host + ":" + port + contextPath + "/faces/log4j.xml";
DOMConfigurator.configure(new URL(urlstring));
log = Logger.getLogger(Log4j.class.getName());
.....using the URL s OK.
Similar Messages
-
How to get the current path of my application in java ?
how to get the current path of my application in java ?
thanksTo get the path where your application has been installed you have to do the following:
have a class called "what_ever" in the folder.
then you do a litte:
String path=
what_ever.class.getRessource("what_ever.class").toString()
That get you a string like:
file:/C:/Program Files/Cool_program/what_ever.class
Then you process the result a little to remove anything you don't want:
path=path.substring(path.indexOf('/')+1),path.lastIndexOf('/'))
//Might be a little error here but you should find out //quickly if it's the case
And here you go, you have a nice
C:/Program Files/Cool_program
which is the path to your application.
Hooray -
How to get the absolute path of logicalhost server domain on Windows Sun
i am reading a file from Xsql Folder, that is located in the logicalhost Sun\AppServer\domains\domain1\applications\j2ee-apps.(IN Sun Application Server)
I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
i tried with System.getProperty("com.sun.aas.instanceRoot").
but i am able to retrive Sun\AppServer\domains\domain1 upto this .i am unable to retrive Sun\AppServer\domains\domain1\applications\j2ee-apps.
please suggest me how u can get absolute path in sun application serverTake a look here
-
How to get the absolute path of logicalhost server domain on Windows?
My logicalhost server domain behaves strangely. I am reading a file from collaboration definiton, that is located in the logicalhost/is/domains/domain1/config folder. I thought, that this folder is used as an application root folder so I can read files like ./file from there. And it worked.
But then I've installed the domain as a Windows service, restarted the PC. When the domain1 gets started, I get exceptions saying that the file can't be found. Then I restart the domain (in domainmgr.bat) and it works again.
I am pretty sure that using the absolute path will solve this issue, so my first question is: How to get the absolute path of logicalhost server domain on Windows?
And my second question is: Why does this happen?The default folder for a Windows Service is the system32 folder contrary to the instance root folder when starting it as a normal process.
That's the why, haven't tried the how, but you should be able to get the value by calling System.getProperty("com.sun.aas.instanceRoot").
Hope this helps
Paul -
How to get the full path instead of just the file name, in �FileChooser� ?
In the FileChooserDemo example :
In the statement : log.append("Saving: " + file.getName() + "." + newline);
�file.getName()� returns the �file name�.
My question is : How to get the full path instead of just the file name,
e.g. C:/xdirectory/ydirectory/abc.gif instead of just abc.gif
import java.io.*;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import javax.swing.filechooser.*;
public class FileChooserDemo extends JFrame {
static private final String newline = "\n";
public FileChooserDemo() {
super("FileChooserDemo");
//Create the log first, because the action listeners
//need to refer to it.
final JTextArea log = new JTextArea(5,20);
log.setMargin(new Insets(5,5,5,5));
log.setEditable(false);
JScrollPane logScrollPane = new JScrollPane(log);
//Create a file chooser
final JFileChooser fc = new JFileChooser();
//Create the open button
ImageIcon openIcon = new ImageIcon("images/open.gif");
JButton openButton = new JButton("Open a File...", openIcon);
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int returnVal = fc.showOpenDialog(FileChooserDemo.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//this is where a real application would open the file.
log.append("Opening: " + file.getName() + "." + newline);
} else {
log.append("Open command cancelled by user." + newline);
//Create the save button
ImageIcon saveIcon = new ImageIcon("images/save.gif");
JButton saveButton = new JButton("Save a File...", saveIcon);
saveButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
int returnVal = fc.showSaveDialog(FileChooserDemo.this);
if (returnVal == JFileChooser.APPROVE_OPTION) {
File file = fc.getSelectedFile();
//this is where a real application would save the file.
log.append("Saving: " + file.getName() + "." + newline);
} else {
log.append("Save command cancelled by user." + newline);
//For layout purposes, put the buttons in a separate panel
JPanel buttonPanel = new JPanel();
buttonPanel.add(openButton);
buttonPanel.add(saveButton);
//Explicitly set the focus sequence.
openButton.setNextFocusableComponent(saveButton);
saveButton.setNextFocusableComponent(openButton);
//Add the buttons and the log to the frame
Container contentPane = getContentPane();
contentPane.add(buttonPanel, BorderLayout.NORTH);
contentPane.add(logScrollPane, BorderLayout.CENTER);
public static void main(String[] args) {
JFrame frame = new FileChooserDemo();
frame.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0);
frame.pack();
frame.setVisible(true);simply use file.getPath()
That should do it!Thank you !
It takes care of the problem !! -
How to get the absolute path of a file from the local disk given the file n
how to get the absolute path of a file from the local disk given the file name
// will look for the file at the current working directory
// this is wherever you start the Java application (cound be C: and your
// application is located in C:/myapp, but the working dir is C:/
File file = new File("README.txt");
if (file != null && file.exists())
String absolutePath = file.getAbsolutePath(); -
How to get the ablolute path of the web application in WebSphere?
How to get the ablolute path of the web application in WebSphere?
For example:
I have installed IBM WebSphere on D:\WebSphere\Appserver, and I created a new appliction named "myapp" on D:\myapp,. How can I get the absolute path of application "myapp"? In other words,how can I get the absolute path of the application's
root directory?In the WebSphere(default), what directory is the Java Bean's root directory ?
-
How to get the document path of the pictures uploaded for products?
Hi Gurus,
How to get the document path of the pictures uploaded for products uploaded through tcode COMMPR01?
Many Thanks,
Neerajclient path.
I need to get the client path in order to download files form server to client.
Best regards,
Huy. -
How to get the project path ?
In my servlet, how do I get the project path ?
I have the following dir structure :
Web_App
+ build
lib
+ nbproject
+ src
test
+ web ( index.jsp , my.jsp , my.html )
+ Dir_Docs ( my file : ABC.txt ) My Servlet is :
public class My_Servlet extends HttpServlet
public void init(ServletConfig config) throws ServletException
super.init(config);
public void destroy() { }
protected void processRequest(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
response.setContentType("text/html");
PrintWriter out=response.getWriter();
out.println(System.getProperty("user.dir"));
}What I got was : C:/apache-tomcat-6.0.14/bin/
How to get the project path ? Which is : C:/Web_App/ ?Yes, config.getServletContext().getRealPath("index.jsp"); got the job done !
Thanks. -
How to get the application path?
Does some body know how to get the application path in Java? Here is an example about what I'm thinking: Let's imagin the application is on "c:\try" or "c:\ProgramFiles\MyApp". My question is how can I find the path where the application is. Please give an example if you know the answer. Thank you so much.
Those two replies give you some useful directories, it's true, but maybe not what the OP asked. However the OP asked for something that doesn't have a meaning (applications don't have to be "on" any directory, whatever that might mean).
Would the OP like to describe what the actual problem is here? -
How to write the folder path in standard webi report - Most Accessed Documents
How to write the folder path in standard webi report - Most Accessed Documents
All
-> Public Folders
-> Auditor
-> ABCD
I want to give path of folder 'ABCD' and all the reports/ subfolders under it?
Prompt - 'Enter the Folder Path(Add % at the end to include Sub Folders)' ?
Give me exact path syntaxHi Daniel,
But when I give my URL as
http://serverA:80/irj/portal??NavigationTarget=ROLES://portal_content/crm-practice/14-Feb/Test_Page
I am able to access the iview but the thing is I am getting TLN,Toolarea,Masthead,etc.
I will tell my requirement,
ServerA (EP 7.0) has some iviews,pages...
I need to access these iviews from serverB(EP 6.0)....
In ServerB only the iviews has to be displayed in the content area but not TLN,Toolarea,etc.
Kindly help me in this regard.
Thanks and regards,
Purushothaman.
Message was edited by: Purushothaman Vyasarao -
How to get the return values from a web page
Hi all :
how to get the return values from a web page ? I mean how pass values betwen webflow and web page ?
thank you very much
Edited by: jingying Sony on Apr 15, 2010 6:15 AM
Edited by: jingying Sony on Apr 15, 2010 6:18 AMHi,
What kind of web page do you have? Do you have possibility to for example make RFCs? Then you could trigger events (with parameters that could "return" the values) and the workflow could react to those events. For example your task can have terminating events.
Regards,
Karri -
How to get the file path in adf application
hii all,
i have a txt file that i am using in my adf application,
i am passing this txt file through a File Reader, for which i have to mention the file path.
The file is in web-content and when i am hard coding the complete file path i.e C:/JDeveloper/myApp/ViewController/public_html/log.txt
the application is working fine when run on integrated weblogic server.
My requirement is to access this file without giving the static file path, as in case i have to use this application on any other machine..
for that how to mention the file path-
i tried using FacesContext to get the context path :-
FacesContext.getCurrentInstance().getExternalContext().getRequestContextPath();
which gives me
\myApp-ViewController-context-root
after appending public_html\log.txt
I am using the following path to access the file :-
\myApp-ViewController-context-root\public_html\log.txt
again i am getting the java.io.FileNotFoundException
Does anyone know how to use file from inside the web-content without giving the complete path..???
ThanksHi,
If you put your file under public_html folder, you can use this code to access the file:
For example file is : log.txt
FacesContext.getCurrentInstance().getExternalContext().getRealPath('/log.txt').toString().trim();
Thanks.
- LSR -
How to get the output path in Java?
Hi all,
is there a way (method) to get the output path (where compiled classes are put) in Java?
thx a lot!
MicheleIf you have already successfully loaded the classes into memory, and you want to find out where the classes are physically stored, then you can use Class.getResource() to retrieve the location of the file.
import java.net.URL;
public class Find
private void run(String obj) {
try {
Class cls = Class.forName(obj);
//Here is the change to input correct resource path
//instead of class name
String resourcePath = "/"+obj.replace('.','/')+".class";
URL url = cls.getResource(resourcePath);
System.out.println(url);
catch (Exception e) {
e.printStackTrace();
public static void main(String[] args) {
Find find = new Find();
find.run(args[0]);
}java Find java.lang.String
jar:file:/usr/local/j2sdk1.4.2_13/jre/lib/rt.jar!/java/lang/String.class
Edited by: Jin on Oct 23, 2007 10:38 AM -
How to find the physical path of the ASM disks?
I am in a dilemma on how to find out the physical path of the ASM disks. I tried the following query, but as you can see it is not providing me the physical path of the LUN. This is a 2 node 10.2.0.4 RAC Cluster using asmlib package.
col name format a20
col path format a20
col label format a20
select name, path, label from v$asm_disk;
NAME PATH LABEL
ORCL:ASM103 ASM103
ORCL:ASM104 ASM104
ORCL:ASM117 ASM117
ASM101 ORCL:ASM101 ASM101
ASM102 ORCL:ASM102 ASM102
ASM105 ORCL:ASM105 ASM105
ASM106 ORCL:ASM106 ASM106
ASM107 ORCL:ASM107 ASM107
ASM108 ORCL:ASM108 ASM108
ASM109 ORCL:ASM109 ASM109
ASM110 ORCL:ASM110 ASM110
NAME PATH LABEL
ASM111 ORCL:ASM111 ASM111
ASM112 ORCL:ASM112 ASM112
ASM113 ORCL:ASM113 ASM113
ASM114 ORCL:ASM114 ASM114
ASM115 ORCL:ASM115 ASM115
ASM118 ORCL:ASM118 ASM118
ASM119 ORCL:ASM119 ASM119
ASM120 ORCL:ASM120 ASM120
ASM121 ORCL:ASM121 ASM121
ASM122 ORCL:ASM122 ASM122
ASM123 ORCL:ASM123 ASM123
NAME PATH LABEL
ASM124 ORCL:ASM124 ASM124
ASM125 ORCL:ASM125 ASM125
ASM126 ORCL:ASM126 ASM126
ASM127 ORCL:ASM127 ASM127
ASM302 ORCL:ASM302 ASM302
ASM303 ORCL:ASM303 ASM303
ASM304 ORCL:ASM304 ASM304
ASM305 ORCL:ASM305 ASM305
ASM306 ORCL:ASM306 ASM306
ASM307 ORCL:ASM307 ASM307
32 rows selected.
Any help will be appreciated.
--MMhi
use the following linux command as root:
$oracleasm listdisks
hth
Maybe you are looking for
-
HT4623 Why can't I install any apps keeps saying that my session has timed out
Why can't I install any apps it keeps saying my session has timed out
-
FM for checking Windows Authentication
Hi All, Is there any function module / class / method etc available for checking windows based authentication? My purpose is to call such FM (If available) from a web based interface as RFC, Kindly advise. Thanks in advance. Regards Vipin
-
How to remove or upgrade itunes on windows 7
I cannot download and install iTunes64 bit or 32 bit on Windows 7. I get a permissions problem.
-
Oracle EBS R12 (12.1.3) / 11.2.0.2 OS : Oracle Linux Can we browse the oracle application modules using the iPhone/iPad. If yes, what additional configuration/setups require to do in EBS. Thanks in advance. Thanks
-
RunTime binding of database adapter.
Hi All, I am trying to work through a requirement where the ESB uses a DB adapter to extract information from various data sources (databases), which have the same table structres. Design is to have a single interface, which would connect into the so