com.javonet.core.analyzer.InterfaceAnalyzer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of javonet-java-sdk Show documentation
Show all versions of javonet-java-sdk Show documentation
Javonet allows you to reference and use modules or packages written in (Java/Kotlin/Groovy/Clojure, C#/VB.NET, Ruby, Perl, Python, JavaScript/TypeScript) like they were created in your technology.
It works on Linux/Windows and MacOS for applications created in JVM, CLR/Netcore, Perl, Python, Ruby, NodeJS, C++ or GoLang and gives you unparalleled freedom and flexibility with native performance in building your mixed-technologies products.
Let it be accessing best AI or cryptography libraries, devices SDKs, legacy client modules, internal custom packages or anything from public repositories available on NPM, Nuget, PyPI, Maven/Gradle, RubyGems or GitHub. Get free from programming languages barriers today!
For more information check out our guides at https://www.javonet.com/guides/v2/
package com.javonet.core.analyzer;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.*;
import java.util.jar.JarEntry;
import java.util.jar.JarFile;
public class InterfaceAnalyzer {
public static LinkedList > returnClassesFromJar(String jarPath) {
File f = new File(jarPath);
LinkedList> classQueue = new LinkedList <>();
if (f.exists()) {
try {
JarFile jarFile = new JarFile(jarPath);
Enumeration e = jarFile.entries();
URL[] urls = {new URL("jar:file:" + jarPath + "!/")};
URLClassLoader cl = URLClassLoader.newInstance(urls);
while (e.hasMoreElements()) {
JarEntry je = e.nextElement();
if (je.isDirectory() || !je.getName().endsWith(".class") || je.getName().contains("$")) {
continue;
}
// -6 because of .class
String className = je.getName().substring(0, je.getName().length() - 6);
className = className.replace('/', '.');
Class c = cl.loadClass(className);
classQueue.add(c);
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
return classQueue;
} else {
throw new RuntimeException("Jar does not exists: " + jarPath);
}
}
}