Java – the executable jar ignores its own class path attribute

I use https://stackoverflow.com/a/5893391/14731 Adds an arbitrary entry to the class path attribute using the directive in This is my manifest MF file:

Manifest-Version: 1.0
Class-Path: jace-runtime.jar
Main-Class: org.jace.examples.Test

I defined org jace. examples. Test is as follows:

public class Test
{
    public static void main(String[] args)
    {
        System.out.println("classpath: " + System.getProperty("java.class.path"));
        System.out.println("PeerExample: " + Class.forName("org.jace.util.ShutdownHook"));
    }
}

Where org jace. util. Shutdown hook is in Jace - runtime Jar When I call Java jar peer_ example1. Jar, I get the following output:

classpath:peer_ example1. Exception "main" in jar thread Java lang.ClassNotFoundException:org. jace. util. ShutdownHook

In other words, Java adds the executable jar file to the classpath, but ignores class - path If I call Java - CP Jace runtime jar; peer_ example1. jar org. jace. examples. Test I get the expected output:

classpath:jace-runtime. jar; peer_ example1. jar

Any ideas?

Solution

Answer my own question:

>Add any entry to the class path itself This problem occurs when you enable jar indexing using the following command:

<configuration>
  <archive>
    <index>true</index>
  </archive>
</configuration>

Maven will be from meta inf / index Omit your entry from list. > When you use jars at runtime, Java looks for index List instead of manifest MF. > Because index Input is missing from list, so the class loader will not find them regardless of the list

A simple solution is to disable jar indexing I don't know how to inject arbitrary class path and enable indexing

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>