如何使用Maven创建Scala可运行的jar?

时间:2019-03-24 16:06:50

标签: java scala maven

我尝试使用Maven创建简单的Scala可运行jar。我在运行“错误:找不到或加载主类”时遇到此错误 这是我的命令:java -jar Jar_file-name.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>com.scala</groupId>
  <artifactId>ScalaProject</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.5.1</version>
                <configuration>
                    <source>1.8</source>
                    <target>1.8</target>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>com.learn.scala.chapter1.HelloWorldScala</mainClass>
                        </manifest>
                    </archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependencies</descriptorRef>
                    </descriptorRefs>
                </configuration>
                <executions>
                    <execution>
                        <id>make-assembly</id>
                        <phase>package</phase>
                        <goals>
                            <goal>single</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>


    </build>

</project>

使用mvn clean install创建了可运行的jar。可以在目标目录中看到两个jar。 ScalaProject-0.0.1-SNAPSHOT-jar-with-dependencies.jar(没有类文件夹)和ScalaProject-0.0.1-SNAPSHOT.jar(有classes文件夹)

Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Built-By: xxxx
Created-By: Apache Maven 3.5.4
Build-Jdk: 1.8.0_201

enter image description here

0 个答案:

没有答案