Retrieve current executable jar path?

I have several classes put together into an executable jar, which is working fine.
I would like to obtain the path to the location in which the jar is located at runtime in order to check for the existence of a text file in the same directory as the executable jar. For example, if my jar was started from c:\temp\aa.jar I would like to be able to retrieve c:\temp\aa.txt at runtime - how do I tell the program to look for aa.txt in c:\temp as opposed to some other directory?
I have experimented with java.lang.System.getProperty("user.dir"), but this directory is not the same as the one in which the jar is located.
Any ideas? THANKS!

I still would like a way to retrieve the path to the location of the jar file that was executed, if possible.
This may be partly an IDE issue. I'm using Sun ONE Studio 4 update 1, Community Edition. When I execute the jar outside of the IDE (double-clicking it in File Explorer) my program is able to find preferences.txt properly in the same directory as the jar. However, when using the IDE java searches for the text file in the Sun ONE studio's bin directory.
section of program that is looking for the text file:
File filePref = new File("preferences.txt");
System.out.println("preferences.txt path: " + filePref.getAbsolutePath());
standard output when run from within the IDE:
preferences.txt path: C:\Program Files\s1studio_jdk\s1studio\bin\preferences.txt
standard output when run from outside the IDE:
preferences.txt path: directory in which jar is located\preferences.txt
What I would like to do is retrieve the path to the directory in which the jar is located automatically, so that I could write code like the following:
String strPath = path to jar;
File filePref = new File(strPath + "preferences.txt");
I can work around this by pulling the path to the jar from the file object (.getAbsolutePath()) and always testing my jar from outside of the IDE, but this seems like an awkward solution.

