Override class in java

后端 未结 1 1643
没有蜡笔的小新
没有蜡笔的小新 2021-01-17 10:28

Assume I have a project K

K depends lib.jar

In lib.jar , there is a class named x.y.z.Foo

相关标签:
1条回答
  • 2021-01-17 10:52

    Java class loading behaviour in a standalone application (at least with no custom classloaders) is stable. Make sure that your k.jar (or path) comes before lib.jar in -cp java arg

    java -cp k.jar lib.jar ...
    

    or add dependencies to /META-INF/MANIFEST.MF of your K project as

    ...
    Class-Path: lib1.jar lib2.jar
    ...
    

    and run

    java -jar k.jar
    

    k.jar classes will be loaded first

    in Maven it is

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-jar-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
             ...
    
    0 讨论(0)
提交回复
热议问题