Snippet. CPP. Execute a Java class on Windows

This small CPP snippet sends a command to the Java virtual machine to run a specified Java class. This can be useful, if we want the Java application to have a native executable.

#include <windows.h>
#include <stdio.h>
#define MAIN_CLASS  "MyApplication"
int main( int argc, char** argv )
  char* cmdline = malloc( 1024 ); /* big buffer */
  sprintf( cmdline, "java.exe %s", MAIN_CLASS );
  system( cmdline );
  return 0;

Updated on: 21 Jul 2024