1. Batch files don't nest well - if I want to call lein.bat from
within another batch file, I have to remember to say "call lein arg
arg..." rather than simply "lein arg arg..." as the latter doesn't
return to the calling script.
2. I use JP Software's Take Command, which implements a command
language almost, but not precisely, like that of cmd.exe. As a result,
lein.bat (in particular, possibly others) fails with syntax errors. I
appreciate that this is a Take Command problem (and it's not too hard
to work around, in fact) but nevertheless it does routinely trip me
up. And presumably other Take Command users have the same problem.
3. Using a bat file to start a GUI application from Explorer causes an
unnecessary and ugly console window to appear.
Before I spend time trying to solve a problem that the Java community
turns out to have solved years ago, is there another solution that
people use? Or is it just one of those things that Windows people put
up with (I'm not a typical Windows user, I guess :-))?
Thanks,
Paul
> The common way of running Java applications (and hence Clojure code)
> on Windows seems to be to use a batch file wrapper (for example,
> lein.bat for Leiningen). It seems to me that there are a number of
> issues with this:
> [...]
> Before I spend time trying to solve a problem that the Java community
> turns out to have solved years ago ...
For simple-and-quick, make an "executable jar" by adding a
META_INF/Manifest.mf
file which calls out the main entry point to the app; then it runs with a
double-click ('lein uberjar' might already do this?)
For slightly prettier and distributable, make a .jnlp file that lists
jar dependencies, icon, etc.; then download/running the .jnlp installs the
app
to your machine. You don't see this too much, but it works okay for the
basic "install a java app" use case... I think by the time it was finally
possible, a lot of people didn't really care any more. Still, it's better
than nothing.
--
Kevin Kelley
You should use "javaw" instead of "java" to start the JVM without the
console window appearing. This should ship with both the JRE and JDK
on Windows.
R.
Thanks. That's certainly one option - I could probably without too
much difficulty put together something similar for Leiningen.
It sounds like there isn't a generic answer, so going with a custom
launcher sounds viable. Hmm, I wonder whether a stub executable plus a
suitable Ant task / Leiningen plugin (see how I use these terms like I
know what they mean? :-)) would be an option - add some static data
onto the stub, which the stub reads and sets the appropriate variables
and command line args, then launches Java.
Something to think about...
Paul.
Sorry for not being clear - I know about javaw, but even with that,
double clicking on a .bat file flashes up a console window (briefly).
I can also set the console to start minimised and it's then a very
minor inconvenience. As I said, there are workarounds (and this is the
least problematic of the three issues I noted) but I still find it an
issue.
Clearly others don't get so up tight about these inconveniences as me,
which is fine. At least that means I haven't missed a solution that
already exists.
Thanks for the feedback,
Paul.
Maybe Windows Script Host is an option, if you haven't looked at that one yet.
Lars Nilsson
Dim WshShell, oExec
Set WshShell = CreateObject("WScript.Shell")
Set oEnv = WshShell.Environment("Process")
oEnv("CLOJURE_DIR") = "C:\\Devtools\\clojure"
oEnv("CLOJURE_JAR") = "C:\\Devtools\\clojure\\clojure.jar"
Set oExec = WshShell.Exec("javaw -cp %CLOJURE_JAR%;.\\classes;.\\src;.
clojure.main %1 -- %*")
Saving this as a .vbs file, and replacing %1 with the name of a gui
.clj file seems to work for me. I don't happen to have any Clojure gui
code laying around, so I just picked the temperature converter program
from the Clojure website (http://clojure.org/jvm_hosted). Closing the
window left the javaw process running, maybe because it doesn't listen
for the closing of the window.
Lars Nilsson
> Maybe Windows Script Host is an option, if you haven't looked at that one yet.
Yes, WSH/VBS is a reasonable option. There are some gotchas which you
need to be careful of though - there's *still* only one filetype
(.vbs) which is executed by cscript or wscript depending on
user-settable defaults (cscript //H:wscript) which makes it
unreliable.
For a really robust solution, I think a custom EXE might be the best
(for the user) answer.
But this is probably far too Windows-specific for the list now. I'll
go off and try to implement something and report back.
Thanks for all the feedback,
Paul.