Si vous créez un projet Maven avec les valeurs par défaut dans Eclipse (STS pour être exact), le POM ressemblera à ceci.
pom.xml
<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>test</groupId>
  <artifactId>test</artifactId>
  <version>0.0.1-SNAPSHOT</version>
</project>
Main.java
package jp.demo;
public class Main {
	public static void main(String[] args){
		System.out.println("### START ###");
		System.out.println("### END ###");
	}
}
Quand je lance Jar après l'installation de maven, je me fâche s'il n'y a pas de manifeste.
Ligne de commande
C:\sts\workspace\simple_maven\target>java -jar test-0.0.1-SNAPSHOT.jar
test-0.0.1-SNAPSHOT.jar n'a pas d'attribut manifeste principal
Générer un fichier manifeste
Par conséquent, spécifiez la balise mainClass dans l'ordre à partir de la balise de construction comme indiqué ci-dessous. Dans la balise mainClass, spécifiez la classe principale du package.
pom.xml
<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>test</groupId>
	<artifactId>test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<mainClass>jp.demo.Main</mainClass>
						</manifest>
					</archive>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>
Après l'installation de maven, quand je l'ai exécuté à nouveau, il s'est terminé normalement.
Ligne de commande
C:\sts\workspace\simple_maven\target>java -jar test-0.0.1-SNAPSHOT.jar
### START ###
### END ###
Puisque la version du compilateur est basse, ajoutons ce qui suit.
pom.xml
	<properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
	</properties>
Ajoutons ce qui suit aux propriétés comme ci-dessus. (Cela semble être un bogue dans maven-jar-plugin 3.1.2. Il est sorti dans un autre projet.)
pom.xml
	<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
référence: https://bugs.eclipse.org/bugs/show_bug.cgi?id=547409
Maintenant ça.
pom.xml
<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>test</groupId>
	<artifactId>test</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<properties>
		<maven.compiler.source>1.8</maven.compiler.source>
		<maven.compiler.target>1.8</maven.compiler.target>
	</properties>
	<build>
		<plugins>
			<plugin>
				<groupId>org.apache.maven.plugins</groupId>
				<artifactId>maven-jar-plugin</artifactId>
				<configuration>
					<archive>
						<manifest>
							<mainClass>jp.demo.Main</mainClass>
						</manifest>
					</archive>
				</configuration>
			</plugin>
		</plugins>
	</build>
</project>
        Recommended Posts