maven-assembly-plugin的使用,打包SparkSQL项目到生产环境

版权声明:未经允许,随意转载,请附上本文链接谢谢(づ ̄3 ̄)づ╭❤~
https://blog.csdn.net/xiaoduan_/article/details/79809188

maven-assembly-plugin的使用,打包SparkSQL项目到生产环境

  这里有一个pom.xml文件,其中Spark,hadoop等生产上已经有环境。所以打包的时候需要将这些依赖不打包进去,所以需要使用 maven-assembly-plugin 插件
1. 在pom.xml文件中添加一个插件

<plugin>
     <artifactId>maven-assembly-pluginartifactId>
        <configuration>
             <archive>
                  <manifest>
                     <mainClass>mainClass>
                  manifest>
             archive>
                     <descriptorRefs>
   <descriptorRef>jar-with-dependenciesdescriptorRef>
                    descriptorRefs>
                configuration>
plugin>
  1. 将不需要的依赖添加属性 provided,添加这个属性的依赖将不会被打入jar包内

下面是一个例子

<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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0modelVersion>
    <groupId>com.anthony.sparkgroupId>
    <artifactId>sqlartifactId>
    <version>1.0version>
    <inceptionYear>2008inceptionYear>
    <properties>
        <scala.version>2.11.8scala.version>
        <spark.version>2.1.0spark.version>
    properties>

    <repositories>
        <repository>
            <id>scala-tools.orgid>
            <name>Scala-Tools Maven2 Repositoryname>
            <url>http://scala-tools.org/repo-releasesurl>
        repository>
    repositories>

    <pluginRepositories>
        <pluginRepository>
            <id>scala-tools.orgid>
            <name>Scala-Tools Maven2 Repositoryname>
            <url>http://scala-tools.org/repo-releasesurl>
        pluginRepository>
    pluginRepositories>

    <dependencies>
        
        <dependency>
            <groupId>org.scala-langgroupId>
            <artifactId>scala-libraryartifactId>
            <version>${scala.version}version>
        dependency>

        
        <dependency>
            <groupId>org.apache.sparkgroupId>
            <artifactId>spark-sql_2.11artifactId>
            <version>${spark.version}version>
            <scope>providedscope>
        dependency>


        
       <dependency>
            <groupId>org.apache.sparkgroupId>
            <artifactId>spark-hive_2.11artifactId>
            <version>${spark.version}version>
           <scope>providedscope>
        dependency>

        
        <dependency>
            <groupId>org.spark-project.hivegroupId>
            <artifactId>hive-jdbcartifactId>
            <version>1.2.1.spark2version>
            <scope>providedscope>
        dependency>

        
        <dependency>
            <groupId>org.apache.poigroupId>
            <artifactId>poi-ooxmlartifactId>
            <version>3.14version>
        dependency>

        <dependency>
            <groupId>org.apache.poigroupId>
            <artifactId>poiartifactId>
            <version>3.14version>
        dependency>
        <dependency>
            <groupId>com.ggstargroupId>
            <artifactId>ipdatabaseartifactId>
            <version>1.0-SNAPSHOTversion>
        dependency>
        
        <dependency>
            <groupId>mysqlgroupId>
            <artifactId>mysql-connector-javaartifactId>
            <version>5.1.13version>
        dependency>

    dependencies>

    <build>

        
            
                
                
                    
                
            
        

        <sourceDirectory>src/main/scalasourceDirectory>
        <testSourceDirectory>src/test/scalatestSourceDirectory>
        <plugins>
            <plugin>
                <groupId>org.scala-toolsgroupId>
                <artifactId>maven-scala-pluginartifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>compilegoal>
                            <goal>testCompilegoal>
                        goals>
                    execution>
                executions>
                <configuration>
                    <scalaVersion>${scala.version}scalaVersion>
                    <args>
                        <arg>-target:jvm-1.5arg>
                    args>
                configuration>
            plugin>
            <plugin>
                <artifactId>maven-assembly-pluginartifactId>
                <configuration>
                    <archive>
                        <manifest>
                            <mainClass>mainClass>
                        manifest>
                    archive>
                    <descriptorRefs>
                        <descriptorRef>jar-with-dependenciesdescriptorRef>
                    descriptorRefs>
                configuration>
            plugin>

        plugins>
    build>
    <reporting>
        <plugins>
            <plugin>
                <groupId>org.scala-toolsgroupId>
                <artifactId>maven-scala-pluginartifactId>
                <configuration>
                    <scalaVersion>${scala.version}scalaVersion>
                configuration>
            plugin>
        plugins>
    reporting>
project>

你可能感兴趣的:(Maven)