Maven packs an executable jar__maven that contains a dependent jar package

Source: Internet
Author: User
Tags echo message pack

The problems encountered:

MVN Jar:jar

When you run a jar file packaged with Maven, there is always a classnotfound error.


The first is the reference:

Http://stackoverflow.com/questions/574594/how-can-i-create-an-executable-jar-with-dependencies-using-maven

The answer to more than 800 high votes.

<plugin>
      <artifactId>maven-assembly-plugin</artifactId>
      <configuration>
        <archive>
          <manifest>
            <mainClass>edu.wit.fcl.gsontools.GsonFormat</mainClass>
          </manifest>
        </archive>
        <descriptorRefs>
          <descriptorRef> jar-with-dependencies</descriptorref>
        </descriptorRefs>
      </configuration>
    </ Plugin

MVN Clean Compile Assembly:single

Failed, Gson still didn't pack it in.


Again the reference:

http://m.oschina.net/blog/127531

http://panyongzheng.iteye.com/blog/1955763

    <plugin>    
        <groupId>org.apache.maven.plugins</groupId>    
        <artifactId> maven-jar-plugin</artifactid>    
        <configuration>    
            <archive>    
                <manifest>    
                    <addClasspath>true</addClasspath>    
                    <classpathPrefix>lib/</classpathPrefix>    
                    < mainclass>edu.wit.fcl.gsontools.gsonformat</mainclass>    
                </manifest>    
            </archive>    
        </configuration>    
    </plugin>

MVN Clean Package
Failed, Gson still didn't pack it in.


Finally, using MAVEN to generate ant, you can modify the Build.xml to reach the target

First MVN ant:ant

Then modify Build.xml to

<?xml version= "1.0" encoding= "UTF-8"?> <!--=============================================================        =========--> <!--ant build file (http://ant.apache.org/) for Ant 1.6.2 or above. --> <!--======================================================================--> <project name= " Gsontools "default=" Create_run_jar "basedir=". > <!--======================================================================--> <!--Import Maven-buil D.xml into the current project--> <!--=================================================== ===================--> <import file= "Maven-build.xml"/> <!--======================================== ==============================--> <!--help Target--&
  Gt <!--======================================================================--> <target name= "Help" > &L T;echo message="Please run: $ant-projecthelp"/> </target> <target name= "Create_run_jar" > <jar destfile= "${mav"
                En.build.dir}/${maven.build.finalname}.jar "filesetmanifest=" Mergewithoutmain "> <manifest> <attribute name= "Main-class" value= "Edu.wit.fcl.gsontools.GsonFormat"/> <attribute name = "Class-path" value= "."  /> </manifest> <fileset dir= "${maven.build.outputdir}"/> <zipfileset Excludes= "meta-inf/*. SF "src=" ${maven.repo.local}/com/google/code/gson/gson/2.3/gson-2.3.jar "/> </jar> </target> <
 /project>

To reach the target.

Because time is limited, this solves temporarily, should have a better method, wait for inquiry.

This way, there are manual changes to the file, such as Zipfileset after a paragraph, you need to copy

If you rely too much on it, it is completely unworkable.


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.