In the actual project I used Antrun and closure-compiler to compress the JS project. Then I use the following code: first join the dependency.
<Dependency> <groupId>Com.google.javascript</groupId> <Artifactid>Closure-compiler</Artifactid> <version>v20160315</version></Dependency>
Add the plugin code to the Pom.xml file.
<plugin> <groupId>Org.apache.maven.plugins</groupId> <Artifactid>Maven-antrun-plugin</Artifactid> <version>1.6</version> <executions> <Execution> <Phase>Generate-sources</Phase> <Goals> <goal>Run</goal> </Goals> <Configuration> <Target> < Propertyname= "Closure.compiler.class.name"value= "Com.google.javascript.jscomp.CommandLineRunner" /> <Echomessage= "Generate main.min.js" /> <JavaClassName= "${closure.compiler.class.name}"Classpathref= "Maven.compile.classpath"Fork= "true"FailOnError= "true"> <Argvalue= "--js"/> <Argvalue= "${basedir}/src/main/webapp/js/main.js"/> <Argvalue= "--js_output_file"/> <Argvalue= "${basedir}/src/main/webapp/js/main.min.js" /> <Argvalue= "--compilation_level"/> <Argvalue= "Simple_optimizations"/> </Java> </Target> </Configuration> </Execution> </executions> </plugin>
Then run to find an error. CreateProcess error=206,?? T??? Ò)??? Then there is a pile of garbled characters, and then after StackOverflow find after found garbled is probably "CreateProcess error=206, the filename or extension is too long"
" under Windows, the string length supported by the command line is limited, and the maximum length of a string that can be used at the command prompt is 8,191 characters on a computer that is running Microsoft Windows XP or later. On a computer that is running Microsoft Windows 2000 or Windows NT 4.0, the maximum length of the string that can be used at the command prompt is 2047 characters. "
I can't figure out why my antrun command is too long and there are so few arg parameters on it. Then I use MVN package–x to print the details. Found a classpathref= "Maven.compile.classpath" back to print all Lib jar packages to run the command.
Instead of specifying Closure-complie to run this jar package.
In Maven, you know that you can specify the Closure-complie.jar package that Maven relies on directly, referring to the following address:
Http://maven.apache.org/plugins/maven-antrun-plugin/examples/classpaths.html
So modify the above Pom.xml code:
<plugin> <groupId>Org.apache.maven.plugins</groupId> <Artifactid>Maven-antrun-plugin</Artifactid> <version>1.6</version> <executions> <Execution> <Phase>Generate-sources</Phase> <Goals> <goal>Run</goal> </Goals> <Configuration> <Target> < Propertyname= "Closure.compiler.class.name"value= "Com.google.javascript.jscomp.CommandLineRunner" /> <Echomessage= "Generate main.min.js" /> <PathID= "MAVEN.LIB.DEP"Path= "${com.google.javascript:closure-compiler:jar}"/> <JavaClassName= "${closure.compiler.class.name}"Classpathref= "MAVEN.LIB.DEP"Fork= "true"FailOnError= "true"> <Argvalue= "--js"/> <Argvalue= "${basedir}/src/main/webapp/js/main.js"/> <Argvalue= "--js_output_file"/> <Argvalue= "${basedir}/src/main/webapp/js/main.min.js" /> <Argvalue= "--compilation_level"/> <Argvalue= "Simple_optimizations"/> </Java> </Target> </Configuration> </Execution> </executions> </plugin>
Specifying the CLASSPATHREF parameter
CreateProcess error=206, the filename or extension is a too long "solution