zoukankan      html  css  js  c++  java
  • Eclipse 打包项目jar 及依赖其他jar包

    1.使用eclipse 导出testsolr.jar包,被导项目依赖其他的jar包,这些jar包信息要写到MANIFEST.MF文件中。在运行testsolr.jar时,需要在testsolr.jar同目录下放好需要的jar包。

    编辑MANIFEST.MF文件:

      

     

      

    指定main方法:

     

    使用MANIFEST.MF中配置的Main-Class 启动:

    使用该种方式运行jar包必须在jar包外添加需要用的jar,运行时依赖。

    2.使用maven打包,将项目及其依赖的jar打到一个jar中。

    新建成maven,在pom.xml中添加<build>

      <build>
            <plugins>
                <plugin>
                    <artifactId>maven-compiler-plugin</artifactId>
                    <version>3.7.0</version>
                    <configuration>
                        <source>1.8</source>
                        <target>1.8</target>
                    </configuration>
                </plugin>
                <plugin>
                    <artifactId> maven-assembly-plugin </artifactId>
                    <configuration>
                        <descriptorRefs>
                            <descriptorRef>jar-with-dependencies</descriptorRef>
                        </descriptorRefs>
                        <archive>
                            <manifest>
                                <mainClass>solr.main.SolrAction</mainClass>
                            </manifest>
                        </archive>
                    </configuration>
                    <executions>
                        <execution>
                            <id>make-assembly</id>
                            <phase>package</phase>
                            <goals>
                                <goal>single</goal>
                            </goals>
                        </execution>
                    </executions>
                </plugin>
            </plugins>
        </build>

    使用maven打包:maven clean,maven install。在target生成带依赖的jar包:

    jar内结构:META-INF:

    再执行就不需要在jar包配置依赖的jar了。java -jar solrtest.jar arg0 arg1  (会直接运行pom中配置的mainclass)。

    使用java -cp solrtest.jar  xxx.xxx.Main arg0 arg1 (指定运行jar中的任一main方法)

    =========================================

    参考地址:https://www.cnblogs.com/f-zhao/p/6929814.html

  • 相关阅读:
    【洛谷P1119】灾后重建
    【洛谷P1462】通往奥格瑞玛的道路
    【洛谷P1991】无线通讯网
    poj 2892(二分+树状数组)
    hdu 1541(树状数组)
    hdu 5059(模拟)
    hdu 5056(尺取法思路题)
    poj 2100(尺取法)
    hdu 2739(尺取法)
    poj 3320(尺取法)
  • 原文地址:https://www.cnblogs.com/mryangbo/p/11731508.html
Copyright © 2011-2022 走看看