3 Replies Latest reply: Apr 23, 2010 4:00 PM by 794459 RSS

    Please help with reflection


      i have an executable Test.jar wrapped inside an executable Test.exe (by jsmooth) that can be launched by dclicking on it (yes i know Test.jar can also be launched by dclicking on it). the main entry point of the app is Test.java.

      user renames Test.exe to Tested.exe and dclicks on Tested.exe to run it (yes it does run).
      when Tested.exe runs, is there a way for main() of Test.java to know the name of the executable (Tested.exe)?

        • 1. Re: Please help with reflection
          Not with reflection, no.

          (And before you ask I don't know if there's any other way either. That's really a question about jsmooth anyway since Java classes are not normally run that way.)
          • 2. Re: Please help with reflection
            • 3. Re: Please help with reflection
              I know this isn't an elegant solution or anything, and you may not even be able to do it this way (it depends on why you're using JSmooth), but you could write your own executable in C (easy if all your executable is doing is telling the system to run the JAR file). Your executable can then get its own name (by default argv[0] in the main function of the executable) and pass that as a command-line argument into the main (String [] args) function of your Java code.

              In other words, you can have an executable whose approximate C code is:
              int main( int argc, const char* argv[] )
                      //your command is the concatenation of the two strings specified, the latter of which is the executable's name
                      commandString = strcat ("java yourClassName ", argv[0]);
                     // if done correctly, issuing this from a C program is like typing commandString into the command line
              Your Java main method would then receive the name of the executable and could do whatever with it. Like I said, though, I don't know if this solution is really something you'd want to do.