Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

davidmoten/java-script-template

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

31 Commits

Repository files navigation

java-script-template

Can you write a script with Java?

So there are lots of great scripting languages out there that offer a lot over plain old shell scripting. If you know java then groovy is very close and a good option but there is the alternative to write pure java by running the source with runjava (below) or embedding it into a bash script like example.sh.

How to run java source in a separate file

If you want to run java source in a separate file then use runjava. For example:

Example.java:

import java.io.*;
import java.text.*;
import java.util.*;
public class Example {
 public static void main(String[] args) throws Exception {
 System.out.println("Hello " + args[0] + "!");
 }
}

Run it like this (passing dave as an argument):

$ ./runjava Example.java dave
Hello dave!

On my i7 desktop it takes 0.8 seconds to run (compile and execute). Same startup lag as groovy (which you would expect!).

How to embed java source in a bash script

example.sh is a bash script that has Example.java embedded in it. It is designed to be run with a linux/unix bash shell.

The script is run by entering ./example.sh at the command line.

About

Template for a bash script that compiles and runs java commands

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

AltStyle によって変換されたページ (->オリジナル) /