Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tambapps/groovexec
Script to execute Groovy JARs without Groovy SDK in them
https://github.com/tambapps/groovexec
groovy jar
Last synced: 12 days ago
JSON representation
Script to execute Groovy JARs without Groovy SDK in them
- Host: GitHub
- URL: https://github.com/tambapps/groovexec
- Owner: tambapps
- License: apache-2.0
- Created: 2022-07-22T15:02:50.000Z (over 2 years ago)
- Default Branch: main
- Last Pushed: 2022-12-11T20:07:13.000Z (about 2 years ago)
- Last Synced: 2024-11-13T08:36:28.614Z (2 months ago)
- Topics: groovy, jar
- Language: Groovy
- Homepage:
- Size: 12.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# groovexec: Execute JARs without Groovy SDK in them
## Why groovexec
Groovy can be used for scripting, but sometimes you need more than one class, and then your script turns into a
project. To execute a Groovy project (without an IDE), you would have to compile it. You could compile
the jar, including all the Groovy dependencies (`groovy-all` or specific dependencies like `groovy-json`) and then launch `java -jar my-groovy-project.jar` but
these jar can be quite heavy, as they include the whole Groovy SDK (at least the core of groovy).If you installed Groovy on your computer, you already have the Groovy SDK. So why bother including it in your project's jar, making it heavier?
Just build a jar containing only your compiled source code (and your other non-Groovy dependencies if any) and then execute it
using your installed Groovy SDK.groovexec helps you execute such jars, relying on the Groovy SDK installed in your computer.
## How to use
Here is the usage of the script
```text
usage: groovexec [options] /path/to/jar [jar arguments]
-D,--define (Optional) Define a system property (can be used
many times)
-m,--main-class (Optional) The main class to use. Will try to
guess it using the main attribute 'Main-Class'
from the jar's manifest if not provided
```If you are on Linux, you can install it with the `install.sh` script. It will put the script under the `/bin`
directory of you groovy installation.### Examples
Will try to find a main class in the jar
```shell
groovexec jar-without-groovy-sdk.jar --my-project-arg 123
```Or, if you want to explicitly specify the main class
```shell
# Specifying the main class and some java system properties
groovexec -m my.groovy.project.Main jar-without-groovy-sdk.jar --my-project-arg 123
```
You can also define some Java System properties
```shell
# Specifying the main class and some java system properties
groovexec -D propert1=value1 -D property2=value2 jar-without-groovy-sdk.jar --my-project-arg 123
```Note that if you don't want to install the groovexec, you could just execute the script with `groovy`.
Use
```shell
groovy groovexec.groovy args...
```Instead of
```shell
groovexec args...
```## Excluding Groovy SDK from your JARs
To make your JAR smaller, you would have to exclude Groovy SDK when building it.### In Gradle projects
Use the `compileOnly` for all your Groovy dependencies (actually I haven't tested this as I am a Maven guy, so if it doesn't work please, notify me)E.g.
```groovy
compileOnly group: 'org.apache.groovy', name: 'groovy-all', version: '4.0.3', ext: 'pom'
compileOnly group: 'org.apache.groovy', name: 'groovy-cli-commons', version: '4.0.3'
```### In Maven projects
Add the `provided` scope to all your Groovy dependencies
E.g.
```xml
org.apache.groovy
groovy-all
4.0.3
pom
org.apache.groovy
groovy-cli-commons
4.0.3
provided
```