Wrapping java calls in host system executables

S

Stefan Ram

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?
 
N

Nigel Wade

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?

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

Donkey Hottie

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.

Indeed, that is how ant is implemented in Windows and Unix.
 
A

Arne Vajhøj

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?

Use a small script file (bat/sh).

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

Arne
 
K

Kevin McMurtrie

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?

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

Nigel Wade

Also Maven, WebLogic, ...

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

Arved Sandstrom

Nigel Wade wrote:
[ SNIP ]
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.

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
 
J

John B. Matthews

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

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>

[...]
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?

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>
 
A

Aeris

Stefan said:
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?

See Launch4j, a generic cross-platform java wrapper/launcher
http://launch4j.sourceforge.net/
 
A

Arne Vajhøj

Nigel Wade wrote:
[ SNIP ]
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.

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.

Yes.

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

Arne
 
L

Lew

Nigel said:
[ SNIP ]
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.

Arved said:
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.

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

Much of a muchness.
 
A

Arne Vajhøj

Nigel said:
[ SNIP ]
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.

Arved said:
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.

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

Much of a muchness.

BAT file is correct.

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

Arne
 
L

Lew

Nigel said:
[ SNIP ]
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.

Arved said:
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.

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

Much of a muchness.

BAT file is correct.

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

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

Arved Sandstrom

Lew said:
Nigel Wade wrote:
[ SNIP ]
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.

Arved Sandstrom wrote:
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.

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

Much of a muchness.

BAT file is correct.

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

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.

I'm no guru on the intricacies here either, but AFAIK you're right, CMD and
BAT files are "much of a muchness".

AHS
 
A

Arne Vajhøj

Nigel Wade wrote:
[ SNIP ]
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.

Arved Sandstrom wrote:
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.

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

Much of a muchness.

BAT file is correct.

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

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.

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top