Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit 7ff7de1

Browse files
build executable JAR and optionally a native image
1 parent 9c98e50 commit 7ff7de1

File tree

1 file changed

+77
-54
lines changed

1 file changed

+77
-54
lines changed

standalone/pom.xml

Lines changed: 77 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,28 @@
5959
</resource>
6060
</resources>
6161
<plugins>
62+
<plugin>
63+
<groupId>com.googlecode.addjars-maven-plugin</groupId>
64+
<artifactId>addjars-maven-plugin</artifactId>
65+
<version>1.0.5</version>
66+
<executions>
67+
<execution>
68+
<goals>
69+
<goal>add-jars</goal>
70+
</goals>
71+
<configuration>
72+
<resources>
73+
<resource>
74+
<directory>${sqlcl.libdir}</directory>
75+
<includes>
76+
<include>**/dbtools-common.jar</include>
77+
</includes>
78+
</resource>
79+
</resources>
80+
</configuration>
81+
</execution>
82+
</executions>
83+
</plugin>
6284
<plugin>
6385
<groupId>org.apache.maven.plugins</groupId>
6486
<version>3.8.1</version>
@@ -70,56 +92,59 @@
7092
</plugin>
7193
<plugin>
7294
<groupId>org.apache.maven.plugins</groupId>
73-
<artifactId>maven-jar-plugin</artifactId>
74-
<version>3.2.0</version>
75-
<configuration>
76-
<finalName>${project.artifactId}</finalName>
77-
<archive>
78-
<addMavenDescriptor>false</addMavenDescriptor>
79-
<manifest>
80-
<addClasspath>true</addClasspath>
81-
<useUniqueVersions>false</useUniqueVersions>
82-
<classpathPrefix>lib/</classpathPrefix>
83-
<mainClass>com.trivadis.plsql.formatter.TvdFormat</mainClass>
84-
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
85-
</manifest>
86-
<manifestEntries>
87-
<Class-Path>lib/dbtools-common-21.2.0.jar</Class-Path>
88-
</manifestEntries>
89-
</archive>
90-
</configuration>
91-
</plugin>
92-
<plugin>
93-
<groupId>org.apache.maven.plugins</groupId>
94-
<artifactId>maven-dependency-plugin</artifactId>
95-
<version>3.1.1</version>
95+
<artifactId>maven-shade-plugin</artifactId>
96+
<version>3.2.4</version>
9697
<executions>
9798
<execution>
98-
<id>copy-dependencies</id>
9999
<phase>package</phase>
100100
<goals>
101-
<goal>copy-dependencies</goal>
101+
<goal>shade</goal>
102102
</goals>
103-
<configuration>
104-
<outputDirectory>target/lib</outputDirectory>
105-
<overWriteReleases>false</overWriteReleases>
106-
<overWriteSnapshots>true</overWriteSnapshots>
107-
<overWriteIfNewer>true</overWriteIfNewer>
108-
<excludeTransitive>false</excludeTransitive>
109-
<includeScope>compile</includeScope>
110-
<stripVersion>false</stripVersion>
111-
</configuration>
112103
</execution>
113104
</executions>
114-
</plugin>
115-
<plugin>
116-
<groupId>org.apache.maven.plugins</groupId>
117-
<artifactId>maven-surefire-plugin</artifactId>
118-
<version>2.22.2</version>
119105
<configuration>
120-
<includes>
121-
<include>**/*.java</include>
122-
</includes>
106+
<finalName>${artifactId}</finalName>
107+
<shadedArtifactAttached>false</shadedArtifactAttached>
108+
<transformers>
109+
<transformer implementation="org.apache.maven.plugins.shade.resource.ServicesResourceTransformer"/>
110+
<transformer
111+
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
112+
<manifestEntries>
113+
<Main-Class>com.trivadis.plsql.formatter.TvdFormat</Main-Class>
114+
<Class-Path>.</Class-Path>
115+
</manifestEntries>
116+
</transformer>
117+
</transformers>
118+
<filters>
119+
<filter>
120+
<!-- remove conflicting resources (not required) -->
121+
<artifact>*:*</artifact>
122+
<excludes>
123+
<exclude>META-INF/MANIFEST.MF</exclude>
124+
<exclude>module-info.class</exclude>
125+
<exclude>META-INF/versions/**</exclude>
126+
</excludes>
127+
</filter>
128+
<filter>
129+
<!-- include required packages for formatter -->
130+
<artifact>*:*dbtools-common*</artifact>
131+
<includes>
132+
<include>oracle/dbtools/app/**</include>
133+
<include>oracle/dbtools/arbori/**</include>
134+
<include>oracle/dbtools/parser/**</include>
135+
<include>oracle/dbtools/raptor/*</include>
136+
<include>oracle/dbtools/raptor/utils/**</include>
137+
<include>oracle/dbtools/util/**</include>
138+
</includes>
139+
</filter>
140+
<filter>
141+
<!-- include all classes and resources from this project -->
142+
<artifact>*:tvdformat</artifact>
143+
<includes>
144+
<include>**</include>
145+
</includes>
146+
</filter>
147+
</filters>
123148
</configuration>
124149
</plugin>
125150
<plugin>
@@ -136,18 +161,16 @@
136161
</executions>
137162
<configuration>
138163
<skip>${skip.native}</skip>
139-
<imageName>tvdformat</imageName>
140-
<!-- "-language:js -no-fallback" leads to a runtime error:
141-
Exception in thread "main" javax.script.ScriptException: org.graalvm.polyglot.PolyglotException: TypeError: Access to host class java.lang.String is not allowed or does not exist.
142-
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.toScriptException(GraalJSScriptEngine.java:483)
143-
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:460)
144-
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:400)
145-
at com.trivadis.plsql.formatter.TvdFormat.run(TvdFormat.java:40)
146-
at com.trivadis.plsql.formatter.TvdFormat.main(TvdFormat.java:46)
147-
Caused by: org.graalvm.polyglot.PolyglotException: TypeError: Access to host class java.lang.String is not allowed or does not exist.
148-
at <js>.:program(<eval>:19)
149-
at org.graalvm.polyglot.Context.eval(Context.java:375)
150-
at com.oracle.truffle.js.scriptengine.GraalJSScriptEngine.eval(GraalJSScriptEngine.java:458)
164+
<imageName>${project.artifactId}</imageName>
165+
<mainClass>com.trivadis.plsql.formatter.TvdFormat</mainClass>
166+
<!-- Creating a native image with "-language:js -no-fallback -H:ReflectionConfigurationFiles=..."
167+
was e dead end. There were various issues, such as
168+
- different behavior between JS/Java Strings and their methods
169+
- laborious identification of classes used via reflection
170+
- long build times (~280 seconds)
171+
- very large image size (437MB)
172+
Therefore, creating a native image which requires a JDK was much simpler.
173+
The drawback is a slower startup time. However, loading 437MB is not fast ether, at least the first time.
151174
-->
152175
<buildArgs>
153176
-H:IncludeResources=.* --force-fallback

0 commit comments

Comments
 (0)