NOGDUS
October 22, 2018, 06:37:52 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
  Home   Blogs   Help Search Tags Login Register  
Blog Index » RedSlash's Blog
Test
by RedSlash ... November 03, 2009, 01:16:42 AM
Test
 
0 Comments | Write Comment

TUTORIAL: Making Java applications OS friendly
by RedSlash ... November 15, 2008, 02:22:12 AM
Java is a very useful tool for developing cross-platform programs. This nice thing about Java is that it can build cross-platform bytecode binaries, which can be executed on any systems running JRE. The only drawback to Java is that these binaries are usually distributed as JAR files and it feels unnatural for end-users to be launching JAR files instead of native EXEs.

This is a guide on deploying Java applications on Windows, Linux and Mac OS X by using native executable wrappers to make Java applications feel more like home. This is not a guide on building native Java executables, please see GCJ for that.

The idea is we're going to wrap Java JARs into native exes on each host system. I will be using the application 'JavaSoundDemo.jar' from this package http://java.sun.com/products/java-media/sound/samples/JavaSoundDemo.zip to demonstrate on how to make it OS friendly.

WINDOWS

In Windows, we like launching EXEs instead of JAR files. A google search will tell you about a bunch of utilities that will convert JARS to EXE. I'll show you how to do it yourself. Luckily, Java has the capability to launch JAR files appended on to EXE files since v1.5. What this means is that we can write a C program which would call Java to execute itself, and then tack a JAR file on the end of the exe to make a self running Java executable. First, lets write the wrapper in C:
[code]
#include <process.h>
#include <windows.h>
#include <string.h>

int WINAPI WinMain(HINSTANCE hInst,HINSTANCE hPrev,LPSTR arg,int nShow)
{
   char exe_name[4096], path[4096];
   STARTUPINFO si;
   PROCESS_INFORMATION pi;

   /* Get the fullpath name of the executable */
   int n = GetModuleFileName(hInst,exe_name,4096);
   if(n >= 4096) {
      MessageBox(NULL,"Pathname too long.","Error",MB_ICONERROR);
      return -1;      
   }
   
   /* determine pathname of executable */
   strcpy(path,exe_name);
   char *p = strrchr(path,'\\'); /* look for \ */
   if(!p) {
      char *p = strrchr(path,'/'); /* check for / just in case */
      if(!p) {   
         MessageBox(NULL,"Failed to determine pathname.","Error" ... Read More
 
« Last Edit: July 26, 2009, 07:40:20 PM by RedSlash » 1 Comment | Write Comment
xx
Re: TUTORIAL: Making Java applications OS friendly
by Richard Marks ... November 15, 2008, 10:09:36 PM
That is amazing Redslash! I never knew any of what you covered! Grin
Thank you for posting such valuable information!
I look forward to learning more cool things from you! Cheesy
 

Most Recent
Test
TUTORIAL: Making Java applications OS friendly
Blog Mod 1.08 by Charles Hill
Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!