classpath

This commit is contained in:
dzj 2024-02-22 12:10:38 +08:00
parent e7dd90e301
commit 31b8a17e65
6 changed files with 77 additions and 49 deletions

View File

@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>net.risesoft.demo</groupId>
<artifactId>demo-car</artifactId>
<version>1.0</version>
<build>
<plugins>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer>
<mainClass>net.risesoft.demo.Example</mainClass>
</transformer>
<transformer>
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer>
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

1
java-run-order-audi.bat Normal file
View File

@ -0,0 +1 @@
java -cp "./target/*;./target/lib/demo-audi-1.0.jar;;./target/lib/demo-merceds-1.0.jar" net.risesoft.demo.Example

View File

@ -0,0 +1 @@
java -cp "./target/*;./target/lib/demo-merceds-1.0.jar;./target/lib/demo-audi-1.0.jar;" net.risesoft.demo.Example

1
java-run.bat Normal file
View File

@ -0,0 +1 @@
java -cp "./target/*;./target/lib/*" net.risesoft.demo.Example

62
pom.xml
View File

@ -29,9 +29,7 @@
<manifest>
<mainClass>net.risesoft.demo.Example</mainClass>
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
<!-- 将项目的依赖信息添加到 MANIFEST.MF 中 -->
<addClasspath>true</addClasspath>
<!-- 将依赖的存放位置添加到 MANIFEST.MF 中-->
<addClasspath>flase</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
</manifest>
<manifestEntries>
@ -58,10 +56,10 @@
</executions>
</plugin>
<plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.5.5</version>
<version>3.6.0</version>
<configuration>
<archive>
<manifest>
@ -81,34 +79,34 @@
</goals>
</execution>
</executions>
</plugin>
</plugin>-->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.4.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>net.risesoft.demo.Example</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
<!--<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.5.2</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<transformers>
<transformer implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<mainClass>net.risesoft.demo.Example</mainClass>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.handlers</resource>
</transformer>
<transformer implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>META-INF/spring.schemas</resource>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>-->
</plugins>
</build>
</project>

View File

@ -1,28 +1,19 @@
package net.risesoft.demo;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
public class Example {
public static void main(String[] args) {
Car car = new Car();
System.out.println("当前车辆版本: " + car.getVersion());
System.out.println("当前车辆品牌: ");
System.out.println(car.getName());
System.out.println("当前车辆版本: ");
System.out.println(car.getVersion());
System.out.println("当前 jar 包路径 ");
System.out.println(car.getClass().getProtectionDomain().getCodeSource().getLocation().getPath());
Method[] declaredMethods = car.getClass().getDeclaredMethods();
for (Method declaredMethod : declaredMethods) {
System.out.println("------------------");
System.out.println("method name: " + declaredMethod.getName());
List<String> collect = Arrays.stream(declaredMethod.getParameterTypes()).map(Class::getName).collect(Collectors
.toList());
if (!collect.isEmpty()) {
System.out.println("parameter type : " + collect);
}
System.out.println("------------------");
}
}
}