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!
Michele
If 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
Similar Messages
-
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 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 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 source code of Java Concurrent Program?
Hi,
How to get the source code of Java Concurrent Program?
Example
Programe Name:Format Payment Instructions
Executable:Format Payment Instructions
Execution File Name:FDExtractAndFormatting
Execution File Path:oracle.apps.iby.scheduler
Thanks in advance,
SenthilGo on Unix box at $JAVA_TOP/oracle/apps/iby/scheduler
You will get class file FDExtractAndFormatting.
Decompile it to get source code.
Thanks, Avaneesh -
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 ?
-
Sun ONE Studio 4 aka Forte: How to set the output path for classes ?
Help !
Beginner's question:
Sun ONE Studio 4 aka Forte:
How to set the output path for classes ?
As default, the class files are created in the same directory as the
sources.
In opposite, both JBuilder and Together support that there is a tree
with the sources and another tree with the classes.
The first answer I got was "not possible with Forte, but just if you write your own "ANT Build script" !
a) Please point me to a ready-to-use ANT script for this purpose, if such is available
b) Is using ANT instead of the MAKE as comfortable ? Besides the separation of sourcecode and classes, I would like to keep everything else to be the same, i.e. I don�t want to edit the ANT file if I enlarge the project by directories or files.
Tia
Sincerely
RolfYou can set S1S's options to place newly created .class files in a specific location.
Identify the compiler that is being used - Open the S1S's Tools/Options window, expand Editing and select Java Sources. Note the Default Compiler value. (If it's one if the Ant options, you use Ant to specify this option, not S1S.)
Open the S1S's Tools/Options window, expand Building/Compiler Types and select the appropriate compiler.
The Properties tab of the compiler has the property Target, which sets the filesystem where the compiler output is directed. If you choose <not set>, the .class files are written to their source directory.
When you set the Target, your change affects all classes that use this compiler.
Very few options can't be set in S1S; the challenge is finding out where they're set! -
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 context data using java script in interactive forms
Hi All,
How to get the context data using java script in interactive forms by adobe, am using web dynpro java
thanks.Hi venkat,
Please Refer this link.
Populating one Drop-Down list from the selection of another Drop-down list
Thanks,
Raju. -
How to get the output of the report in pdf format
how to get the output of the report in pdf format?
Thanks in advance,
madan.Refer these links
http://www.sap-img.com/bc037.htm
http://www.members.tripod.com/abap4/Save_Report_Output_to_a_PDF_File.html
CONVERT_ABAPSPOOLJOB_2_PDF FM convert abap spool output to PDF -
How to get the output of Standard HR forms in PE51
Hi Experts,
How to get the output of standard HR forms available in PE51 Transaction for coutry grouping 99.
Please advice.
Regards,
IFFHi
Use the t code for country grouping 99....PC00_M99_CEDT - Remuneration Statement. to get the variant in tcode PC00_M99_CALC_SIMU - Simulation.
Like this test for all the standard forms, what all are the available in PE51 for country grouping 99 -
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.
Maybe you are looking for
-
HT3702 Itune charges and Mac charges
I've been charged on 1/3/14 over $90 for playing Candy Crush and i didn not play on that day. I have also been receiving daily charges to my debit account, when i have not played. Can you please tell me who i can speak to in order to discuss this?
-
What's a good software to use for Vendor Management?
We would like to do risk assessments, keep contracts & upload other pertaining documents to these vendors. Looking for a software that can be installed locally in our network. If anyone has any suggestions, please let me know, thank you! We have bee
-
The videos aren't buffering, though. The videos can be fully buffered or not, it doesn't matter. I've checked IE9 & Google Chrome, and bother browsers view the same videos perfectly. I've disabled my add ons, but nothing works. I love FireFox....I lo
-
HotSpot Virtual Machine Error, Internal Error, Error ID: 41443F53504152430E
We're getting an internal error from JavaVM running JBoss 3.2.3 on Sun Solaris. The error ID is always the same. But I did not find any information about that error. Does this Error ID has any relevance? How can I find out more about my error? Thanks
-
Are there any virus protection software out there for iPhone 5?
Just wanting to see there was a virus scanner for the iPhone 4/4s or 5. My phone has been freezing the couple of days. I just want to rule out all possibilities. Thanks.