@@ -499,9 +499,62 @@ private List<String> getProcessCommandsWithoutArgs() throws IOException, URISynt
499499 return command ;
500500 }
501501
502+ public static List <String > getClassLocations (Class <?>... classes ) {
503+ List <String > locations = new ArrayList <>();
504+ for (Class <?> clazz : classes ) {
505+ String location = getClassLocation (clazz );
506+ if (location != null && !locations .contains (location )) {
507+ locations .add (location );
508+ }
509+ }
510+ return locations ;
511+ }
512+
513+ private static String getClassLocation (Class <?> clazz ) {
514+ try {
515+ String classResource = clazz .getName ().replace ('.' , '/' ) + ".class" ;
516+ URL location = clazz .getClassLoader ().getResource (classResource );
517+ System .out .println (location );
518+
519+ if (location != null ) {
520+ String path = extractPath (location );
521+ System .out .println (path );
522+ if (path != null ) {
523+ File file = new File (path );
524+ if (file .isFile ()) {
525+ // If it's a JAR file
526+ return file .getAbsolutePath ();
527+ } else {
528+ // If it's a directory (for .class files)
529+ return file .getParent ();
530+ }
531+ }
532+ }
533+ } catch (UnsupportedEncodingException e ) {
534+ e .printStackTrace ();
535+ }
536+ return null ;
537+ }
538+
539+ private static String extractPath (URL url ) throws UnsupportedEncodingException {
540+ String path = url .getPath ();
541+ if (path .startsWith ("file:" )) {
542+ path = path .substring (5 );
543+ }
544+ path = URLDecoder .decode (path , "UTF-8" );
545+
546+ if (path .contains (".jar!" )) {
547+ path = path .substring (0 , path .lastIndexOf (".jar!" ) + 4 );
548+ }
549+
550+ return path ;
551+ }
552+
502553 private static String getCurrentClasspath () throws UnsupportedEncodingException {
503554
504555 String modelrunnerPath = getPathFromClass (DeepLearningEngineInterface .class );
556+ getClassLocations (DeepLearningEngineInterface .class );
557+ System .out .println ("AAAAAAAAAAAAAAAAAAAAAAAAAAAAA" );
505558 String imglib2Path = getPathFromClass (NativeType .class );
506559 String gsonPath = getPathFromClass (Gson .class );
507560 String jnaPath = getPathFromClass (com .sun .jna .Library .class );
0 commit comments