java – 如何创建一个胖罐子?
作者:互联网
使用SpringBoot,您可以使用@SpringBootApplication注释,但与纯Java Java框架相同的是什么?
IntelliJ创建了一个Maven项目,我添加了spark依赖项,但是运行安装目标,我获得了一个没有清单的5 KB jar.不是可执行的jar.
到目前为止创建的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>sparkdemo</groupId>
<artifactId>sparkdemo</artifactId>
<version>1.0 </version>
<packaging>jar</packaging>
<name>sparkdemo</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.5.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
<optimize>true</optimize>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>
</project>
非常感谢任何建议….谢谢!
解决方法:
你需要的是一个可执行的jar,它不仅包含你的类,还包含所有依赖项中的类.
为此你可以使用Maven Assembly Plugin.
请参阅下面的示例代码.
<project>
[...]
<build>
[...]
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.0.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>org.sample.App</mainClass> // specify your main class here
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
[...]
</project>
然后,运行mvn包,并且可执行jar应该位于文件夹目标中(名称类似于ProjectName-1.0-SNAPSHOT-jar-with-dependencies.jar).
标签:java,maven,intellij-idea,jar,spark-java 来源: https://codeday.me/bug/20190724/1523801.html