My project structure is as follows: ---Detail-RASP---src
My maven pom file:
<?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>com.briar</groupId>
<artifactId>Detail-RASP</artifactId>
<name>Detail-RASP</name>
<version>1.0-SNAPSHOT</version>
<build>
<finalName>Detail-RASP-Agent</finalName>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven.compiler.version}</version>
<configuration>
<source>${jdk.version}</source>
<target>${jdk.version}</target>
<encoding>${maven.compiler.encoding}</encoding>
<skip>true</skip>
<compilerArguments>
<bootclasspath>${java.home}/lib/rt.jar</bootclasspath>
</compilerArguments>
</configuration>
</plugin>
<plugin>
<artifactId>maven-shade-plugin</artifactId>
<version>3.1.1</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<filters>
<filter>
<artifact>*:*</artifact>
<excludes>
<exclude>META-INF/maven/</exclude>
</excludes>
</filter>
</filters>
<transformers>
<transformer>
<manifestEntries>
<Premain-Class>com.briar.Agent</Premain-Class>
<Agent-Class>com.briar.Agent</Agent-Class>
<Can-Redefine-Classes>true</Can-Redefine-Classes>
<Can-Retransform-Classes>true</Can-Retransform-Classes>
<Main-Class>com.briar.Agent</Main-Class>
<Class-Path>. ${java.home}\..\lib\tools.jar ${build.finalName}.jar</Class-Path>
<Can-Set-Native-Method-Prefix>true</Can-Set-Native-Method-Prefix>
</manifestEntries>
</transformer>
</transformers>
<relocations>
<relocation>
<pattern>org.yaml</pattern>
<shadedPattern>com.briar.org.yaml</shadedPattern>
</relocation>
<relocation>
<pattern>javassist</pattern>
<shadedPattern>com.briar.org.javassist</shadedPattern>
</relocation>
</relocations>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>${tools.version}</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
</dependencies>
<properties>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<jdk.version>8</jdk.version>
<maven.compiler.encoding>UTF-8</maven.compiler.encoding>
<tools.version>1.8.0</tools.version>
<maven.compiler.version>3.1</maven.compiler.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<junit.version>3.8.1</junit.version>
</properties>
</project>
I click clean and package,then "cd" to target, java -jar Detail-RASP-Agent.jar,I get the error;
Error: can not find or load main class com.briar.Agent
I check the the MANIFEST.MF file and I see that Main-Class has been added.But still there is this error.
I tried adding . to the classpath of MANIFEST.MF, but it doesn't work.At the same time, I checked the entire project and the MANIFEST.MF file and there is no problem
I add -Xdiag parameter to see the details, the details are as follows:
Error: can not find or load main class com.briar.Agent
java.lang.ClassNotFoundException: com.briar.Agent
at java.net.URLClassLoader.findClass(URLClassLoader.java:387)
at java.lang.ClassLoader.loadClass(ClassLoader.java:418)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:355)
at java.lang.ClassLoader.loadClass(ClassLoader.java:351)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:601)