@@ -94,7 +94,7 @@ private static List<File> processPackages(final boolean checkUpdates, final int
9494 Map <String , String > newVersions = new HashMap <>();
9595
9696 for (Dependency dependency : packages .packages ()) {
97- File jar = handleDependency (dependency , installedVersions , newVersions , packages .destination ());
97+ File jar = handleDependency (dependency , installedVersions , newVersions , dependency . getDestination ( packages .destination () ));
9898 if (jar != null ) results .add (jar );
9999 }
100100
@@ -203,54 +203,45 @@ private static void deleteUnusedDependencies(List<File> existingJars, Set<String
203203 });
204204 }
205205
206- public static String findMainClass (List <File > files ) {
207- for (File file : files ) {
208- if (!file .getName ().endsWith (".jar" )) continue ;
209-
210- try (ZipInputStream zis = new ZipInputStream (new FileInputStream (file ));
211- BufferedReader reader = new BufferedReader (new InputStreamReader (zis ))) {
212- ZipEntry entry ;
213- while ((entry = zis .getNextEntry ()) != null ) {
214- if (SERVICE_PATH .equals (entry .getName ())) {
215- org .mangorage .installer .core .LogUtil .println ("Found " + SERVICE_PATH + " in " + file .getName ());
216- return reader .lines ().collect (Collectors .joining ("\n " ));
217- }
206+ public static String findMainClass (File file ) {
207+ try (ZipInputStream zis = new ZipInputStream (new FileInputStream (file ));
208+ BufferedReader reader = new BufferedReader (new InputStreamReader (zis ))) {
209+ ZipEntry entry ;
210+ while ((entry = zis .getNextEntry ()) != null ) {
211+ if (SERVICE_PATH .equals (entry .getName ())) {
212+ org .mangorage .installer .core .LogUtil .println ("Found " + SERVICE_PATH + " in " + file .getName ());
213+ return reader .lines ().collect (Collectors .joining ("\n " ));
218214 }
219- } catch (IOException e ) {
220- throw new RuntimeException ("Error processing JAR file: " + file .getName (), e );
221215 }
216+ } catch (IOException e ) {
217+ throw new RuntimeException ("Error processing JAR file: " + file .getName (), e );
222218 }
223219 return "" ;
224220 }
225221
226222 public static void launchJar (List <File > jars , String [] args ) {
227223 org .mangorage .installer .core .LogUtil .println ("Attempting to launch...." );
228- String mainClass = findMainClass (jars ).strip ();
224+ String mainClass = findMainClass (new File ("boot/boot.jar" ));
225+
229226 if (mainClass .isEmpty ()) {
230227 org .mangorage .installer .core .LogUtil .println ("Could not find Valid Launch File from List of Jars..." );
231228 return ;
232229 }
233230
234- URL [] urls = jars .stream ()
235- .map (File ::toURI )
236- .map (uri -> {
237- try {
238- return uri .toURL ();
239- } catch (MalformedURLException e ) {
240- throw new RuntimeException ("Invalid JAR file URL: " + uri , e );
241- }
242- })
243- .toArray (URL []::new );
244-
245- try (URLClassLoader cl = new URLClassLoader (urls , Thread .currentThread ().getContextClassLoader ())) {
246- Thread .currentThread ().setContextClassLoader (cl );
247- Class <?> clazz = Class .forName (mainClass , true , cl );
248- Method method = clazz .getDeclaredMethod ("main" , String [].class );
249- method .invoke (null , (Object ) args );
250- } catch (IOException | ReflectiveOperationException e ) {
251- throw new RuntimeException ("Failed to launch the application" , e );
252- } finally {
253- Thread .currentThread ().setContextClassLoader (ClassLoader .getSystemClassLoader ());
231+ try {
232+ URL bootJar = new File ("boot/boot.jar" ).toURI ().toURL ();
233+ try (URLClassLoader cl = new URLClassLoader (new URL []{bootJar }, Thread .currentThread ().getContextClassLoader ())) {
234+ Thread .currentThread ().setContextClassLoader (cl );
235+ Class <?> clazz = Class .forName (mainClass , true , cl );
236+ Method method = clazz .getDeclaredMethod ("main" , String [].class );
237+ method .invoke (null , (Object ) args );
238+ } catch (IOException | ReflectiveOperationException e ) {
239+ throw new RuntimeException ("Failed to launch the application" , e );
240+ } finally {
241+ Thread .currentThread ().setContextClassLoader (ClassLoader .getSystemClassLoader ());
242+ }
243+ } catch (Throwable e ) {
244+ throw new IllegalStateException ("Failed to launch..." , e );
254245 }
255246 }
256247
0 commit comments