Compile the class file into a jar package in Java and run the hint without the main manifest property

Source: Internet
Author: User

Compile the class file into a jar package in Java and run the hint without the main manifest property

Maven project Build Jar runtime Prompt "No master manifest attribute"

A new MAVEN project has been created, mvn compile and a mvn package jar file has been formed, and then the target Java -jar xxx.jar "Xxx.jar no master manifest attribute" error message appears when running the jar package directly to the directory.
According to my experience, there is no way to find the entry class (that is main , the class where the function is), pom.xml plus the configuration of the Ingress class in it! For the first time, just use MAVEN to package the jar and record it.

About the executable program (you need to specify a main class) to hit the jar package is not so convenient, we need to consider the following questions:

    • The configuration file needs to be hit into the jar package;
    • The main entry class needs to be specified;
    • The third-party library on which it relies is also required to enter the jar package;
      • Only if the above three points are met, we can successfully execute the program directly using the Java-jar Swiftonrsa-1.0.0.jar command.
      • 2.1 Configuration file packaging does not require additional attention as long as the configuration files on which your project depends follow the MAVEN specification lil bit location (src/main/resources), the packaged jar package will pack them together:
      • But the well-punched jar package does not specify either the main entry class or the dependency package, and we run it:
        • Tip "There is no main manifest attribute in Swiftonrsa-1.0.0.jar", we look at the MANIFEST in the Meta-inf directory under the JAR package. MF, the contents are as follows:
          manifest-version:1.0
          Built-by:defonds
          build-jdk:1.7.0_67
          Created-by:apache Maven 3.2.3
          Archiver-version:plexus archiver
          It is true that the main entry class is not indicated.
          2.2 Maven-assembly-plugin plug-in so we introduced the Maven-assembly-plugin plug-in, pom.xml add the following code:
          • It is true that the main entry class is not indicated.
            2.2 Maven-assembly-plugin plug-in so we introduced the Maven-assembly-plugin plug-in, pom.xml add the following code:
            [HTML]View PlainCopyprint?
            1. <build>
            2. <plugins>
            3. <plugin>
            4. <artifactid>maven-assembly-plugin</artifactid>
            5. <configuration>
            6. <Appendassemblyid>false</appendassemblyid>
            7. <descriptorrefs>
            8. <descriptorref>jar-with-dependencies</descriptorref>
            9. </descriptorrefs>
            10. <archive>

Compile the class file into a jar package in Java and run the hint without the main manifest property

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.