Tag Archives: no main manifest attribute

No main manifest attribute when running Java – jar

 

Reason: the meta-inf/manifest.mf file in the jar package is missing the key value pair of “main class”

terms of settlement:

<build>
<pluginManagement> 
<plugins>
<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-jar-plugin</artifactId>
    <configuration>
        <archive>
            <manifest>
                <mainClass>com.u1w2.sla.App</mainClass>
            </manifest>
        </archive>
    </configuration>
</plugin>

  

logo

 

Run jar file under Linux system, prompt: no main manifest attribute, in xxx.jar [How to Solve]

When executing Java – jar xxx.jar com.helloworld under Linux system, you will often be prompted: no main manifest attribute, in xxx.jar

The reasons are as follows:

Normally, when Java is packaged as a jar package, you need to specify the main class item in manifest.mf to find the corresponding main class when running Java – jar xxx.jar. Because – jar means that the following jar package has a main class to run independently, you need to specify this class when you package it into a jar package

If you want to specify the class you want to run at runtime, you should use – CP/– classpath to specify it. The command is as follows:
for example: Java – CP xxx.jar com.helloworld

Packaging can also be specified in the following way to directly run the jar file Java – jar XXX. Jar

<plugins>
    <!-- When packaging the jar file, configure the manifest file and add the jar dependencies of the lib package -->
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        <version>2.6</version>
        <configuration>
            <classesDirectory>target/classes/</classesDirectory>
            <archive>
                <manifest>
                    <mainClass>com.alibaba.dubbo.container.Main</mainClass>
                    <!-- Timestamped version not recorded in MANIFEST.MF file when packing -->
                    <useUniqueVersions>false</useUniqueVersions>
                    <addClasspath>true</addClasspath>
                    <classpathPrefix>crm-lib/</classpathPrefix>
                </manifest>
                <manifestEntries>
                    <Class-Path>.</Class-Path>
                </manifestEntries>
            </archive>
        </configuration>
    </plugin>
    <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-dependency-plugin</artifactId>
        <executions>
            <execution>
                <id>copy-dependencies</id>
                <phase>package</phase>
                <goals>
                    <goal>copy-dependencies</goal>
                </goals>
                <configuration>
                    <type>jar</type>
                    <includeTypes>jar</includeTypes>
                    <outputDirectory>
                        ${project.build.directory}/crm-lib
                    </outputDirectory>
                </configuration>
            </execution>
        </executions>
    </plugin>
</plugins>

[Solved] The updated version of springboot causes no main manifest attribute

Recently, the springboot version was upgraded to 2.1.6. Release , and the springcloud version was upgraded to Greenwich. Sr2 when pushing the remote image to Ranger, it has been unable to start. The log shows no main manifest attribute, in/APP. Jar

Packaging tools have not changed, no problem before, and then click the mouse packaging plug-in found no version number

  <plugin>
	  <groupId>org.springframework.boot</groupId>
	  <artifactId>spring-boot-maven-plugin</artifactId>
	  <!--Be sure to match the springboot version number, because the new version of springboot no longer sets the dependencies of this plugin-->
	  <version>${spring-boot.version}</version>
	  <executions>
		  <execution>
			  <goals>
			  	<goal>repackage</goal>
			  </goals>
		  </execution>
	  </executions>
  </plugin>

Add in the version number and it’s done

Gradle Packages Springboot Error: no main manifest attribute, in ./build/libs/scaffold-1.0-SNAPSHOT.jar

The reason for the error is that the build. Gradle file is missing the package plug-in for gradle

buildscript {
    dependencies {
        classpath("org.springframework.boot:spring-boot-gradle-plugin:2.2.6.RELEASE")
    }
}

plugins {
    id 'java'
}


apply plugin: 'java'
apply plugin: 'org.springframework.boot'

group 'com.guanguan.docker'
version '1.0-SNAPSHOT'

sourceCompatibility = 1.8

repositories {
    mavenCentral()
}

dependencies {
    compile('org.springframework.boot:spring-boot-starter-web:2.2.6.RELEASE')
    testCompile group: 'junit', name: 'junit', version: '4.12'
}

Just patch spring-boot-gradle-plugin.

Verification.

./gradlew build

$ java -jar ./build/libs/scaffold-1.0-SNAPSHOT.jar

Then you can see the program get up.