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

    jdir

    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

    jdir

    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

    javac

    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
    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
    #2
    1. Advertisements

  3. Indeed, that is how ant is implemented in Windows and Unix.
     
    Donkey Hottie, Oct 4, 2010
    #3
  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
     
    Arne Vajhøj, Oct 4, 2010
    #4
  5. Stefan Ram

    Lew Guest

    Also Maven, WebLogic, ...
     
    Lew, Oct 5, 2010
    #5
  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
    #6
  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
    #7
  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
    script.
     
    Nigel Wade, Oct 5, 2010
    #8
  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.

    AHS
     
    Arved Sandstrom, Oct 5, 2010
    #9
  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`:

    <https://sites.google.com/site/drjohnbmatthews/applecommander/acguide>

    [...]
    I found this example helpful; it uses JNI_CreateJava.

    <http://java.sun.com/javase/6/docs/technotes/guides/jni/spec/jniTOC.html>
    <http://www.jguru.com/forums/view.jsp?EID=1264492>
     
    John B. Matthews, Oct 5, 2010
    #10
  11. Stefan Ram

    Aeris Guest

    See Launch4j, a generic cross-platform java wrapper/launcher
    http://launch4j.sourceforge.net/
     
    Aeris, Oct 5, 2010
    #11
  12. Stefan Ram

    Arne Vajhøj Guest

    Yes.

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

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

    Lew Guest

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

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

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

    Arne
     
    Arne Vajhøj, Oct 6, 2010
    #14
  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
    #15
  16. I'm no guru on the intricacies here either, but AFAIK you're right, CMD and
    BAT files are "much of a muchness".

    AHS
     
    Arved Sandstrom, Oct 6, 2010
    #16
  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
     
    Arne Vajhøj, Oct 6, 2010
    #17
    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.