How to execute main Java programs by command Line

Unofficial Content

Basically, in a command line write:

   java -cp <classpath> <JavaPackageName>.ObjectName
 <ClassPath> --> Java Classpath
 
<JavaPackageName> is related to the Java Package Name property.

Examples

To execute a basic "mainobject" command line object:
C:\Models\SampleKB\JavaModel\web>"C:\Program Files (x86)\Java\jdk1.6.0_22\bin\java.exe" -cp gxclassd.zip;.; amainobject
To execute a pdf report main program called "mainpdfobject", notice we added the iText.jar file:
C:\Models\SampleKB\JavaModel\web>"C:\Program Files (x86)\Java\jdk1.6.0_22\bin\java.exe" -cp gxclassd.zip;.;iText.jar amainpdfobject
To execute an object accesing a mySQL database, notice we added the mySQL driver file:
C:\Models\SampleKB\JavaModel\web>"C:\Program Files (x86)\Java\jdk1.6.0_22\bin\java.exe" -cp gxclassd.zip;.;iText.jar;./drivers/mysql-connector-java-5.1.11-bin.jar amaindbobject
To execute the GeneXus Developer Menu (Win Environment):
java -cp gxclassr.zip;GXUtils.jar;. com.genexus.developermenu <package>
If your model does not have a Java Package Name, just call:
C:\Models\SampleKB\JavaModel\web>"C:\Program Files (x86)\Java\jdk1.6.0_22\bin\java.exe" -cp gxclassd.zip;.;iText.jar;gxutils.jar com.genexus.developermenu
All these samples assumes a Java interpreter is installed on C:\Program Files (x86)\Java\jdk1.6.0_22\ and the generation folder is C:\Models\SampleKB\JavaModel\web.
 
Make sure to always add the gxclassr.zip or gxclassd.zip jar file (as the file contains the GeneXus Standard Classes for the Java generator) and the current folder "." in case the object calls other GeneXus objects.
 
Depending on the object code you will also need additional jar files in the java classpath, check the GeneXus dependencies for the Java generator here.
 
Notice the GxUtils.jar jar file contains GeneXus Utilities classes.