我正在尝试运行由Maven打包的jar文件。运行java -jar target/java-prac-1.0-SNAPSHOT.jar
时,得到以下输出:
no main manifest attribute, in target/java-prac-1.0-SNAPSHOT.jar
pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>localdomain.localhost.tutorial</groupId>
<artifactId>java-prac</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies></dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
<manifest>
<mainClass>localdomain.localhost.tutorial.Main</mainClass>
</manifest>
</configuration>
</plugin>
</plugins>
</build>
</project>
我的MANIFEST.MF文件看起来像
Manifest-Version: 1.0
Main-Class: localdomain.localhost.tutorial.Main
有趣的是,当我运行ls target/classes
时,列出了'META-INF /'文件夹。所以该文件似乎在jar文件中,java出于某种原因找不到它。
答案 0 :(得分:3)
pom.xml
文件中 <plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.6</source>
<target>1.6</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<!--add you main class-->
<mainClass>cn.lonecloud.RefDemo</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy</id>
<phase>install</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
mvn compile package
java -jar target/java-prac-1.0-SNAPSHOT.jar
答案 1 :(得分:0)
尝试将以下节点添加到pom.xml文件:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>