• idea16使用maven命令clean、编译、打包jar或者war


    项目环境:idea16+jdk1.7+maven-3.3.9

    项目说明:编写简单的Java类,使用maven命令生成jar包,然后执行-------》"java  -classpath  jar所在路径  main类名称"

    注意:使用idea16工具的maven命令生成的jar包可能不包含第三方依赖

    1、编写pom.xml文件

       1
       2
       3
       4
       5
       6
       7
       8
       9
      10
      11
      12
      13
      14
      15
      16
      17
      18
      19
      20
      21
      22
      23
      24
      25
      26
      27
      28
      29
      30
      31
      32
      33
      34
      35
      36
      37
      38
      39
      40
      41
      42
      43
      44
      45
      46
      47
      48
      49
      50
      51
      52
      53
      54
      55
      56
      57
      58
      59
      60
      61
      62
      63
      64
      65
      66
      67
      68
      69
      70
      71
      72
      73
      74
      75
      76
      77
      78
      79
      80
      81
      82
      83
      84
      85
      86
      87
      88
      89
      90
      91
      92
      93
      94
      95
      96
      97
      98
      99
     100
     101
     102
     103
     104
     105
     106
     107
     108
     109
     110
     111
     112
     113
     114
     115
     116
     117
     118
     119
     120
     121
     122
     123
     124
     125
     126
     127
     128
     129
     130
     131
     132
     133
     134
     135
     136
     137
     138
     139
     140
     141
     142
     143
     144
     145
     146
     147
     148
     149
     150
     151
     152
     153
     154
     155
     156
     157
     158
     159
     160
     161
     162
     163
     164
     165
     166
     167
     168
     169
     170
     171
     172
     173
     174
     175
     176
     177
    <?xml version="1.0" encoding="UTF-8"?>
    <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>spark-jqz-predict</groupId>
    <artifactId>com.enn</artifactId>
    <version>1.0-SNAPSHOT</version>
    <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    <java.version>1.7</java.version>
     
    <!--add maven release-->
    <maven.compiler.source>1.7</maven.compiler.source>
    <maven.compiler.target>1.7</maven.compiler.target>
    <encoding>UTF-8</encoding>
     
    </properties>
    <dependencies>
    <dependency>
    <groupId>mysql</groupId>
    <artifactId>mysql-connector-java</artifactId>
    <version>5.1.24</version>
    </dependency>
     
    <!--junit-->
    <dependency>
    <groupId>junit</groupId>
    <artifactId>junit</artifactId>
    <version>4.12</version>
    </dependency>
    <!--slf4j-->
    <dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>slf4j-log4j12</artifactId>
    <version>1.7.20</version>
    </dependency>
    <!---
    引入本地jar
    <dependency>
    <groupId>org.apache.spark</groupId>
    <artifactId>spark-assembly_2.10</artifactId>
    <version>1.6.0-cdh5.8.0</version>
    <scope>system</scope>
    <systemPath>D:/spark-assembly-1.6.2-hadoop2.6.0.jar</systemPath>
    </dependency>
     
    --->
    </dependencies>
    <!--编译java代码使用该配置-->
    <build>
    <finalName>spark-jqz-predict</finalName>
    <plugins>
    <!-- 编译插件 -->
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>3.1</version>
    <configuration>
    <source>1.7</source>
    <target>1.7</target>
    <encoding>UTF-8</encoding>
    </configuration>
    </plugin>
    <!-- 打包 -->
    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
    <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    <archive>
    <manifest>
    <mainClass></mainClass>
    </manifest>
    </archive>
    </configuration>
    <executions>
    <execution>
    <id>make-assembly</id>
    <phase>package</phase>
    <goals>
    <goal>single</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>
     
    <!--注意:如果是编译scala代码,则需要使用如下配置-->
    <!--
     
     
    <build>
    <finalName>sparkEnn</finalName>
    <sourceDirectory>src/main/scala</sourceDirectory>
    <testSourceDirectory>src/test/scala</testSourceDirectory>
    <plugins>
    <plugin>
    <groupId>org.scala-tools</groupId>
    <artifactId>maven-scala-plugin</artifactId>
    <executions>
    <execution>
    <goals>
    <goal>compile</goal>
    <goal>testCompile</goal>
    </goals>
    </execution>
    </executions>
    <configuration>
    <scalaVersion>${scala.version}</scalaVersion>
    <args>
    <arg>-target:jvm-1.7</arg>
    </args>
    </configuration>
    </plugin>
    <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-eclipse-plugin</artifactId>
    <configuration>
    <downloadSources>true</downloadSources>
    <buildcommands>
    <buildcommand>ch.epfl.lamp.sdt.core.scalabuilder</buildcommand>
    </buildcommands>
    <additionalProjectnatures>
    <projectnature>ch.epfl.lamp.sdt.core.scalanature</projectnature>
    </additionalProjectnatures>
    <classpathContainers>
    <classpathContainer>org.eclipse.jdt.launching.JRE_CONTAINER</classpathContainer>
    <classpathContainer>ch.epfl.lamp.sdt.launching.SCALA_CONTAINER</classpathContainer>
    </classpathContainers>
    </configuration>
    </plugin>
    <plugin>
    <artifactId>maven-assembly-plugin</artifactId>
    <configuration>
    <descriptorRefs>
    <descriptorRef>jar-with-dependencies</descriptorRef>
    </descriptorRefs>
    <archive>
    <manifest>
    <mainClass></mainClass>
    </manifest>
    </archive>
    </configuration>
    <executions>
    <execution>
    <id>make-assembly</id>
    <phase>package</phase>
    <goals>
    <goal>single</goal>
    </goals>
    </execution>
    </executions>
    </plugin>
    </plugins>
    </build>
    <reporting>
    <plugins>
    <plugin>
    <groupId>org.scala-tools</groupId>
    <artifactId>maven-scala-plugin</artifactId>
    <configuration>
    <scalaVersion>${scala.version}</scalaVersion>
    </configuration>
    </plugin>
    </plugins>
    </reporting>
     
     
    -->
     
     
    </project>
    来自CODE的代码片
    pom.xml

    注意:一定需要将编译的jdk选择为1.7(有3个地方需要选择)、build属性一定要添加,否则maven编译不会正常生成jar或者war包!

    如下3个地方:

    (1)第一个


    (2)第二个



    (3)第三个



    2、编写Helloword.java类


    3、开始执行clean、compleiler和jar命令

    如下:



    4、查看项目目录可以发现jar包





    注:以上测试已经通过,可以直接使用!

    转:http://blog.csdn.net/high2011/article/details/52812746


  • 相关阅读:
    python openpyxl 封装Execl常用操作的方法
    python webdriver grid多节点运行webdriver程序
    url的正则表达式
    基于Erlang VM的函数式编程语言Elixir
    [整理]团队开发效率提升探索一
    FreeBSD应该装gnome3做桌面
    FreeBSD pkg仓库有台湾的镜像了
    再探OAuth2
    【转】Android世界的Swift
    内存只有4G的MBP要怎么破
  • 原文地址:https://www.cnblogs.com/xijin-wu/p/6548692.html
Copyright © 2020-2023  润新知