eclipse导出maven工程的可执行jar包

一、eclipse导出maven工程的可执行jar包

建立两个maven工程 ZKServer 和ZKClient

注意:用maven进行开发管理的话,默认的打出来的jar包是不能运行的,需要在pom.xml文件中添加如下配置以生成可执行的jar包

<build>
    <plugins>
      <plugin>
        <artifactId> maven-assembly-plugin </artifactId>
        <configuration>
          <descriptorRefs>
            <descriptorRef>zkServer</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>com.fanghao.AppServer</mainClass> 
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>

而我们在eclipse中创建的工程默认的 JRE System Library 是 Java-SE-1.5 ,我们需要添加以下配置让其变成1.7或1.8,并且无论我们对该maven工程update多少次,都不会回到1.5

<build>
    <plugins>

      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>

  </plugins>
</build>

ZKServer工程

<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       ">
  <modelVersion>4.0.0</modelVersion>
  <groupId>com.fanghao</groupId>
  <artifactId>ZKServer</artifactId>
  <version>0.0.1-SNAPSHOT</version>

  <dependencies>
    <dependency>
      <groupId>org.apache.zookeeper</groupId>
      <artifactId>zookeeper</artifactId>
      <version>3.4.11</version>
    </dependency>
  </dependencies>
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <artifactId> maven-assembly-plugin </artifactId>
        <configuration>
          <descriptorRefs>
            <descriptorRef>zkServer</descriptorRef>
          </descriptorRefs>
          <archive>
            <manifest>
              <mainClass>com.fanghao.AppServer</mainClass>
            </manifest>
          </archive>
        </configuration>
        <executions>
          <execution>
            <id>make-assembly</id>
            <phase>package</phase>
            <goals>
              <goal>single</goal>
            </goals>
          </execution>
        </executions>
      </plugin>
    </plugins>
  </build>
</project>

--------------------------------------------------------

package com.fanghao;

import java.util.concurrent.CountDownLatch;

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:https://www.heiqu.com/zzdwxg.html