java  or  scala  打包,带依赖,生成可执行jar 包, 指定主类  然后可以直接  :  java -jar  xxxxx.jar    or  java -cp .     com.xxx.appmain

 

    <build>
        <sourceDirectory>src/main/scala</sourceDirectory>
<!--        <testSourceDirectory>src/test/scala</testSourceDirectory>-->
        <!--声明并引入子项目共有的插件-->
<!--        <pluginManagement>-->
            <plugins>
                <!--java maven的打包插件-->
                <plugin>
                    <groupId>org.apache.maven.plugins</groupId>
                    <artifactId>maven-assembly-plugin</artifactId>
                    <version>3.2.0</version>
                    <configuration>
                        <archive>
                            <manifest>
                                <!--指定入口文件的位置-->
                                <mainClass>com.bx.ItemRealTimeMonitor</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>
                <!--该插件用于将scala代码编译成class文件-->
                <plugin>
                    <groupId>net.alchim31.maven</groupId>
                    <artifactId>scala-maven-plugin</artifactId>
                    <version>3.2.2</version>
                    <executions>
                        <!--绑定到maven的编译阶段-->
                        <execution>
                            <goals>
                                <goal>compile</goal>
                                <goal>testCompile</goal>
                            </goals>
                            <configuration>
                                <args>
                                    <arg>-dependencyfile</arg>
                                    <arg>${project.build.directory}/.scala_dependencies</arg>
                                </args>
                            </configuration>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
<!--        </pluginManagement>-->
    </build>

 

 

 

 

 

二、将项目打jar 包时,将依赖的 jar 包一起并入到项目 jar 包中
在 pom.xml 的 build-plugins 节点上添加以下配置即可

<!-- 配置将依赖包一并打入到项目的 jar 包中 -->
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-assembly-plugin</artifactId>
            <version>3.0.0</version>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass></mainClass>
                    </manifest>
                </archive>
                <descriptorRefs>
                    <descriptorRef>jar-with-dependencies</descriptorRef>
                </descriptorRefs>
            </configuration>
            <executions>
                <execution>
                    <id>make-assembly</id> <!-- this is used for inheritance merges -->
                    <phase>package</phase> <!-- 指定在打包节点执行jar包合并操作 -->
                    <goals>
                        <goal>single</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>

 

 

posted on 2020-04-01 10:49  lshan  阅读(8573)  评论(0编辑  收藏  举报