Click here to Skip to main content
13,289,552 members (58,100 online)
Click here to Skip to main content
Add your own
alternative version


15 bookmarked
Posted 4 Oct 2010

EXE Launcher for Java Desktop Application

, 11 Oct 2010
Rate this:
Please Sign up or sign in to vote.
A useful launcher for JAR executable files, with Splash Image function


Many users asked how to make an EXE file from a Java SE project. First of all, we must say that creating an EXE build file from a JAVA source is possible, but it is out of purpose and it is a very bad idea!

As may be evident, although JAR is an executable file, EXE file for more users (end-users) can be more comfortable. So the idea is to create an EXE reference file that can run “java -jar” command, or “javaw -jar” command for Windows usage. More articles on the web explain how to create a BAT file with the same scope, furthermore other tools can easily convert BAT -> EXE. Now, why don't you create a simple EXE automated file that can perform these tasks?

This is a simple work, reusable for small and medium projects, a work that wants to be a starting point for creating personal EXE application launcher for your custom desktop Solutions.


  • Java Runtime Bin Directory must be in your system class path.


In the background, I explain the use of certain methods, like strtok() a tokenizer function:

char* token = strtok(result, "\\.");
    while (next != "exe") {
        name = next;
        token = strtok(NULL, "\\.");

This is a piece of source code. The char* token variable is where the strtok() stores pieces of main string.

strtok(result, "\\."); 

This gets the first piece of result string dividing by two characters "\" and "." ; So why "\\." ? Because "\" causes formatting error. Why these two characters are explained in the next section, however result string is the simple path of EXE application, so it iterates each piece up to the last "AppName.exe", it discards "EXE" and keeps only a simple name of app.

The strtok() function has a particular use as you can see. The next iterations of that function will be:

strtok(NULL, "\\."); 

until the end of string.

Using the Code

Anyway a picture is better than a thousand words (also if this picture is a piece of code). :)

#include <iostream>

#include <fstream>

#include <windows.h>

using namespace std;

string getAppName() {

    // Creates char array with maximum needed length
    char result[MAX_PATH];
    // Uses <windows.h> method to retrieve app name. Only Windows OS
    std::string(result, GetModuleFileName(NULL, result, MAX_PATH));

    char* token;
    string name, next = "";

    //Iterates until end of tokens of Name string, divided by char -> '\' and '.'
    //The only '.' in Filename must be that for ".exe" , error otherwise.
    token = strtok(result, "\\.");
    while (next != "exe") {
        name = next;
        token = strtok(NULL, "\\.");
    return name;

int main(int argc, char** argv) {

    ifstream file; // file stream
    string value = "";
    string jar_name = "";
    string image_name = "splash.gif";"run.ini");
    if (!file) { // file does not exist, so use standard name
        jar_name = getAppName();
        jar_name += ".jar";
    } else {
        do {
            file >> jar_name;
            file >> image_name;
        } while (!file.eof());

    //Launch JAVAW command on "jar_name" file with "image_name" splash image
    string exec_command = "start javaw -splash:" + image_name + " -jar " + jar_name;

    return 0;

The application works in two way. First, it seeks for a file named “run.ini” in the same folder, when found, it retrieves from file two string values (jar_name, image_name) delimited by RETURN character (or rather each string per line). Its job is to build a simple exec String like this:

  • javaw -splas:image_name -jar jar_name

and it invokes system(command) to execute it like you are in command window.

The second way of application, if “run.ini” does not exist in folder, it retrieves (jar_name, image_name) by default parameters, that is jar_name = ApplicationName.jar ( where ApplicationName is the name of EXE file ) and image_name = “splash.gif”. As mentioned earlier, it is a starter point for a custom application launcher capable of reading a custom configuration file.

For the uninitiated, the splash image is the Loading Image that appears when application is loading. From JAVA 6, the “java” command is able to load directly an image for splash screen. So valuable uses for this little application is just to load a splash screen for our application.


  • In the source code, we have the execution command preceded by "start" key. This is one way to avoid console window show.
  • EXE implies that we are on Windows Platform (strong implication) so this code works only on Windows. Why? Because:
    std::string(result, GetModuleFileName(NULL, result, MAX_PATH));

    is the way to retrieve app name in Windows. It may not work on Linux for example.


This article, along with any associated source code and files, is licensed under The Apache License, Version 2.0


About the Author

Engineer n
Italy Italy
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralProcessname is still jawaw.exe Pin
Reto7018-Oct-10 9:46
memberReto7018-Oct-10 9:46 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.171207.1 | Last Updated 11 Oct 2010
Article Copyright 2010 by b4rc0ll0
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid