Wrapping java calls in host system executables

Discussion in 'Java' started by Stefan Ram, Oct 4, 2010.

  1. Stefan Ram

    Stefan Ram Guest

    I assume one had written a nice directory lister in Java.
    The only problem would be that the user cannot simply write


    but has to write something along the lines of

    java -cp shelltools com.example.shellcalls.jdir

    in his system text-command shell. Appearingly, jar-files
    can be opened in a GUI, but not directly from a text
    shell, that is, one has to write

    java -jar jdir.jar

    , while simply


    can not be used as an abbreviation for »java -jar jdir.jar«.

    Now, one might write a C program as a wrapper for that

    java -cp shelltools com.example.shellcalls.jdir

    . The straightforward solution would be the C statement

    system( "C:\Programs\Java\jdk1.6.0\bin\java -cp shell..." );

    , but one might need to do some more coding, for
    example, to try to lookup JAVA_HOME and use this and so.

    After all, this seems to be the way the standard call


    has been implemented for a long time: The compiler is
    written in Java, but the call uses a native executable
    wrapper for this.

    So, what I am looking for is some example code for this.
    Maybe someone has already published a generic wrapper code
    in C or C++ under the GPL to be used in such cases?
    Stefan Ram, Oct 4, 2010
    1. Advertisements

  2. Stefan Ram

    Nigel Wade Guest

    Surely it's called the shell.

    In UNIX/Linux you can use a shell alias.
    You could also use a shell script containing the necessary java command
    line, call the script "jdir" and make it executable.

    In Windows land I have no idea if there is a concept similar to the
    shell alias. But you do have the .bat script which serves the same
    function as the executable shell script.
    Nigel Wade, Oct 4, 2010
    1. Advertisements

  3. Indeed, that is how ant is implemented in Windows and Unix.
    Donkey Hottie, Oct 4, 2010
  4. Stefan Ram

    Arne Vajhøj Guest

    Use a small script file (bat/sh).

    Or write a special wrapper. It is not that hard.

    Arne Vajhøj, Oct 4, 2010
  5. Stefan Ram

    Lew Guest

    Also Maven, WebLogic, ...
    Lew, Oct 5, 2010
  6. IntelliJ is a .exe which I'm guessing uses JNI to start up a JVM. Those two
    are pretty much your choices.
    Mike Schilling, Oct 5, 2010
  7. The SDK for an operating system should have a Java tools section for
    this. For Mac OS, XCode provides Jar Bundler.app. I don't know of any
    Sun utility for this and Oracle seems to have 404'ed all the standard
    Java help links.
    Kevin McMurtrie, Oct 5, 2010
  8. Stefan Ram

    Nigel Wade Guest

    NetBeans, Eclipse, Firefox...

    In fact, it's probably harder to find an installed application which
    directly runs a binary executable (or jar) rather than a shell startup
    Nigel Wade, Oct 5, 2010
  9. Nigel Wade wrote:
    [ SNIP ]
    Or a Powershell script. Although for this purpose it's overkill as compared
    to a straight BAT file, in general on Windows Powershell is your friend.

    Arved Sandstrom, Oct 5, 2010
  10. One approach I've taken with command line applications is to supply
    scripts that wrap some of the details. In this example, `java -jar
    ac.jar -l disk.po` may be shortened to `ac -l disk.po`:


    I found this example helpful; it uses JNI_CreateJava.

    John B. Matthews, Oct 5, 2010
  11. Stefan Ram

    Aeris Guest

    See Launch4j, a generic cross-platform java wrapper/launcher
    Aeris, Oct 5, 2010
  12. Stefan Ram

    Arne Vajhøj Guest


    PS is one of the small gems frequently missed by people
    using Windows.

    Arne Vajhøj, Oct 6, 2010
  13. Stefan Ram

    Lew Guest

    In Modern Windows it's actually now a CMD script.

    Much of a muchness.
    Lew, Oct 6, 2010
  14. BAT file is correct.

    That they are executed by CMD.EXE instead of COMMAND.COM
    does not change the extension.

    Arne Vajhøj, Oct 6, 2010
  15. Stefan Ram

    Lew Guest

    All the windows systems at work have .cmd files instead of .bat files. They
    use a different extension. It's not the only place I've seen that.

    Maybe I misconstrue that it's modern Windows. But it's pretty new to me and
    seems to inf - er, affect only newer Windowses.

    I haven't researched this at all so I don't know the rules behind it.
    Lew, Oct 6, 2010
  16. I'm no guru on the intricacies here either, but AFAIK you're right, CMD and
    BAT files are "much of a muchness".

    Arved Sandstrom, Oct 6, 2010
  17. cmd.exe has been in the Windows NT series of OS'es since early 90's.

    ..cmd and .bat files are treated exactly identical by Windows.

    Lots of people that used DOS or Win9x still use .bat files.

    Arne Vajhøj, Oct 6, 2010
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.