Similar Messages

  • Finding a file in the current executable jar file.

    Hi all,
    I am writing a little command line type application and I thought it would be neat to embed it's 'help file' into it's executable JAR file.
    Please can someone show me how to code my application to extract a file from the JAR file from which the Main.class also came?
    (Is that possible?)
    I've been looking around, I can find out how to work with a different JAR file but NOT how to examine the currently 'executing' one.
    Many thanks,
    - jon.

    Excellent! Thank you very much. It's easy when you know how. This works a treat!:
         private static void printHelp() {
              InputStream helpFile = Misql.class.getClassLoader().getResourceAsStream("doc/MISQLhelp.txt");
              if (helpFile == null) {
                   _out.println("Help file: doc/MISQLhelp.txt not found.");
                   return;               
              try {
                   int c;
                   while ((c = helpFile.read()) != -1)
                        _out.write(c);
                   helpFile.close();
              } catch (IOException e) {
                   // TODO Auto-generated catch block
                   e.printStackTrace();
              return;
         }

  • Including jars into executable jar

    Hello
    I want to create an application in one application even if this application depends by many other jar libraries.
    So , my development process resulted into one library: myapp.jar
    This application depends by other jars: lib1.jar, lib2.jar, lib3.jar,
    If I'll create one big jar archive with my classes and these libraries doesn't work (even I'll specify in manifest file all tags:
    Class-Path: lib1.jar lib2.jar lib3.jar
    Main-Class: com.snt.xdoc.MyApp
    So, it is possible to create one single JAR archive including all resources (my interesting point is to include jar libraries) and executable class to know where are these resoures (to establish corectly the classpath)?
    Thank you

    Hello Stefan
    Other topics about this problem can be found here:
    http://forum.java.sun.com/thread.jsp?forum=22&thread=405160&tstart=0
    http://forum.java.sun.com/thread.jsp?forum=4&thread=432114&tstart=0
    But you might want to take a look at META JAR UTILITIES : http://www.yagga.net/java/metajar/
    "Three classes with full source code and documentation that allows to extract resources from a file, from inside a JAR file that is currently executing (java -jar foo.jar), from a JAR that is included in the aforementioned executing JAR and to define a classLoader that can work with JARs, even if those JARs are JARred inside the currently executing JAR."
    MetaJarUtilities are being distributed with full source code under GNU's General Public License.
    For the moment being a JAR structured like this works:
    FOO.jar
    +- SuperMetaJarTest.class (uses BootstrapJarClassLoader.class)
    +- net/
    | +- yagga/
    | +- util/
    | +- BootstrapJarClassLoader.class
    |
    +- metatest.jar (content below)
    | +- net/
    | | +- yagga/
    | | +- util/
    | | +- Meta Jar Utilities classes here...
    | +- jars/
    | | +- test.jar
    | +- TestmetaJar.class
    | +- text.txt
    |
    +- jars2/
    +- test2.jar
    Good luck!

  • File path of a currently executing teststand test step

    How do i extract the file path for the currently executing LabVIEW test step within my operator interface.
    Many Thanks,
    Dave.

    Hi,
    I assume you need the SequenceFile Path where the LabView test step is located in TestStand.
    To reach to the currently executing step SequenceFile path you have to:
    1. get the SequenceContext for the execution
    2. get the currently executing step from the SequenceContext (SequenceContext.Step)
    3. get the sequence in which the step resides from the Step (Step.Sequence)
    4. get the containing sequence file for the Sequence (Sequence.SequenceFile)
    5. get the Path from the SequenceFile (SequenceFile.Path property)
    In case you want to determine the VI file path for the LabView test step Module one approach is:
    1. get the SequenceContext for the execution
    2. get the currently executing step from the SequenceContext (SequenceContext.Step)
    3. get the PropertyObject for the step (Step.AsPropertyObject)
    4. get the VI relative path from the step subproperty using "TS.SData.ViCall.VIPath" lookup string (PropObject.GetValString)
    5. now use the Engine.FindFile on the retrieved path at the step 4. above, to get the path to the executing VI
    Hope this helps,
    Silvius
    Silvius Iancu

  • Query JVM for executing JAR absolute path

    Good morning
    In order to use resources in an executed JAR file, I use the following :
    URL url = JARFILENAME.class.getResource(myResourceRelativePath);But, JARFILENAME is the name of the JAR file which is being executed and I would not like it to be hard coded. Is there anyway to query the JVM the absolute path of the executed JAR file ?
    Thanks a lot
    Christophe

    Good Afternoon everybody,
    Thank you very much Owen ! Your words were very helpful to me.
    In order to help other people who would like to process text files embedded in an executable JAR file, here all my sources for this example.
    HOW TO PROCESS TEXT FILES EMBEDDED IN AN EXECUTABLE JAR FILE WITH PACKAGED CLASS FILES
    File list for the project (after executing the makefile) :
    .\build
    .\docs
    .\src
    .\makefile.bat
    .\JarTextResourcesReaderDemo.jar
    .\sources.txt
    .\JarTextResourcesReaderDemo(Sources).zip
    .\build\cbismuth
    .\build\txt
    .\build\manifest.mf
    .\build\cbismuth\demos
    .\build\cbismuth\utils
    .\build\cbismuth\demos\JarTextResourcesReaderDemo.class
    .\build\cbismuth\utils\jar
    .\build\cbismuth\utils\jar\textreader
    .\build\cbismuth\utils\jar\textreader\JarTextResourcesReader.class
    .\build\txt\myTextFile.csv
    .\docs\cbismuth
    .\docs\package-list
    .\docs\resources
    .\docs\stylesheet.css
    .\docs\allclasses-frame.html
    .\docs\allclasses-noframe.html
    .\docs\constant-values.html
    .\docs\deprecated-list.html
    .\docs\help-doc.html
    .\docs\index.html
    .\docs\index-all.html
    .\docs\JarTextResourcesReader.html
    .\docs\JarTextResourcesReaderDemo.html
    .\docs\overview-frame.html
    .\docs\overview-summary.html
    .\docs\overview-tree.html
    .\docs\package-frame.html
    .\docs\package-summary.html
    .\docs\package-tree.html
    .\docs\cbismuth\demos
    .\docs\cbismuth\utils
    .\docs\cbismuth\demos\JarTextResourcesReaderDemo.html
    .\docs\cbismuth\demos\package-frame.html
    .\docs\cbismuth\demos\package-summary.html
    .\docs\cbismuth\demos\package-tree.html
    .\docs\cbismuth\utils\jar
    .\docs\cbismuth\utils\jar\textreader
    .\docs\cbismuth\utils\jar\textreader\JarTextResourcesReader.html
    .\docs\cbismuth\utils\jar\textreader\package-frame.html
    .\docs\cbismuth\utils\jar\textreader\package-summary.html
    .\docs\cbismuth\utils\jar\textreader\package-tree.html
    .\docs\resources\inherit.gif
    .\src\cbismuth
    .\src\cbismuth\demos
    .\src\cbismuth\utils
    .\src\cbismuth\demos\JarTextResourcesReaderDemo.java
    .\src\cbismuth\utils\jar
    .\src\cbismuth\utils\jar\textreader
    .\src\cbismuth\utils\jar\textreader\JarTextResourcesReader.java[b]File .\sources.txt :
    .\src\cbismuth\utils\jar\textreader\JarTextResourcesReader.java
    .\src\cbismuth\demos\JarTextResourcesReaderDemo.java[b]File .\makefile.bat :
    @title Java Project Compilation
    @echo off
    echo ------------------
    echo Old Files Deletion
    echo ------------------
    del /f /q *.zip
    del /f /q *.jar
    del /f /q build\cbismuth
    echo -----------
    echo Compilation
    echo -----------
    javac -O -deprecation -d build @sources.txt
    echo -------------------
    echo Java Doc Generation
    echo -------------------
    javadoc -author -version -private -windowtitle JarTextResourcesReaderDemo -d docs @sources.txt
    echo -------------------------
    echo Executable JAR Generation
    echo -------------------------
    cd build
    jar -cvfm JarTextResourcesReaderDemo.jar .\manifest.mf *
    move JarTextResourcesReaderDemo.jar ..
    cd ..
    echo ----------------------
    echo ZIP Project Generation
    echo ----------------------
    jar -cvf JarTextResourcesReaderDemo(Sources).zip *[b]File .\src\cbismuth\utils\jar\textreader\JarTextResourcesReader.java :
    package cbismuth.utils.jar.textreader;
    import java.io.IOException;
    import java.io.InputStream;
    import java.io.BufferedReader;
    import java.io.InputStreamReader;
    import java.lang.NullPointerException;
    import java.lang.IndexOutOfBoundsException;
    public class JarTextResourcesReader {
      protected BufferedReader[] readers = null;
      public JarTextResourcesReader(String[] paths) throws NullPointerException {
        int nbFiles = paths.length;
        readers = new BufferedReader[nbFiles];
        for (int i = 0; i < nbFiles; i++) {
          InputStream inputStream = this.getClass().getResourceAsStream(paths);
    this.readers[i] = new BufferedReader(new InputStreamReader(inputStream));
    if (readers[i] == null) {
    throw(new NullPointerException());
    public void print() {
    for (int i = 0; i < readers.length; i++) {
    String line = null;
    try {
    while((line = readers[i].readLine()) != null) {
    System.out.println(line);
    catch(IOException e) {
    // exception managment
    public BufferedReader getReaderAt(int i) throws IndexOutOfBoundsException {
    if (i > this.readers.length) {
    throw(new IndexOutOfBoundsException());
    else {
    return(this.readers[i]);
    public BufferedReader[] getReaders() {
    return(this.readers);
    public void close() {
    for (int i = 0; i < this.readers.length; i++) {
    try {
    readers[i].close();
    catch(IOException e) {
    // exception managment
    File .\src\cbismuth\demos\JarTextResourcesReaderDemo.java :
    package cbismuth.demos;
    import cbismuth.utils.jar.textreader.JarTextResourcesReader;
    public class JarTextResourcesReaderDemo {
      public static void main(String[] args) {
        String[] paths = new String[1];
        paths[0] = "/txt/myTextFile.csv";
        JarTextResourcesReader jtrr = new JarTextResourcesReader(paths);
        jtrr.print();
        jtrr.close();
    }[b]File .\build\txt\myTextFile.csv :
    Line 1 Column 1;Line 1 Column 2;Line 1 Column 3
    Line 2 Column 1;Line 2 Column 2;Line 2 Column 3[b]File .\build\manifest.mf :
    Main-Class: cbismuth.demos.JarTextResourcesReaderDemo
    [BLANK LINE !]NOTE : a blank line MUST be left at the end of the MANIFEST file !
    [b]Command line to execute the JAR file in the root directory :
    java -jar JarTextResourcesReaderDemo.jar[b]Output :
    Line 1 Column 1;Line 1 Column 2;Line 1 Column 3
    Line 2 Column 1;Line 2 Column 2;Line 2 Column 3[b]Special thanks to Owen !
    See you soon,
    Christophe

  • Execute executable jars without jar.exe in system path???

    Hello all,
    I could run an executable jar file on my workstation once I configured its MANIFEST.MF file with its Main and class-path attributes. But, the execution failed when I tried to copy this executable jar file alongwith other required jar files to a workstation not having jar.exe in the path! However, the same programme executes successfully when I run it using a batch file where I set jar.exe in the path. is it possible to configure MANIFEST.MF file with system path?
    thanks in advance.

    Actually you don't need Jar.exe to run jars.yes, you are right! actually, I need another dll file in the system path to execute the application. how can I add this dll file to the path when running the application using executable jar.
    BTW, thanks for the reply!!
    note: the dll file required in the path is bundled alongwith other jar files.

  • Retrieving Jar path in the HD from within the jar?

    I have a small problem. I wrote a program which is packed in a jar file and this program is able to compile and run java files (Which I do by running javac and java processes) but the kind of files that this program compiles requires some other libraries inside the same package (In the jar file) so I am wondering how can I retrieve the jar path in the harddisk from within this jar because at the moment I ask the user where the program is and I think it is kind of ugly to ask the user where the program is from within the exact same program we are looking for.
    Hope I made myself understandable.
    Best Regards
    NooK

    Thanks for the answer. I mistakenlly ended writing a new thread (New to the forum)
    but if you would kindly look here, I have other problem now which I have been working on for a whole day.
    http://forum.java.sun.com/thread.jsp?thread=524717&forum=31&message=2514471
    Best Regards
    NooK

  • Links not working in executable jar

    I have a problem with my java application
    html and images files do not work in executable jar
    though the application works normally
    I tried some suggestion but I received an exception thread indicating problem at
    ImageIcon iChing = new ImageIcon(imageURL);
    Please could you help me thank you so much
    here is the class
    public class Main extends JFrame
    * objects required for the GUI: JFrame,JLabel, JButton, ImageIcon, JPanel,
    * Dimension
    private static final long serialVersionUID = 1L;
    JButton jbEnter;
    ImageIcon iChing, logo;
    JPanel buttonPanel, ImagePanel;
    JLabel jlbIching;
    Dimension dim;
    URL imageURL;
    File fileName;
    // Class constructor to create the GUI
    public Main()
    Container container = getContentPane();
    URL imageURL = this.getClass().getClassLoader().getResource("src/myFiles/iching.gif");
    ImageIcon iChing = new ImageIcon(imageURL);
    jlbIching = new JLabel(iChing);
    // button to go to the Title class
    jbEnter = new JButton("Enter ");
    jbEnter.setBorderPainted(false);
    jbEnter.setFont(new Font("Edwardian Script ITC", Font.BOLD, 42));
    jbEnter.setBackground(new Color(0, 0, 50));
    jbEnter.setForeground(Color.YELLOW);
    jbEnter.addActionListener(new ActionListener() {
    // method to render the current frame invisible and trigger the
    // Welcome Menu
    public void actionPerformed(ActionEvent e)
    setVisible(false);
    // this line does not work...............
    new Title();
    } // close the actionPerformed(ActionEvent e) Method
    }); // close the addActionListener(new ActionListener() method
    // Panel holding the decorative image and Button
    ImagePanel = new JPanel();
    ImagePanel.add(jlbIching);
    ImagePanel.setBackground(new Color(0, 0, 50));
    buttonPanel = new JPanel();
    buttonPanel.add(jbEnter);
    buttonPanel.setBackground(new Color(0, 0, 50));
    // setting up of the panels position
    container.add(ImagePanel, BorderLayout.CENTER);
    container.add(buttonPanel, BorderLayout.SOUTH);
    dim = Toolkit.getDefaultToolkit().getScreenSize();
    dim.width = dim.width / 2 - 300;
    dim.height = dim.height / 2 - 250;
    setBounds(dim.width, dim.height, 400, 400);
    setSize(600, 500);
    setResizable(false);
    setVisible(true);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    //To set the icon for the application. Top left hand corner.
    //this.setIconImage(Image);
    setIconImage(new ImageIcon("src/myFiles/ichingRose.gif").getImage());
    } // close the Constructor
    * the main method for the program.
    * @param args
    * The command-line arguments.
    public static void main(String[] args)
    new Main();
    } // close the main method
    } // close the Main class

    Thank you very much for your quick reply and really hope you can help me a little more
    it's so frustrating
    I do not really know about the relative path but here is my xml file
    <?xml version="1.0" encoding="UTF-8" ?>
    <project default="jar">
    <!-- Compile and zip the source code into a jar -->
    <target name="jar">
    <!-- Make the folders we'll need -->
    <mkdir dir="ant"/>
    <mkdir dir="work"/>
         <mkdir dir="ant/myFiles"/
    <!--
    Compile all the .java files into .class files
    debug = yes Include debug information in the .class files
    destdir Where to put the .class files
    source and target Use Java version 1.6.0_06
    -->
    <javac
    debug="yes"
    destdir="ant"
    source="1.6"
    target="1.6">
    <!-- Folders that have trees of .java files to compile -->
    <src path="src"/>
    </javac>
         <copy todir="ant/myFiles"><fileset dir="src/myFiles"></fileset></copy>
    <!--
    Zip files together to make a jar
    jarfile Where to make the .jar file, overwrite something there
    basedir Find the files to zip in the jar here
    -->
    <jar
                   jarfile="work/BookOfChanges.jar"
    basedir="ant"
    >
    <!-- Write a manifest inside the jar -->
    <manifest>
    <!-- The class Java will run when the user double-clicks the jar -->
    <attribute name="Main-Class" value="iChing.Main"/>
    </manifest>
    </jar>
    </target>
    </project>

  • Executable JAR sometimes could not find the main class.

    I have a little task, that seems to be trivial- but I have no idea how to solve the current problem.
    With a double click on my jar, a message comes up: JVM could not find the main class. Program will exit.
    The executable JAR is an export result from eclipse, with a manifest file that contains the right entry to the main class.
    But the curious thing is, that I have tested the little Swing-Application with 3 JRE versions: 1.4.2._06, 1.4.2_09 and 1.5 on Win2K and XP. Every time it works fine, but on one system it fails. (Normally it requires no external classpath settings, no path-entries to work.)
    The ugly system is Win XP with JRE 1.4.2_06 installed.
    Is there anybody with a good hint?
    Please let me know.
    Christiane

    OK, I ll try to explain it in other words:
    It is an executable jar file, with a manifest file that specifies the Main-Class. No other external files or jars or settings needed. Only a simple JDialog initialized from a parent JFrame.
    I d like to start it with a double click from the Win-Explorer, not from command line!
    As a result a dialog from "Java Virtual machine Launcher" displays
    "Could not find the main class. Programm will exit."
    My Problem is, I don t understand the launching process in depth. But I can reproduce the message with the following command:
    wrong:
    javaw -cp OrderAlertTest.jar OrderAlertParentDialog
    -> Error dialog appears
    correct:
    javaw -cp OrderAlertTest.jar apo.order.OrderAlertParentDialog
    -> OK
    Any idea?
    Christiane

  • Executable jar referring to external library

    dear reader,
    I developed a swing tool which uses xml generated by xerces for socket communication contents. I'd like to the classes that I made to an executable jar.
    Just making executable jar file is simple. I followed the guide on the web.( thanks you all guys for that).
    However, once the jar file need to refer to xerces to generate xml file, it fails to refer to the library which is located as './lib/xerces**.jar'.
    './' means the location that my jar file is located.
    the purpose of this system is a run in any OS.
    Actually I found a way of using Ant. and using manifest file.
    In the latter case, the string "Main-Class = " stop me to set referred path.
    and the former Ant case, I am not sure if the values are validated or i am using the exact tag.
    I tried "Main-Class = test.MainClass", "Main-Class = test/MainClass.class", etc. and even with <manifest .../>, it doesn't work.
    is it possible to refer to external jar file as lib?
    give some clue.
    best regards,
    from moon in the sky...

    Sorry, let me explain a little bit better. I am new to java and eclipse and terminology has never really been my thing but lets try this again:
    I am trying to turn my project into a JAR file. My project needs an external jar (AvayaPushSDKLib) in order to run. I have my code running fine in Eclipse, but the moment I export it, it gives me the "Exception in thread 'Main' java.lang.NoClassDefFoundError: com/avaya/phones/push" followed by several other errors, one of which says "Cause by: java.lang.ClassNotFoundException: com.avaya.phones.push".
    In Eclipse these run fine. Here is the files that are currently in each directory:
    ./Server1.0/
              /server/
              start.jar (I created the jar file here)
    ./Server1.0/server/
              /start/
              MANIFEST.mf
    ./Server1.0/server/start/
              AvayaPushSDKLib.jar
              PushClass.class
              ServerStart.class
              UserInterface.class
              PushClass.java (all .java files will eventually be removed)
              ServerStart.java
              UserInterface.javaI hope this makes more sense. Thanks

  • Netbeans 5.0 Executable Jar Problem--One Solution

    Hi all.
    This issue seems to constantly come up with all the Netbeans IDEs. I managed to solve the problem I was having so I felt obligated to post my solution since it can be mind-numbingly frustrating to deal with.
    This may not work for you, but it worked for me in my situation so you may want to give it a shot.
    This is what I did to solve the problem:
    a) make sure a file called manifest.mf is in the root of your project folder. The manifest file should contain the following text (do not include the lines with ----------- on them of course):
    Manifest-Version: 1.0
    X-COMMENT: Main-Class will be added automatically by build
    To be safe:
    Note the trailing carriage return after the X-COMMENT line--LEAVE THIS IN.
    Note the case of the file name manifest.mf--MAKE SURE YOU DO NOT ADD CAPITAL LETTERS.
    b) In the nbprojects folder of your main project folder, open the file project.properties and add the line:
    manifest.file=manifest.mf
    Clean and build your project. If you check the manifest in the main jar file, you'll see (hopefully) it has the Main-Class attribute set, as well as the class path to any other jar files you've put in your project classpath.
    BTW1:
    Make sure you don't have any files open in the directories that will need to be deleted by the 'clean' step or you'll get an error.
    BTW2:
    Also, make sure you've set your main class in your project by right-clicking the project node, click Properties, select Run from the tree on the left side, and fill in the 'Main-Class' text field.
    This worked for me. I hope it helps others with the overly-confusing executable jar issues the Netbeans series of IDEs always seem to have. I think the complexity lies in its use of Ant in the build process. While Ant adds a ton of flexibility--it also a ton of complexity.
    For example, this jar issue has been very annoying, but I wouldn't have been able to add a hook into my build process that signs my jar files (for use with Java Web Start) without the Ant system.
    Netbeans 5.0 is still currently my favourite Java IDE though.
    Cheers!
    Michael N. Christoff

    Genius! thank.

  • Adding a jar to the classpath of an executable jar (mixing -jar and -cp)

    Hello,
    frankly I hesitated over posting this to "New to Java"; my apologies (but also, eternal gratefulness) if there is an ultra-simple answer I have overlooked...
    I integrate a black-box app (I'm not supposed to have the source) that comes packaged as an executable jar (with a Manifest.MF that specifies the main class and a bunch of dependent jars), along with a few dependent jars and a startup script. Long story short, the application code supports adding jars in the classpath, but I can't find a painless way to add a jar in its "classpath".
    The app's "vendor" (another department of my customer company) has a slow turnaround on support requests, so while waiting for their suggestion as to how exactly to integrate custom jars, I'm trying to find a solution at the pure Java level.
    The startup script features a "just run the jar" launch line:
    java -jar startup.jarI tried tweaking this line to add a custom jar in the classpath
    java -cp mycustomclasses.jar -jar startup.jarBut that didn't seem to work ( NoClassDefFound at the point where the extension class is supposed to be loaded).
    I tried various combination of order, -cp/-classpath, using the CLASSPATH environment variable,... and eventually gave up and devised a manual launch line, which obviously worked:
    java -cp startup.jar;dependency1.jar;dependency2.jar;mycustomclasses.jar fully.qualified.name.of.StartupClassI resent this approach though, which not only makes me have to know the main class of the app, but also forces me to specify all the dependencies explicitly (the whole content of the Manifest's class-path entry).
    I'm surprised there isn't another approach: really, can't I mix -jar and -cp options?
    - [url http://download.oracle.com/javase/6/docs/technotes/tools/windows/classpath.html]This document (apparently a bible on the CLASSPATH), pointed out by a repited forum member recently, does not document the -jar option.
    - the [url http://download.oracle.com/javase/tutorial/deployment/jar/run.html]Java tutorial describes how to use the -jar option, but does not mention how it could play along with -cp
    Thanks in advance, and best regards,
    J.
    Edited by: jduprez on Dec 7, 2010 11:35 PM
    Ahem, the "Java application launcher" page bundled with the JDK doc (http://download.oracle.com/javase/6/docs/technotes/tools/windows/java.html) specifies that +When you use [the -jar] option, the JAR file is the source of all user classes, and other user class path settings are ignored+
    So this behavior is deliberate indeed... my chances diminish to find a way around other than specifying the full classpath and main class...

    I would have thought that the main-class attribute of the JAR you name in the -jar option is the one that is executed.Then I still have the burden of copying that from the initial startup.jar's manifest. Slightly less annoying than copying the whole Class-path entry, but it's an impediment to integrating it as a "black-box".
    The 'cascading' behavior is implicit in the specification
    I know at least one regular in addition to me that would issue some irony about putting those terms together :o)
    Anyway, thank you for confirming the original issue, and merci beaucoup for your handy "wrapper" trick.
    I'll revisit the post markers once I've actually tried it.
    Best regards,
    Jérôme

  • How to get the current executing file/itself absolute directory?

    hellooo,
              gentlemen/lady, how to get the current executing file/itself absolute directory?
              thanks
              

              Hello,
              you can get the real path information of the JSP through the servlet context:
              http://java.sun.com/products/servlet/2.2/javadoc/index.html
              javax.servlet
              Interface ServletContext
              Method getRealPath
              Christian Plenagl
              Developer Relations Engineer
              BEA Support
              [email protected] (alex mok) wrote:
              >hellooo,
              >
              >gentlemen/lady, how to get the current executing file/itself absolute
              >directory?
              >
              >thanks
              

  • Get name of executing jar-file (who-am-i)

    Hi,
    I'm planning to use a jar-file for a JAVA-application that holds all classes and an additional file with initial values (init.txt). This should allow an easy way to change initial behavior without having to recompile the code (I mean I could put all the initial values directly into the code). So I simply change init.txt and deploy the jar-file.
    To achieve this I need a way to find out the name of the jar-file that is currently executing. With that I can open the jar-file from within the code and do the rest (I'm not going to bother you with this ;) ).
    In C it was pretty simple, an argv[0] would do it. But how does it work in JAVA? I only have access to the parameters passed to the program.
    EXAMPLE:
    ========
    The command line looks like this:
    java -jar MyApp.jar
    MyApp.jar contains this (among others):
    |- MyApp.class
    |- init.txt
    In this example I need to get the information that I'm "MyApp.jar". I already have the rest of the code so I'm only missing this little thingy.
    Thanks beforehands for help.

    No, you should NOT need the name of your JAR file. You are probably coding it up the wrong way. If what you're after is to be able to read that "init.txt" file, then do so via something like:
    InputStream initStream = getClass().getResourceAsStream("/init.txt");
    rather than using filename-based API's.

  • Add classpath in an executable jar file

    an executable jar file contains a manifest file with entry main-class: MyApplicationClass.
    if we double click the jar file on Windows OS, main class is loaded.
    my question is:
    if classes in he jar file use classpaths which are not default, how to add those classpaths into manifest file to tell classes to use those classpaths?
    it is similar to command line:
    java -classpath c;\mypackage; .......; MyApplicationClass

    Thanks, i will try soon.
    here is another Q.
    if i need to add tools.jar (JDK lib) as classpath in manifest file, it is as following in my PC
    d:\install\java\jdk14101\lib\tools.jar.
    but my customers install JDK in different path (should be considered as unknown), how to add it as entry Class-path for all customers?

Maybe you are looking for

  • WebLogic 10.3.2.0 hanging at startup after "The server log file is opened."

    Hi, A WebLogic 10.3.2.0 server is hanging at startup. There are no error messages. The last command in the startup window is: "The server log file <log file dest> is opened. All server side log events will be written to this file." I think the next l

  • Hierarchy with time-dependent structure

    Hello, collegues, Im attempting to build a report on payrolll data using DS 0HR_PY_1_CE. There is a time-dependent structure hierarchy which changes very often (new departments are created\dispatched) on 0ORGUNIT. The data granularity in infoprovider

  • Dad ready to throw the ipad!! closing out of photos

    Hi, I bought my dad an ipad. I don't have one (have a macbook pro). He called me extremely frustrated because he was checking his email and he clicked on a link someone sent him of a slide show of photos and cannot get out of it. I've tried everythin

  • [SOLVED] conky + amarok 2 + xfce

    Hello! Is there is a way to make conky work with Amarok 2 in Xfce. Scripts for Amarok are using DCOP, but as far as I know, DCOP is working with kde3. So I am looking for a way to enable DCOP in Xfce, either to make Amarok working with Conky in some

  • Ossstatus error 2

    I have an IOmega IX2-200 and a MacBook Pro. All equipped with the latest software. And I can't get the timemachine connected. If I log in as guest I get above error. Can anybody help me?