Skip to content

CrazedoutCom/jgazm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

#jGazm

jGazm is a Java Language scriptning tool designed to enable lightning fast Java scripting. Everything the JVM has to offer is now at your service by scripting Java code and getting instant compilation at runtime. How does it work?

Usage: jgazm [file] [-stdin,-dump,-clean,-export:,-keepsource,-noimport,-help,-version,-compiler, -check] %arg1 %arg2 ...

jgazmEdit.bat or open jgazm.jar as executable jar opens jGazm simple editor.

Why jGazm?

Java is a very powerful coding language but has a very high setup/startup overhead. When wanting to use the Java language for smaller or temporary assignments it's is a pain to go through the boilerplate coding of setting up a class and static void main etc. Then you have to compile the source and run the class separately. What if there was a way to execute Java code directly without the hassle of creating the class overhead. jGazm is created for tht soul purpose to execute Java code on the fly, right of the bat without a IDE or java/javac. It can also be used to create batch files or other scripting jobs as file parsing, FTP/HTTP downloads, instant database access and so on...

Running jGazm programs without jGazm

The command line option -export exports and packages all the class files, resources, classpaths etc in a executable jar file. This means the you can distribute your jGazm program as a standard Java program with ease.

jgazm -stdin -export:C:\\myexport\\MyApp.jar
alert("Hello from pure Java");
.
Exported to:C:\myexport\MyApp.jar

How does it work?

jGazm parses the given file or text input stream and creates a Java source file which is compiled at runtime and executed. The created Java object inherits com.crazedout.jgazm.Lang and all code that is not jGazm annotated is placed inside a try/catch java.lang.Exception inside Lang.execute() method. Command line arguments can be obtained from the global String[] ARGS. The flag -dump will print the created Java source to stdout. Exampel of jGazm code:

jgazm -stdin
>out("Hello World");
>. // . on a single line executes...
Generated Java source.
import java.util.*;
import java.sql.*;
import com.crazedout.jgazm.*;
import java.net.*;
import java.lang.*;
import java.io.*;
import static java.util.Arrays.*;

/* Code auto generated by jGazm v.1.0*/

public class defaultjgazm1461509252663_java extends com.crazedout.jgazm.Lang {

    /* main() arguments */
    final String[] ARGS = new String[0];
      public static void main(String argv[]) {
        new defaultjgazm1461509252663_java().execute();
      }
    @Override
    public void execute() {

            try{

    /* JAVA */
    out("Hello World");

            }catch(Exception ex){
                    onException(ex);
            }
    }

}

Hello World!

@classpath ".;" //Set to current dir for example. Change to what ever classpath you want or remove.

@import javax.swing.*; // Not needed in this example but put here for reference.

/* execute the whole file or selected text as long as the texts is executable Java */
System.out.println("Hello from jGazm"); // Select only this statement and hit CTRL+ENTER...

/* View the .setup file for more reference */

String hello = "Hello World";

MyClass mc = new MyClass("Ringo");
out(mc.getName()); //com.crazedout.jgazm.Lang.out(Object out);
showMessage(hello);

@method /* Needed to identify method */
void showMessage(String msg){
    alert(msg); //com.crazedout.jgazm.Lang.alert(String msg);
}

@class /* Needed to identify inner class */
public class MyClass {
    String name;
    public MyClass(String name){
        this.name = name + " Star";
    }

    public String getName(){
        return this.name;
    }
}
@thread {
    out("Executed inside a threads run() method");
}

@exception {
    out("Handle exception" + ex.getMessage());
}

Usage

jGazm must be used with a JDK 1.7 or higher. When distrubuting your jGazm code use -export to make it pure Java and runnable on JRE.

Usage: jgazm {options} [file] %arg1 %arg2 ...
Options:
-stdin				Read input directly from System.in (Single "." + ENTER quits)
-dump				dump script as POJO to stdout.
-dump:[file]			dump script as POJO to [file].
-clean				Remove all temp files generated.
-export:[dest_jar]  		export the works as one java runnable package.
-java				Input file is pure Java. Can not be used with -stdin.
                -dump,-clean,-noimport and -keepsource has no meaning when -java in used.
                will be set by default if file ends width '.java'.
-keepsource			Do not delete generated POJO code.
-noimport			Do not import any packages by default.
-version			Print jgazm version.
-check				Compile only.
-showapi			Print methods of com.crazedout.jgazm.Lang.
-help or /?			Prints this message.

Command line arguments to jGazm programs must be preceded with '%' (%myarg1 %myarg2).

Editor mode:

Start editor: java -jar jgazm.jar

Run jgazm from command line: java -cp ".;jgazm.jar" com.crazedout.jgazm.JGazm [options] [input.file]

Pure mode:

Start jGazm: java -jar jgazm_pure.jar [options] [input.file]

or: java -cp ".;jgazm_pure.jar" com.crazedout.jgazm.JGazm [options] [input.file]

Pipe Java code from command line:

echo File dir = new File("."); String[] files = dir.list(); for(String f:files) out(f); | jgazm -stdin

jgazmEdit.bat Starts in editor mode.

@echo off
REM %JAVA_HOME% must point to current JDK.
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45\jre

REM Path to jgazm.jar file.
set JGAZ_BIN=C:\Fredriks_Mapp\Java\JGazm\release\.\bin\jgazm.jar
set JGAZ_HOME=C:\Fredriks_Mapp\Java\JGazm\release\.

REM Path to user imports file.
set JGAZM_PROPS=C:\Fredriks_Mapp\Java\JGazm\release\.\bin\user.properties

"%JAVA_HOME%/bin/javaw" -classpath "%JGAZ_BIN%" -Djgazm.home="%JGAZ_HOME%" -Djgazm.props="%JGAZM_PROPS%" com.crazedout.jgazm.editor.Editor %1 %2 %3 %4

jgazm.bat starts in command line mode.

@echo off	
REM %JAVA_HOME% must point to current JDK.
set JAVA_HOME=C:\Program Files\Java\jdk1.7.0_45\jre

REM Path to jgazm.jar file.
set JGAZ_BIN=C:\Fredriks_Mapp\Java\JGazm\release\.\bin\jgazm.jar
set JGAZ_HOME=C:\Fredriks_Mapp\Java\JGazm\release\.

REM Path to user imports file.
set JGAZM_PROPS=C:\Fredriks_Mapp\Java\JGazm\release\.\bin\user.properties

"%JAVA_HOME%/bin/java" -classpath "%JGAZ_BIN%" -Djgazm.home="%JGAZ_HOME%" -Djgazm.props="%JGAZM_PROPS%" com.crazedout.jgazm.JGazm %1 %2 %3 %4

About

Java Scripting tool

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages