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;
     }

Similar Messages

  • 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
              

  • Can you get the file name of the current executing TSQL script?

    Can you get the file name of the current executing TSQL script? I wrote entries to a generic log file and would like to include the script name.

    Okay, So What you can do is
    1. Read get the version from your  database and redirect it to a text file(SQLCMD outout can be directed to text file using -o option or windows redirection operator >)
    2. Now you can read this value from the text file either inside a batch file or a powershell script and decide what operations you can do. 
    Satheesh
    My Blog |
    How to ask questions in technical forum

  • Trap the currently executing line number?

    Hi,
    how can one get the number of the currently executing line of code?
    Like what is generated when there are compilation/runtime errors.
    I saw LineNumberReader() & getLineNumber() but they seem to be for reading files or a jpanel (I think).
    thanks,
    HSC

    ok, with all your help I managed to get this:
                //----------------- stack trace for debugging ------------------           
                StackTraceElement[] e = new Throwable().getStackTrace();
                StackTraceElement stack[] = e;
                // stack[0] contains the method that created the exception.
                // stack[stack.length-1] contains the oldest method call.
                // Enumerate each stack element.
                //for (int i=0; i<stack.length; i++)
                int i=0;
                String filename = stack.getFileName();
    if (filename == null) {
    // The source filename is not available
    String className = stack[i].getClassName();
    String methodName = stack[i].getMethodName();
    boolean isNativeMethod = stack[i].isNativeMethod();
    int line = stack[i].getLineNumber();
    System.out.println(
    " >>className =" + className +
    " >> methodName =" + methodName +
    " >> line = " +line
    // } //end-for
    //----------------- stop stack trace for debugging ------------------
    Still don't quite understand it all but considering I've been learning java on my own for about 3 weeks I figure I'm doing better than a lot of newbies. - I am frustrated as hell, but I don't give up!
    thanks.
    Note: anyone looking for code examples you can look at: "The Java Developers Almanac 1.4" http://javaalmanac.com/

  • Method reference of the currently executed method

    Hello,
    is there a way (i think using reflection) to have a reference to a Method object of the currently executed method?
    class A {
         void foo() {
              java.lang.reflect.Method m = ???     // would be a reference to the foo() method
         void foo(int i) {
              java.lang.reflect.Method m = ???     // would be a reference to the foo(int i) method
    }Thanks in advance for any answer

    There is no such feature. I can't think of a single reason why you'd want it either.

  • Find the full sql text of the currently executing query

    Hi,
    I wish to find the full sql text of currently executing sql.
    Tried through v$sql and v sqltext_with_newlines but it doesn't give the full sql.
    We do not want to enable trace to get sql query.
    How to get this ?
    Thanks.

    Hye,
    I got my answer on the below link,
    Getting data from sql_fulltext
    Thanks.

  • 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.

  • How do I find out what is the current data rate on my wifi card?

    I have a macbook pro running OSX 10.8.2. When I go to system profiler I see that the card is in 802.11n mode, but how do I find out the current rate? There is a 'Transmit Rate' parameter but there is no unit next to it.

    The data rate depends on if it is using the 2.4 GHz band or the 5 GHz band, both are possible with n-protocol unless you have limited your wireless to only one band.  The data rate in 5 GHz is double that in 2.4 GHz.  Also, you have to know what the protocol of the network is, the AirPort card can only transmit at the rate of the network, so if you are on a g-protocol router, that is the fastest rate you can see.
    And then interference, attenuation, etc. will drop that rate.

  • How to find last  date of the current year

    Hi
    Please tell me is there any function module to find out the last date of the current year.

    Hi,
    You can do that very simply like so.
    code
    report zrich_0001.
    data: first type sy-datum.
    data: last type sy-datum.
    first = sy-datum.
    first+4(4) = '0101'.
    last = sy-datum.
    last+4(4) = '1231'.
    write:/ first, last.
    [/code]
    OR use function modules
    1.use this function module HR_GB_TAX_YEAR_DATES
    Pass these values
    P08_TXYEAR = Year
    P08_PAYROLL_AREA = '01'
    2.use FM......... FIRST_AND_LAST_DAY_IN_YEAR_GET
    DATA: first LIKE sy-datum,
    last LIKE sy-datum.
    CALL FUNCTION 'FIRST_AND_LAST_DAY_IN_YEAR_GET'
    EXPORTING
    i_gjahr = '2007'
    i_periv = '24'
    IMPORTING
    e_first_day = first
    e_last_day = last.
    WRITE: / 'First Date', first, ' Last Date', last.
    Regards,
    Raj.

  • Datetime of the current executing job

    Hi,
    Just want to know if there's way to know the date and time of the current running job get executed?
    Thanks in advance.

    Hi Ronald,
    Thanks, for the response. Please excuse my ignorance, is DEFINE_METADATA_ARGUMENT used only if you have a program defined? If its not too much to ask, could you please provide some short example on how to use this.
    Right now, we are not defining any program object, what we are doing are:
    1. Create schedules for individual dates
    2. Create a main schedule which has the consolidated schedules that was created on #1.
    3. Create Job.
    4. Create Job Argument.
    5. Enable the Job.
    What we need now is when the job ran we want to know its start date (job_start). We tried to look if some views are providing this information. Like ALL_SCHEDULER_JOB_RUN_DETAILS, but this view only updated after the job is done executing. We also looked into ALL_SCHEDULER_RUNNING_JOBS but this does not provide the job start date.

  • How to know if the current application jar file has been overwritten?

    When I overwrite a jar file that is being used, the buttons that call new windows stop responding silently but is there some check I can make from within the application to know if the jar file has been overwritten, so that I can warn the user to restart it?
    I know this sounds bad so let me explain why I would want this, if you don't care then skip everything below this point.
    I have close to a hundred of users executing Java applications from a central repository in the network. This is important because the applications are always changing and evolving so it's important that I only have to update one binary. I do most updates after work hours so I don't have a problem there but sometimes there are critical errors that need to be corrected immediately. Depending on the amount of people using an application it may be impractical to warn and wait for everyone to close it and make everyone else wait for that so I just overwrite the files that need to be updated and then warn everyone to restart the application. The result is that buttons that call for frames that haven't been called yet stop working silently. Some users already know what to do when that happens but I want a more graceful approach. I wanted to check for this situation from inside the application so that I could inform the user of the update and provide information on what to do next. Can I do this? I tried some try and catch blocks of code but I can't seem to catch anything when that happens.

    You can write your own class loader that loads classes from that jar file. Make sure it isn't on the class path and when you want to create an object from that jar file, call up your class loader to do that. (You only have to do that for your "top-level" objects, within those objects creating another object will automatically be done by your class loader.)
    Periodically check whether the jar has been modified. If it has, refresh the application by creating a new instance of your class loader and using that to create new instances of all your objects.
    But that sounds like a lot of work just to avoid setting up an emergency change procedure where you get everybody to close their applications.

  • Getting the absolute path of the current executing file

    I have a file which will be placed in window and linux environment. It is not good to change the source code in that way:
    String path = "D:\\java\file1.txt"; (Window)
    String path = "/java/file1.txt"; (Linux)
    So I would like to ask how to get the absolute path based on that executing file?
    I referred to the reference in jsp, but I don't know what class and the coding syntax in console environment.
    Thx for any help.

    If you are looking to "get" a file that is located in a directory with (or somewhere under) the class file than use
    myClass.getClass().getResource(<relativePathWithFileFromClass>);  //URL
    myClass.getClass().getResourceAsStream(<relativePathWithFileFromClass>);  //InputStreamAs far as determining which Operating System you are on, there are a number of environment variables that will tell you that, and you can then format your file path accordingly.
    You can use "/" in your path regardless of which OS you are using. You do not have to use "\\" on Windows (excpet maybe inside of a Runtime.exec command string).
    Here is a very small program you can compile and run if you wish to see the list of System Properties available:
    public class ShowProperties {
      public static void main(String[] args) {
        System.getProperties().list(System.out);
    }Just save that to a file (named ShowProperties.java of course) and compile and run it, and you will get a list of your available System Properties and their current values

  • Finding the currently executed SQL statement

    Hi,
    We have some users who have submitted some SQL statements which have been running for a very long time.
    Please let me know how to find out the SQL which is being currently being executed and also is it possible to find an estimated time of completion for the statement.
    Regards,
    VN

    You've posted enough to know you need to provide your 4 digit Oracle version.
    >
    We have some users who have submitted some SQL statements which have been running for a very long time.
    Please let me know how to find out the SQL which is being currently being executed and also is it possible to find an estimated time of completion for the statement.
    >
    You can query V$SESSION_LONGOPS. See my reply in this recent thread
    Re: SQL query to see what the db/schema is doing

  • Sort files in Finder column view for the current folder only?

    Hi,
    I don't really understand how finder sort settings work, even after using OS X since it first came out. Maybe someone can give me a hand.
    I'm trying to sort files inside one specific folder according to their name decending. In general I have arranged them by label and sorted by file name ascending. Every time I try to use the settings in the "display options" (cmd+J), this applies also to several other folders. Even if I right-click on that particular folder to enter the settings.
    Isn't it possible to apply different sort/arrange options to individual folders?
    p.

    For column view, there is only one arrange/sort, no matter where you are in the hierarchy. It is based on what the arrange/sort was set on the original folder opened.
    In the View Options, the Brows by ??? view checkbox controls what happens when you open a folder from that view. If it is set, then the folder opens in the same view as the enclosing folder. If unchecked, and you have set a view on a folder, that folder will open in the desired view.
    Again, this does not apply in column view. Column view has only one arrange/sort for the entire hierarchy.

  • How to find CPU_time being used by currently executing query

    Hello,
    Is there a way to know how much CPU is being used by a query that is currently being runninng? I tried to look into dm_exec_sessions or even dm_exec_requests dmv but it looks like CPU_time stat doesn't get updated to those views until the query actually
    completes or get cancelled. Sometimes, it's important to find out among the actively running queries, which session/query is consuming the most CPU and there seem to be no way to find out that stat until the query actually completes or get cancelled. I was
    testing it on SQL 2008 r2 but behavior could be same on 2014 or 2012.
    Appreciate any feedback.
    thanks,
    Raj

    I have been using Adam's great utility
    Who Is Active? v10.00 (2010-10-21)
    (C) 2007-2010, Adam Machanic
    Updates: http://sqlblog.com/blogs/adam_machanic/archive/tags/who+is+active/default.aspx
    "Beta" Builds: http://sqlblog.com/files/folders/beta/tags/who+is+active/default.aspx
    License: 
    Who is Active? is free to download and use for personal, educational, and internal 
    corporate purposes, provided that this header is preserved. Redistribution or sale 
    of Who is Active?, in whole or in part, is prohibited without the author's express 
    written consent.
    CPU filter
    /*CPU*/
    EXEC dbo.sp_WhoIsActive
    @get_transaction_info=0,
    @output_column_list ='[session_id][start_time]
                      [cpu][status][context_switches][wait_info][program_name]
                     [database_name][sql_text][host_name][open_tran_count]', 
    @sort_order='[CPU]DESC'
    /*delta*/
    EXEC dbo.sp_WhoIsActive
    @delta_interval=5, @get_task_info = 2,
    @output_column_list ='[session_id][start_time][context switches]
                      [CPU_delta][reads_delta][writes_delta][tempdb_writes_delta]
                      [tempdb_reads_delta][tempdb_current_delta]
                      [database_name][host_name][login_name]', 
    @sort_order='[CPU_delta]DESC'
    Best Regards,Uri Dimant SQL Server MVP,
    http://sqlblog.com/blogs/uri_dimant/
    MS SQL optimization: MS SQL Development and Optimization
    MS SQL Consulting:
    Large scale of database and data cleansing
    Remote DBA Services:
    Improves MS SQL Database Performance
    SQL Server Integration Services:
    Business Intelligence

Maybe you are looking for

  • Expoert out of Final Cut Pro to ATV

    How best to export DV footage out of FCP to use on ATV? No "Movie to AppleTV" export option from FCP like in QuickTime. Wouldn't it show up in FCP if it's in QT? Thanks

  • Inserting into two tables using JDBC Receiver Adapter

    I've defined following type for Receiver JDBC to save data in two different tables Name          Category     Type          Occurrence ReceiverDB_DT     Complex Type           STATEMENT     Element                    1..unbounded TABLE_NAME     Eleme

  • Table API and Generated forms

    I have been told that Oracle Designer Table API (Application Programmer Interface) disables default functionality of querying records in a Headstart generated form, due to limitations with Designer. I am unable to find a bug number for this fault and

  • Printing Across Multiple Labels

    I have a requirement to modify a report that will print data in a designated format. The report was originally designed to accommodate five or less detail lines. Now I have to change the report to accommodate an indefinite number of detail lines that

  • ITUNES CAN'T UPDATE IP0D MINI

    my ipod which isn't that old and is still working won't download my newer songs. it won't allow me to update for a couple of months now and im freaking out!! this little thing pops up at the bottom of my laptop(windows xp) and something like chsdk ut