A console tool is started at command line with arguments.
Introduction
If your java program is a tool to start at command line with arguments, this advice will show you the complete solution by Jar2exe, with a live demo.
Solution
With Jar2Exe, you can start your java program from an exe file instead of a bat file. The VM parameters can be put into config , so the only file you need to redistribute is a single exe file.
This type of programs are usually small programs (<10M) for download, so you need not ship a whole 'jre' with your program. Instead, you can let the exe file prompt user to download and install JRE following your instructions.
Features used
We advise you to use following features in your solution:
Feature | Advice | Introduction | How to enable |
---|---|---|---|
Minimum JRE |
Recommended |
If you use a feature of JRE since a certain version, you'd better prompt user the minimum version. For example, regular expression since 1.4. |
At Step 1, select a min version |
Encryption |
Recommended |
If you want to protect your program from being extracted and decompiled, you can select to encrypt it. |
At Step 4, check the encrypt option |
Custom messages |
Recommended |
Prompt user to download JRE from http://java.com in your own words. |
At Step 6 > Version & Messages, edit the message |
Config internal |
Optional |
Put configs such as VM parameters internal into exe, in order to let your program a single exe file. |
At Step 6 > Config Internal |
Program icon |
Optional |
Add a program icon to the exe file. A console tool is usually started at command line, so a program icon is not necessary. |
At Step 6 > Version & messages |
Steps with live demo
You can refer to this live demo to know this solution.
-
Write the java program: (download here)
package com.regexlab.toys; import java.io.*; import java.util.regex.*; public class SvnDumpUp { /** * Entry point of tool, arguments of exe file will be passed to main() as arguments */ public static void main(String[] args) throws Exception { if(args.length < 2) { // print Usage here if user does not pass in parameters System.out.println("Usage: svndumpup <dumpfile> <parent-to-remove>"); return; } ......
- Compile into class file and then pack into a jar file: 'svndumpup.jar'.
- Start Jar2Exe, at step 1, click Browse Jar and select 'svndumpup.jar'.
- At step 1, click the Min box and edit it to 1.4.2.
- At step 2, select Console application.
- At step 3, select the main class com.regexlab.toys.SvnDumpUp.
- At step 4, check the "Encrypt and hide class files" option.
-
At step 6, click "Version & Message", then
- At "Product Info" tab, click Add to add a program icon.
- At "Custom message" tab, click the item "1", then type a new message in Edit box "Please download JRE at http://java.com ".
- Press OK to close this popup dialog.
- At step 6, click "Config Internal", add some config item if you need, then press OK to close.
- Click next to create the 'svndumpup.exe' file.
Download
- You can download the 'svndumpup.exe' and get more usage on this page
- solutions-all.zip - 11.3M, all solution related files in one file.
Comments
window disappears immediately
window disappears immediately after the execution of the program, how to put it on pause?
Add new comment