解决了jar包无法扫描问题
This commit is contained in:
@@ -1,24 +0,0 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
|
||||||
<module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
|
|
||||||
<component name="FacetManager">
|
|
||||||
<facet type="Spring" name="Spring">
|
|
||||||
<configuration />
|
|
||||||
</facet>
|
|
||||||
</component>
|
|
||||||
<component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_8">
|
|
||||||
<output url="file://$MODULE_DIR$/target/classes" />
|
|
||||||
<output-test url="file://$MODULE_DIR$/target/test-classes" />
|
|
||||||
<content url="file://$MODULE_DIR$">
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
|
|
||||||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
|
||||||
<excludeFolder url="file://$MODULE_DIR$/target" />
|
|
||||||
</content>
|
|
||||||
<orderEntry type="inheritedJdk" />
|
|
||||||
<orderEntry type="sourceFolder" forTests="false" />
|
|
||||||
<orderEntry type="library" name="Maven: cglib:cglib:3.1" level="project" />
|
|
||||||
<orderEntry type="library" name="Maven: org.ow2.asm:asm:4.2" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
|
|
||||||
<orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
|
|
||||||
</component>
|
|
||||||
</module>
|
|
||||||
102
pom.xml
102
pom.xml
@@ -6,7 +6,7 @@
|
|||||||
<name>javafx-plus</name>
|
<name>javafx-plus</name>
|
||||||
<groupId>com.gitee.Biubiuyuyu</groupId>
|
<groupId>com.gitee.Biubiuyuyu</groupId>
|
||||||
<artifactId>javafx-plus</artifactId>
|
<artifactId>javafx-plus</artifactId>
|
||||||
<version>1.0.0-RELEASE</version>
|
<version>1.1.1-RELEASE</version>
|
||||||
<packaging>jar</packaging>
|
<packaging>jar</packaging>
|
||||||
|
|
||||||
|
|
||||||
@@ -78,56 +78,56 @@
|
|||||||
|
|
||||||
<profiles>
|
<profiles>
|
||||||
<profile>
|
<profile>
|
||||||
<id>release</id>
|
<id>release</id>
|
||||||
<build>
|
<build>
|
||||||
<plugins>
|
<plugins>
|
||||||
<!-- Source -->
|
<!-- Source -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-source-plugin</artifactId>
|
<artifactId>maven-source-plugin</artifactId>
|
||||||
<version>2.2.1</version>
|
<version>2.2.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>jar-no-fork</goal>
|
<goal>jar-no-fork</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- Javadoc -->
|
<!-- Javadoc -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-javadoc-plugin</artifactId>
|
<artifactId>maven-javadoc-plugin</artifactId>
|
||||||
<version>2.9.1</version>
|
<version>2.9.1</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<phase>package</phase>
|
<phase>package</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>jar</goal>
|
<goal>jar</goal>
|
||||||
</goals>
|
</goals>
|
||||||
<configuration>
|
<configuration>
|
||||||
<additionalparam>-Xdoclint:none</additionalparam>
|
<additionalparam>-Xdoclint:none</additionalparam>
|
||||||
</configuration>
|
</configuration>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
<!-- GPG -->
|
<!-- GPG -->
|
||||||
<plugin>
|
<plugin>
|
||||||
<groupId>org.apache.maven.plugins</groupId>
|
<groupId>org.apache.maven.plugins</groupId>
|
||||||
<artifactId>maven-gpg-plugin</artifactId>
|
<artifactId>maven-gpg-plugin</artifactId>
|
||||||
<version>1.5</version>
|
<version>1.5</version>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>sign-artifacts</id>
|
<id>sign-artifacts</id>
|
||||||
<phase>verify</phase>
|
<phase>verify</phase>
|
||||||
<goals>
|
<goals>
|
||||||
<goal>sign</goal>
|
<goal>sign</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</profile>
|
</profile>
|
||||||
</profiles>
|
</profiles>
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
package cn.edu.scau.biubiusuisui.utils;
|
package cn.edu.scau.biubiusuisui.utils;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
import java.lang.annotation.Annotation;
|
import java.lang.annotation.Annotation;
|
||||||
import java.lang.reflect.Field;
|
import java.lang.reflect.Field;
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.Arrays;
|
import java.util.*;
|
||||||
import java.util.LinkedList;
|
import java.util.jar.JarEntry;
|
||||||
import java.util.List;
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @Author jack
|
* @Author jack
|
||||||
@@ -24,12 +25,16 @@ public class ClassUtils {
|
|||||||
URL url = classLoader.getResource(splashPath);
|
URL url = classLoader.getResource(splashPath);
|
||||||
String filePath = StringUtils.getRootPath(url);
|
String filePath = StringUtils.getRootPath(url);
|
||||||
List<String> names = null;
|
List<String> names = null;
|
||||||
names = readFromDirectory(filePath);
|
if(filePath.endsWith("jar")){
|
||||||
for (String name : names) {
|
nameList = readFromJarDirectory(filePath,base);
|
||||||
if (isClassFile(name)) {
|
}else {
|
||||||
nameList.add(toFullyQualifiedName(name, base));
|
names = readFromDirectory(filePath);
|
||||||
} else if (isDirectory(name)) {
|
for (String name : names) {
|
||||||
nameList = getAllFXControllerClassName(base + "." + name, nameList);
|
if (isClassFile(name)) {
|
||||||
|
nameList.add(toFullyQualifiedName(name, base));
|
||||||
|
} else if (isDirectory(name)) {
|
||||||
|
nameList = getAllFXControllerClassName(base + "." + name, nameList);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return nameList;
|
return nameList;
|
||||||
@@ -55,6 +60,37 @@ public class ClassUtils {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private static List<String> readFromDirectory(String path) {
|
private static List<String> readFromDirectory(String path) {
|
||||||
|
if (path == null) return null;
|
||||||
|
return readFromFileDirectory(path);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> readFromJarDirectory(String path,String packageName) {
|
||||||
|
JarFile jarFile = null;
|
||||||
|
try {
|
||||||
|
jarFile = new JarFile(path);
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Enumeration<JarEntry> entrys = jarFile.entries();
|
||||||
|
List<String> classNames = new ArrayList<>();
|
||||||
|
while (entrys.hasMoreElements()) {
|
||||||
|
JarEntry jarEntry = entrys.nextElement();
|
||||||
|
if(!jarEntry.getName().endsWith(".class"))continue;
|
||||||
|
int packageNameIndex = jarEntry.getName().indexOf("/");
|
||||||
|
if("".equals(packageName)){
|
||||||
|
classNames.add(jarEntry.getName());
|
||||||
|
}else {
|
||||||
|
if(packageNameIndex == -1) continue;
|
||||||
|
String baseName = jarEntry.getName().substring(0, packageNameIndex);
|
||||||
|
if (baseName.equals(packageName)) {
|
||||||
|
classNames.add(StringUtils.trimExtension(jarEntry.getName()).replaceAll("/","."));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return classNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static List<String> readFromFileDirectory(String path) {
|
||||||
File file = new File(path);
|
File file = new File(path);
|
||||||
String[] names = file.list();
|
String[] names = file.list();
|
||||||
if (null == names) {
|
if (null == names) {
|
||||||
@@ -107,8 +143,6 @@ public class ClassUtils {
|
|||||||
Field[] fields = clazz.getDeclaredFields();
|
Field[] fields = clazz.getDeclaredFields();
|
||||||
for (Field field : fields) {
|
for (Field field : fields) {
|
||||||
field.setAccessible(true);
|
field.setAccessible(true);
|
||||||
|
|
||||||
// Field field1 = targetClass.getField(field.getName());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,29 @@
|
|||||||
|
package cn.edu.scau.biubiusuisui.utils;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Enumeration;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.jar.JarEntry;
|
||||||
|
import java.util.jar.JarFile;
|
||||||
|
|
||||||
|
public class ClassUtilsTest {
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JarFile jarFile = null;
|
||||||
|
try {
|
||||||
|
jarFile = new JarFile("/Users/Jack/test.jar");
|
||||||
|
} catch (IOException e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
Enumeration<JarEntry> entrys = jarFile.entries();
|
||||||
|
List<String> classNames = new ArrayList<>();
|
||||||
|
while (entrys.hasMoreElements()) {
|
||||||
|
JarEntry jarEntry = entrys.nextElement();
|
||||||
|
classNames.add(jarEntry.getName());
|
||||||
|
}
|
||||||
|
classNames.forEach(System.out::println);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user