jeudi 23 juin 2011

Java classpath via Maven too long (Windows)

If you have any problems with Java Classpath length :


For example:

[ERROR]Failed to execute goal org.codehaus.mojo:exec-maven-plugin:1.1.1:exec (default-cli) on project gcl-presentation: Result of cmd.exe /X /C 
""C:\Program Files\Java\jdk1.6.0_24\bin\java.exe" [...] execution is: '1'. -> [Help 1]
[ERROR]
[ERROR]To see the full stack trace of the errors, re-run Maven with the -e switch.


The problem is that the Java Classpath is contained in the command line instead of putting it into $CLASSPATH env. variable. The workaround consist on asking Maven to do it by writing classpath directly in a manifest file.This solution can be applied on 2 context, depending on the maven plugin you use.
Solution for maven-jar-plugin

<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-jar-plugin</artifactId>
        ...
        <configuration>
          <archive>
            <manifest>
              <addClasspath>true</addClasspath>
            </manifest>
          </archive>
        </configuration>
        ...
      </plugin>
    </plugins>
  </build>
  ...
</project>

Solution for exec-maven-plugin
<project>
  ...
  <build>
    <plugins>
      <plugin>
        <groupId>org.codehaus.mojo</groupId>
        <artifactId>exec-maven-plugin</artifactId>
        <version>1.2</version>
        <executions>
          <execution>
            ...
            <goals>
              <goal>exec</goal>
            </goals>
          </execution>
        </executions>
        <configuration>
          <executable>maven</executable>
          <!-- optional -->
          <workingDirectory>/tmp</workingDirectory>
          <longClassPath>true</longClasspath>
<arguments> ... </arguments> </configuration> </plugin> </plugins> </build> ... </project>
on Netbeans :

2 commentaires:

  1. You can try Long Path Tool when you face extension is too long and error. I did use it. I did not found any problem yet.

    RépondreSupprimer
  2. I like and suggest you to try LongPathTool program. It is very helpful for copying/deleting or renaming long path files.

    RépondreSupprimer