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.