Task generates error = 7: argument list too long

I have an Ant build.xml file that works without problems on my machine (Ubuntu), but causes the following error:

 /var/lib/hudson/workspace/myproject/build.xml:254: Error running /var/lib/hudson/tools/java_6/bin/javac compiler at org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter.executeExternalCompile(DefaultCompilerAdapter.java:525) (...) Caused by: java.io.IOException: Cannot run program "/var/lib/hudson/tools/java_6/bin/javac": java.io.IOException: error=7, Argument list too long at java.lang.ProcessBuilder.start(ProcessBuilder.java:460) at java.lang.Runtime.exec(Runtime.java:593) at org.apache.tools.ant.taskdefs.Execute$Java13CommandLauncher.exec(Execute.java:862) at org.apache.tools.ant.taskdefs.Execute.launch(Execute.java:481) at org.apache.tools.ant.taskdefs.Execute.execute(Execute.java:495) at org.apache.tools.ant.taskdefs.compilers.DefaultCompilerAdapter.executeExternalCompile(DefaultCompilerAdapter.java:522) ... 19 more Caused by: java.io.IOException: java.io.IOException: error=7, Argument list too long at java.lang.UNIXProcess.<init>(UNIXProcess.java:148) at java.lang.ProcessImpl.start(ProcessImpl.java:65) at java.lang.ProcessBuilder.start(ProcessBuilder.java:453) ... 24 more 

The argument list is quite large, in fact it contains all the jar files from WEB-INF/lib 231650 characters long! Any suggestions for fixing it?

+4
source share
3 answers

Use apply for fileset in build.xml for example

 <?xml version="1.0" encoding="UTF-8"?> <project default="build"> <fileset id="myfiles" dir="${basedir}"> <include name="**/*.java"/> <exclude name="**/Resources/**"/> <modified> <param name="cache.cachefile" value="${basedir}/cache.${project}.fileset.myfiles.properties"/> </modified> </fileset> <target name="execute-some-command"> <apply executable="javac" dir="${basedir}" failonerror="true"> <fileset refid="myfiles"/> </apply> </target> </project> 

By default, the command will be executed once for each file.

If you need to use parallel to run the command only once, use maxparallel to limit the amount of parallelism by transferring at most this many source files at once (for example, set to 1000 to transfer thousands of files in one pass). For instance:

 <apply executable="javac" parallel="true" maxparallel="1000" dir="${basedir}"> <fileset refid="myfiles"/> </apply> 

To find out how many files you have, check the contents of the cache file (see cache.cachefile in the example above).

0
source

With a command that will probably run in ARG_MAX in a shell for a long time.

This will report a good estimate of the available length, expr getconf ARG_MAX - env|wc -c - env|wc -l * 4 - 2048 >

Here you can find a good article on arg lists and lengths.

+1
source

Run ant -d . This will lead to an increase in output. However, it will also show your entire compilation line, which can help you understand why it took so long.

Do you use Jenkins / Hudson and where does the error occur?

Try the following:

  • Disable the assembly.
  • Log in to your build server AS JENKINS USER and find the workdir directory where Jenkins / Hudson is trying to build.
  • You may need to change $PATH or set $JAVA_HOME to point to the JDK that Hudson / Jenkins uses.
  • Now run ant -d <target> just like Jenkins / Hudson. Run this output through tee to a file. Now let's see what Hudson / Jenkins does, and why javac has too many arguments.
+1
source

Source: https://habr.com/ru/post/1346698/


All Articles