Skip to content

Commit 07f92cb

Browse files
authored
Add support to build a execuable jar (#16)
Co-authored-by: rick <[email protected]>
1 parent 0eced52 commit 07f92cb

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

.github/workflows/build.yaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
# This workflow will build a package using Maven and then publish it to GitHub packages when a release is created
2+
# For more information see: https://github.com/actions/setup-java/blob/main/docs/advanced-usage.md#apache-maven-with-a-settings-path
3+
4+
name: Maven Package
5+
6+
on:
7+
release:
8+
types: [created]
9+
10+
jobs:
11+
build:
12+
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: read
16+
packages: write
17+
18+
steps:
19+
- uses: actions/checkout@v2
20+
- name: Set up JDK 11
21+
uses: actions/setup-java@v2
22+
with:
23+
java-version: '11'
24+
distribution: 'adopt'
25+
server-id: github # Value of the distributionManagement/repository/id field of the pom.xml
26+
settings-path: ${{ github.workspace }} # location for the settings.xml file
27+
28+
- name: Build with Maven
29+
run: mvn -B package --file pom.xml
30+
31+
- name: Publish to GitHub Packages Apache Maven
32+
run: mvn deploy -s $GITHUB_WORKSPACE/settings.xml
33+
env:
34+
GITHUB_TOKEN: ${{ github.token }}

README.md

+11
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,14 @@ According to different use cases, we provide several Jenkinsfile for you:
1010
|[Jenkinsfile.jmeter.groovy](Jenkinsfile.jmeter.groovy)|A kubernetes environment|Running a JMeter test in Jenkins|
1111
|[Jenkinsfile-milestone.groovy](Jenkinsfile-milestone.groovy)|None|Abort running build if new one is started|
1212
See also https://jenkins-zh.cn/about/course/#1
13+
14+
# Jar
15+
16+
You can run it via the following:
17+
18+
```
19+
mvn package
20+
java -jar target/demo-junit-1.0.1-20170422.jar
21+
```
22+
23+
# War

pom.xml

+23
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,29 @@
2525
<target>7</target>
2626
</configuration>
2727
</plugin>
28+
<plugin>
29+
<groupId>org.apache.maven.plugins</groupId>
30+
<artifactId>maven-jar-plugin</artifactId>
31+
<executions>
32+
<execution>
33+
<id>make-a-jar</id>
34+
<phase>compile</phase>
35+
<goals>
36+
<goal>jar</goal>
37+
</goals>
38+
</execution>
39+
</executions>
40+
<configuration>
41+
<archive>
42+
<manifest>
43+
<addClasspath>true</addClasspath>
44+
<mainClass>
45+
cli.App
46+
</mainClass>
47+
</manifest>
48+
</archive>
49+
</configuration>
50+
</plugin>
2851
</plugins>
2952
</build>
3053

src/main/java/cli/App.java

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package cli;
2+
3+
/**
4+
* This is a demo for Java executable jar
5+
*/
6+
public class App {
7+
public static void main(String[] args) {
8+
System.out.println("Env: NAME=" + System.getenv("NAME"));
9+
}
10+
}

0 commit comments

Comments
 (0)