1

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)

5
  • 1
    Check the class has been added into the jar after compile, if it is compiled packaged and inserted among other jars, check the contents has compiled and been inserted in such a process also. Commented Feb 22, 2023 at 4:41
  • If a jar has a main class, it must be specified according rules syntax of MANIFEST.MF for a main class. Commented Feb 22, 2023 at 4:44
  • In rare instances, file permission of the jar and contents may need to be set executable for the jar and contents to the OS properties tab Commented Feb 22, 2023 at 4:45
  • I have checked the compiled jar package, he does exist in the main class Commented Feb 22, 2023 at 13:51
  • At the same time, I also see that the MANIFEST.MF file in the jar package specifies the Main-Class Commented Feb 22, 2023 at 13:52

2 Answers 2

0

I'd say you are issuing the wrong command syntax on your terminal or prompt. First problem, there is no -jar flag for the "java" command If you type onto your console the command java -h you will be given all the -flags you can use with the command java. Second to put a package into a jar , create a jar you use the "jar" command

To run an executable jar that has a main class, open a prompt or terminal into the "working folder" the jar is inside.

issue the command "example"

cd /home/myprojects/jarprojects/proj1

java -64 Detail-RASP-Agent.jar

or

java -64 -classpath "/home/myprojects/jarprojects/proj1" Detail-RASP-Agent.jar

or

java -64 -cp "/home/myprojects/jarprojects/proj1" Detail-RASP-Agent.jar

Sign up to request clarification or add additional context in comments.

Comments

0

I know what's wrong.My manifest.mf file is wrong.After removing the classpath attribute, it runs successfully.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.