【MANIFEST.MF】 文件到底是个啥?

mac2024-03-12  27

1  Executable JAR files

2 Define a main class in your JAR's MANIFEST.MF file that defines the executable class. (MANIFEST.MF is the file that Maven generates when packaging your application.)

3 Find all of the libraries on which your project depends.

4 Include those libraries in your MANIFEST.MF file so that your application classes can find them.

MANIFEST.MF is the file that Maven generates when packaging your application.

 

举例:

 MANIFEST.MF

Manifest-Version: 1.0

Premain-Class: com.geekcap.openapm.jvm.agent.Agent

Can-Redefine-Classes: true

Can-Retransform-Classes: true

Can-Set-Native-Method-Prefix: true

 

<plugin>

    <groupId>org.apache.maven.plugins</groupId>

    <artifactId>maven-jar-plugin</artifactId>

    <configuration>

        <archive>

            <manifestFile>

              src/main/resources/META-INF/MANIFEST.MF

            </manifestFile>

            <manifest>

                <addClasspath>true</addClasspath>

                <classpathPrefix>lib/</classpathPrefix>

                <mainClass>

                  com.geekcap.openapm.ui.PerformanceAnalyzer

                </mainClass>

            </manifest>

        </archive>

    </configuration>

</plugin>

 

This is an interesting example because it both defines a Premain-Class that allows the JAR file to work as a Java agent and has a mainClass that allows it to run as an executable JAR file. In this particular example, I've used OpenAPM (a code tracing tool that I built) to define code tracing that will be recorded by the Java agent and a user interface, which will facilitate analysis of recorded traces. In short, the example shows the power of combining an explicit manifest file with dynamic modifications.

 

5 springboot 的Manifest

Manifest-Version: 1.0

Implementation-Title: myproject

Implementation-Version: 0.0.1-SNAPSHOT

Built-By: jenkins

Implementation-Vendor-Id: com.myproject

Spring-Boot-Version: 2.0.6.RELEASE

Main-Class: org.springframework.boot.loader.JarLauncher

Start-Class: com.myproject.VApplication

Spring-Boot-Classes: BOOT-INF/classes/

Spring-Boot-Lib: BOOT-INF/lib/

Created-By: Apache Maven 3.5.2

Build-Jdk: 1.8.0_151

Implementation-URL: https://projects.spring.io/spring-boot/#/spring-bo

ot-starter-parent/myproject

 

6 依赖树

mvn dependency:tree

 

7 环境选择

<build>

    <plugins>

        <plugin>

            <groupId>net.fpic</groupId>

            <artifactId>tomcat-deployer-plugin</artifactId>

            <version>1.0-SNAPSHOT</version>

            <executions>

                <execution>

                    <id>pos</id>

                    <phase>install</phase>

                    <goals>

                        <goal>deploy</goal>

                    </goals>

                    <configuration>

                        <host>${deploymentManagerRestHost}</host>

                        <port>${deploymentManagerRestPort}</port>

                        <username>${deploymentManagerRestUsername}</username>

                        <password>${deploymentManagerRestPassword}</password>

                        <artifactSource>

                            address/target/addressservice.war

                        </artifactSource>

                    </configuration>

                </execution>

            </executions>

        </plugin>

    </plugins>

</build>

 

<profiles>

    <profile>

        <id>dev</id>

        <properties>

            <deploymentManagerRestHost>10.50.50.52</deploymentManagerRestHost>

            <deploymentManagerRestPort>58090</deploymentManagerRestPort>

            <deploymentManagerRestUsername>myusername</deploymentManagerRestUsername>

            <deploymentManagerRestPassword>mypassword</deploymentManagerRestPassword>

        </properties>

    </profile>

    <profile>

        <id>qa</id>

        <properties>

            <deploymentManagerRestHost>10.50.50.50</deploymentManagerRestHost>

            <deploymentManagerRestPort>58090</deploymentManagerRestPort>

            <deploymentManagerRestUsername>myotherusername</deploymentManagerRestUsername>

            <deploymentManagerRestPassword>myotherpassword</deploymentManagerRestPassword>

        </properties>

    </profile>

</profiles>

mvn -Pdev clean install

 

8 自定义maven插件:

https://www.ibm.com/developerworks/java/library/j-5things13/index.html?ca=drs-

 
最新回复(0)