Skip to content

Commit

Permalink
Merge pull request #22 from michab66/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
michab66 authored Mar 24, 2020
2 parents a61415e + be00554 commit 8a0ba93
Show file tree
Hide file tree
Showing 7 changed files with 332 additions and 55 deletions.
49 changes: 41 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,23 @@ Yet another Java launcher generator for Windows. Unique features are:
* Knows about (jigsaw) modules.
* Works with Java 10+.
* Automatically creates the necessary icon resources from a single .png image.
* Offers a command line option to generate a Windows `.ico`-file from a given `.png`-file.

Many other fine launchers exist. But after a long search we did not find one that was able to work with Java 11 and application images generated by JLink. jlgen is in use today as part of our Windows toolchain for generating Java-JLink-based native Windows installers for a set of commercial applications. And no customer knows it's Java :)
Many other fine launchers exist. But after a long search we did not find one that was able to work with Java 11 and application images generated by JLink. jlgen is in use today as part of our Windows build chain for generating Java-JLink-based native Windows installers for a set of commercial applications. And no customer knows it's Java :)

## How to generate a launcher
In addition we had a hard time to generate Windows `.ico`-files. The existing tools didn't work or were clumsy to use, so we added this to `jlgen`.

Get the latest version of the jlgen executable from the project's [release page](https://github.com/michab66/jlaunch/releases).
# Usage

`jlgen.exe` is a command line application that supports different commands. The command *`MakeLauncher`* represents the central functionality of the software. It generates a native Windows launcher for a JLink-generated Java application image.
Firstly, get the latest version of the jlgen executable from the project's [release page](https://github.com/michab66/jlaunch/releases).

`jlgen.exe` is a command line application that supports different commands. Execute `jlgen` to get a list of the supported commands.

## How to generate a launcher -- `MakeLauncher`

The command *`MakeLauncher`* represents the central functionality of the software. It generates a native Windows launcher for a JLink-generated Java application image. The command line is

`jlgen MakeLauncher <target.exe> <icon.png> <application module> <start class>`.

The required parameters are:
* The name of the target file, e.g. 'Farboo.exe'. If the .exe extension is not specified then it is added.
Expand All @@ -23,11 +32,35 @@ The required parameters are:
A complete sample call may look like

`jlgen MakeLauncher C:\cygwin64\tmp\Farboo.exe ..\mmt-icon-1024.png app.mmt de.michab.app.mmt.Mmt`.

## I have the launcher executable, what now?
Note that the generated launcher--in our example 'Farboo.exe'--has to be placed in the existing jlink image directory hierarchy at the same position where the file `jvm.dll` is located. This is currently `{jlink-app-root}/bin/server` but this may change in coming versions of the Jdk. (It is a deliberate decision not to look-up the jvm.dll dynamically to prevent to start the target application using a wrong Jdk/Jre that non-deterministically happened to be found.)

In Windows Explorer the launcher is displayed with the application icon that was passed to `jlgen.exe` above. On a double click your application opens, joy starts :)
## How to generate a Windows `.ico`-file -- `CreateWindowsIcon`

The command *`CreateWindowsIcon`* lets you create a Windows `.ico`-file from a given input `.png`-file. Internally the input `.png` gets scaled to square images of the pixel sizes 16x16, 32x32, 64x64, 128x128 and 256x256. The resulting `.ico`-file is generated in the directory of the input file, with an `.ico` suffix. The command line is:

`jlgen CreateWindowsIcon <input.png>`.

A sample command line is

`jlgen CreateWindowsIcon felix.png`.

This results in the creation of the file `felix.ico` in the same directory as `felix.png`.

## How to generate a MacOS `.icns`-file -- `CreateAppleIcon`

The command *`CreateAppleIcon`* lets you create a MacOS `.icns`-file from a given input `.png`-file. Internally the input `.png` gets scaled to square images of the pixel sizes 16x16, 32x32, 64x64, 128x128 and 256x256. The resulting `.icns`-file is generated in the directory of the input file, with an `.icns` suffix. The command line is:

`jlgen CreateAppleIcon <input.png>`.

A sample command line is

`jlgen CreateAppleIcon felix.png`.

This results in the creation of the file `felix.icns` in the same directory as `felix.png`.

# I have the launcher executable and the icon files, what now?
Note that the generated launcher--in our example 'Farboo.exe'--has to be placed in the existing jlink image directory hierarchy at the same position where the file `jvm.dll` is located. This is currently `{jlink-app-root}/bin/server` but this may change in coming versions of the Jdk.

In Windows Explorer the launcher is displayed with the application icon that was passed to `jlgen.exe` above. On a double click your application opens and joy starts :^)

The next step for professional application packing is to create a native Windows installer based on the JLink file system including the `jlgen`-generated launcher that has to be configured as the start application. We use the [WiX toolset](https://wixtoolset.org/) for this purpose, but this is a different story.

Expand Down
2 changes: 1 addition & 1 deletion jlgen/RtIcon.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,4 +43,4 @@ void RtIcon::update(HANDLE resourceHolder, int resourceId)
}

} // namespace windows
} // namespace micbinz
} // namespace mob
7 changes: 6 additions & 1 deletion jlgen/RtIcon.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,16 @@ namespace windows

void update(HANDLE resourceHolder, int resourceId);

const std::vector<std::uint8_t>& raw_png()
{
return data_;
}

GRPICONDIRENTRY GetDirectoryEntry()
{
return directoryEntry_;
}
};

} // namespace windows
} // namespace micbinz
} // namespace mob
59 changes: 51 additions & 8 deletions jlgen/jlgen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,12 +169,49 @@ namespace jlgen
return EXIT_SUCCESS;
}

int WriteImageSet(
const string& file)
/**
* Create an .ico icon file for Windows. Create target file at position
* of input file with extension .ico.
*
* @param pngFile Input png.
*/
int CreateWindowsIcon(
const string& pngFile)
{
smack::util::icons::WriteImageSet(
file,
IMAGE_SIZES );
path icnFile = pngFile;
icnFile.replace_extension(".ico");

cerr << "Writing icon file: " << icnFile << endl;

smack::util::icons::CreateWindowsIcon(
pngFile,
IMAGE_SIZES,
icnFile);

return EXIT_SUCCESS;
}

/**
* Create an .icns icon for Mac. Create target file at position
* of input file with extension .icns.
*
* @param pngFile Input png.
*/
int CreateAppleIcon(
const string& pngFile)
{
path icnFile = pngFile;
icnFile.replace_extension(".icns");

cerr << "Writing icon file: " << icnFile << endl;

// TODO(michab66) The Apple iconviewer expects 16,32,128,256,512.
// But the file with our current setting seems to work.
smack::util::icons::CreateAppleIcon(
pngFile,
IMAGE_SIZES,
icnFile);

return EXIT_SUCCESS;
}

Expand All @@ -199,10 +236,16 @@ namespace jlgen
"startClass"
}),
Commands<string>::make(
"WriteImageSet",
WriteImageSet,
"CreateWindowsIcon",
CreateWindowsIcon,
{
"pngFilename",
}),
Commands<string>::make(
"CreateAppleIcon",
CreateAppleIcon,
{
"imageFilename"
"pngFilename",
})
);

Expand Down
Loading

0 comments on commit 8a0ba93

Please sign in to comment.