https://github.com/samurai016/jre-maven-plugin
Maven plugin that bundles a JRE inside the project
https://github.com/samurai016/jre-maven-plugin
adoptium github-packages java jre maven maven-plugin
Last synced: about 1 month ago
JSON representation
Maven plugin that bundles a JRE inside the project
- Host: GitHub
- URL: https://github.com/samurai016/jre-maven-plugin
- Owner: Samurai016
- License: gpl-3.0
- Created: 2025-01-31T13:28:56.000Z (3 months ago)
- Default Branch: master
- Last Pushed: 2025-02-10T21:49:55.000Z (3 months ago)
- Last Synced: 2025-04-02T08:17:49.817Z (about 1 month ago)
- Topics: adoptium, github-packages, java, jre, maven, maven-plugin
- Language: Java
- Homepage: https://samurai016.github.io/jre-maven-plugin/
- Size: 445 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# JRE Maven Plugin
[](https://github.com/Samurai016/jre-maven-plugin/releases/latest)
[](https://mvnrepository.com/artifact/io.github.samurai016.plugins/jre-maven-plugin)
[](https://adoptium.net/)This Maven plugin allows you to bundle a JRE inside your project.
It can download the JRE from [Adoptium](https://adoptium.net/) and optionally unzip it to a specified directory.## 🚀 Usage
Add the following to your `pom.xml` to use the plugin:
```xml
io.github.samurai016.plugins
jre-maven-plugin
1.0.0
jre-bundler
21
${project.build.directory}/bundled-jre
${project.build.directory}/final-jre
```
## 🔧 Plugin Parameters
| Parameter | Default Value | Description |
|------------------|----------------------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `version` | `${maven.compiler.source}` | The version of the JRE to download. Specify a valid Java feature version (e.g., 8, 11, 17, 21). |
| `jvmImpl` | `hotspot` | The JVM implementation to download. Currently, only `hotspot` is supported. [See Adoptium V3 API docs for more details][adoptium-docs] |
| `architecture` | `x64` | The architecture of the JRE to download (e.g., `x64`, `arm64`). [See Adoptium V3 API docs for more details][adoptium-docs] |
| `os` | `windows` | The operating system for the JRE (e.g., `windows`, `linux`, `mac`). [See Adoptium V3 API docs for more details][adoptium-docs] |
| `imagetype` | `jre` | The type of image to download. It is recommended to use the `jre` image type as it is the smallest version available. [See Adoptium V3 API docs for more details][adoptium-docs] |
| `vendor` | `eclipse` | The vendor providing the JRE. Currently, only `eclipse` (Adoptium) is supported. [See Adoptium V3 API docs for more details][adoptium-docs] |
| `outputdir` | `${project.build.directory}/jre` | The directory where the JRE will be downloaded. You can use variables in the form `{{variable}}`. |
| `outputfilename` | `.zip` | The name of the output file. If not specified, it will use the release name of the JRE with `.zip` appended if necessary. |
| `unzipto` | N/A | The directory where the JRE will be unzipped. If not specified, the JRE will not be unzipped. |
| `movetoroot` | `true` | If `true`, the contents of the first-level folder in the JRE zip will be moved to the root directory. If `false`, they will stay nested. |## 🛠️ Example Configuration
### Basic Example
```xml21
${project.build.directory}/bundled-jre
${project.build.directory}/unpacked-jre
true```
### Advanced Example
In this example, we specify all possible configuration options:```xml
21
hotspot
x64
linux
jre
eclipse
${project.build.directory}/bundled-jre
jre.zip
${project.build.directory}/jre
true```
### Real World Example
In this example, we use the same JRE version as the project and we use:* **jre-maven-plugin** to bundle the JRE.
* [maven-shade-plugin](https://maven.apache.org/plugins/maven-shade-plugin/) to create a fat JAR (with dependencies).
* [launch4j-maven-plugin](https://github.com/orphan-oss/launch4j-maven-plugin) to create an executable file for Windows which includes the JRE.In this way, we can create a standalone executable file that runs on Windows without requiring the user to have Java installed or to update any existing Java installations.
```xml
4.0.0
io.github.samurai016.plugins.example
jre-maven-plugin-example
0.1.0-SNAPSHOT
jar
21
21
21
UTF-8
io.github.samurai016.plugins.example.App
io.github.samurai016.plugins
jre-maven-plugin
1.0.0
jre-bundler
${maven.compiler.release}
x64
jre
windows
target/jre
org.apache.maven.plugins
maven-shade-plugin
package
shade
${app.mainClass}
com.akathist.maven.plugins.launch4j
launch4j-maven-plugin
l4j-clui
package
launch4j
console
target/${project.artifactId}.exe
target/${project.artifactId}.jar
./jre/${jre.version};%JAVA_HOME%;%PATH%
```
## 🔍 How It Works
1. **Parameter Configuration:** The plugin reads the configuration parameters specified in `pom.xml`.
2. **Adoptium API Interaction:** It retrieves the latest available JRE version from Adoptium.
3. **Download:** The JRE binary is downloaded to the specified output directory.
4. **Unzip (Optional):** If the `unzipto` parameter is set, the JRE is extracted to the given directory.
5. **Move to Root (Optional):** If `movetoroot` is `true`, the contents of the first-level folder in the archive are moved to the root.## 📌️ Example Directory Structure
With the following configuration:
```xml
${project.build.directory}/bundled-jre
jre.zip
${project.build.directory}/jre
true
```
The result will be:
```
/target/bundled-jre
├── jre.zip
/target/jre
├── bin/
├── lib/
├── ...
```## 💻 Development
To build and test the plugin locally, run:
```sh
mvn clean install
```## 🛡️ License
This project is licensed under the [GNU General Public License v3.0](https://github.com/Samurai016/jre-maven-plugin/LICENSE.md).## 🤝 Contributing
Contributions are welcome! Please fork the repository and submit a pull request.## 🐛 Issues
If you encounter any problems, feel free to [open an issue](https://github.com/Samurai016/jre-maven-plugin/issues).## ❤️ Credits
Thanks to [Adoptium](https://adoptium.net/) for providing reliable JRE builds.[adoptium-docs]: https://api.adoptium.net/q/swagger-ui/