1111import org .apache .commons .lang3 .SystemUtils ;
1212
1313import io .github .fvarrui .javapackager .model .Platform ;
14- import io .github .fvarrui .javapackager .utils .CommandUtils ;
1514import io .github .fvarrui .javapackager .utils .FileUtils ;
1615import io .github .fvarrui .javapackager .utils .JDKUtils ;
1716import io .github .fvarrui .javapackager .utils .Logger ;
1817import io .github .fvarrui .javapackager .utils .VersionUtils ;
1918
19+ import static io .github .fvarrui .javapackager .utils .CommandUtils .execute ;
20+
21+
2022/**
2123 * Bundles a Java Runtime Enrironment (JRE) with the app
2224 */
@@ -142,11 +144,14 @@ protected File doApply(Packager packager) throws Exception {
142144 // full path to jlink command
143145 File jlink = new File (currentJdk , "/bin/jlink" );
144146
147+ List <File > modulePaths = new ArrayList <File >();
148+ modulePaths .add (modulesDir );
149+ modulePaths .addAll (additionalModulePaths );
150+
145151 // generates customized jre using modules
146- CommandUtils . execute (
152+ execute (
147153 jlink ,
148- "--module-path" , modulesDir ,
149- additionalModulePathsToParams (additionalModulePaths ),
154+ "--module-path=" + StringUtils .join (modulePaths , File .pathSeparator ),
150155 "--add-modules" , modules ,
151156 "--output" , destinationFolder ,
152157 "--no-header-files" ,
@@ -204,13 +209,8 @@ protected String getRequiredModules(File packagingJdk, File libsFolder, boolean
204209 Logger .infoIndent ("Getting required modules ... " );
205210
206211 File jdeps = new File (packagingJdk , "/bin/jdeps" );
207-
208- File jarLibs = null ;
209- if (libsFolder != null && libsFolder .exists ())
210- jarLibs = new File (libsFolder , "*.jar" );
211- else
212- Logger .warn ("No dependencies found!" );
213212
213+ List <File > modulePaths = getModulePaths (jarFile , libsFolder , additionalModulePaths );
214214 List <String > modulesList ;
215215
216216 if (!customizedJre ) {
@@ -228,15 +228,14 @@ protected String getRequiredModules(File packagingJdk, File libsFolder, boolean
228228 } else if (VersionUtils .getJavaMajorVersion () >= 13 ) {
229229
230230 String modules =
231- CommandUtils . execute (
232- jdeps . getAbsolutePath () ,
231+ execute (
232+ jdeps ,
233233 "-q" ,
234234 "--multi-release" , VersionUtils .getJavaMajorVersion (),
235235 "--ignore-missing-deps" ,
236236 "--print-module-deps" ,
237- additionalModulePathsToParams (additionalModulePaths ),
238- jarLibs ,
239- jarFile
237+ "--add-modules=ALL-MODULE-PATH" ,
238+ "--module-path=" + StringUtils .join (modulePaths , File .pathSeparator )
240239 );
241240
242241 modulesList =
@@ -249,15 +248,14 @@ protected String getRequiredModules(File packagingJdk, File libsFolder, boolean
249248 } else if (VersionUtils .getJavaMajorVersion () >= 9 ) {
250249
251250 String modules =
252- CommandUtils . execute (
251+ execute (
253252 jdeps .getAbsolutePath (),
254253 "-q" ,
255254 "--multi-release" , VersionUtils .getJavaMajorVersion (),
256255 "--ignore-missing-deps" ,
257256 "--list-deps" ,
258- additionalModulePathsToParams (additionalModulePaths ),
259- jarLibs ,
260- jarFile
257+ "--add-modules=ALL-MODULE-PATH" ,
258+ "--module-path=" + StringUtils .join (modulePaths , File .pathSeparator )
261259 );
262260
263261 modulesList =
@@ -288,23 +286,21 @@ protected String getRequiredModules(File packagingJdk, File libsFolder, boolean
288286 return StringUtils .join (modulesList , "," );
289287 }
290288
291- private String [] additionalModulePathsToParams (List <File > additionalModulePaths ) {
292-
293- List <String > additionalPaths = new ArrayList <>();
294-
295- additionalModulePaths
296- .stream ()
297- .filter (path -> {
298- if (path .exists ()) return true ;
299- Logger .warn ("Additional module path not found: " + path );
300- return false ;
301- })
302- .forEach (path -> {
303- additionalPaths .add ("--module-path" );
304- additionalPaths .add (path .toString ());
305- });
306-
307- return additionalPaths .toArray (new String [0 ]);
289+ private List <File > getModulePaths (File jarFile , File libsFolder , List <File > additionalModulePaths ) {
290+ List <File > modulePaths = new ArrayList <>();
291+ modulePaths .add (jarFile );
292+ modulePaths .add (libsFolder );
293+ modulePaths .addAll (
294+ additionalModulePaths
295+ .stream ()
296+ .filter (path -> {
297+ if (path .exists ()) return true ;
298+ Logger .warn ("Additional module path not found: " + path );
299+ return false ;
300+ })
301+ .collect (Collectors .toList ())
302+ );
303+ return modulePaths ;
308304 }
309305
310306}
0 commit comments