Reputation: 1225
I'm trying to make one of my command line utilities a little more user friendly. Most of my co-workers don't mind using the utility as a CLI, but navigating to it is a bit of a pain (to them). I'd rather not go to every computer and set up a shortcut in their CLI so:
Is there a way to make a .jar file launch a command line utility into a command prompt (preferably PowerShell?) I tried searching Google and Stack Overflow but am having a hard time making headway... Any direction would be much appreciated.
I somehow imagine this using Desktop
, but am not sure how that would work.
Upvotes: 4
Views: 4205
Reputation: 11940
Maybe you need to make a swing based console to redirect output and input. Here are the links I found in a simple web search. (I've never used these before)
And an open source project here at Swing-Console.
EDIT:
Another option. What if you distribute your application with a run-me.bat
file?
@echo off
java -jar my-console-app.jar
You can also change the title.
Upvotes: 9
Reputation: 7929
You have at least two options.
Make an executable jar file.
An example on Windows would look something like this:
mkdir temp
cd temp
for %f in (..\dist\lib\*.jar) do @jar xf %f
jar xf ..\dist\YourJar.jar
jar cfe YourJar.jar com.something.Main *.*
You can read more about the jar archive tool here: http://docs.oracle.com/javase/1.4.2/docs/tooldocs/windows/jar.html
This is a lot easier with Maven. See the Maven shade plug-in here: https://maven.apache.org/plugins/maven-shade-plugin/
Make a Java Web Start application
For an overview, take a look at this: http://docs.oracle.com/javase/tutorial/deployment/webstart/
For a step by step guide, take a look at this: http://docs.oracle.com/javase/7/docs/technotes/guides/javaws/developersguide/contents.html
Upvotes: 0
Reputation: 414
You should reassociate jar files with java.exe instead of javaw.exe. javaw is the non-CLI version of Java, but launching it with java.exe instead should do the trick.
This is how to do that(provided you have administrative rights):
assoc .jar=jarfileterm
ftype jarfileterm="PATH\TO\JRE\bin\java.exe" -jar "%1" %*
Of course, replace PATH\TO\JRE with the correct path. After doing this, double-clicking a .jar file should open a CLI.
Upvotes: 0