views:

1725

answers:

3

I have a large Java project with a large number of jar file dependencies. When I try to run the project (using exec) from Eclipse or Netbeans, Maven throws an exception which turns out to be a too large number of entries on the classpath (only 2/3 of the needed entries are included). Does anyone know a workaround for this? (Except from building an executable jar and running it from terminal.) Is it possbile to "extend" the "classpath-buffer"-size?

A: 

In Java 6 (which I hope you use) you can use wildcards in classpath entries. For the exact syntax check this page Setting the classpath and search to the right section by searching for "Understanding the class path and package names".

Or you try shortening the paths by placing all required jars in a single folder with a short path. e.g. C:\jars\

jitter
i have already shortened the path to C:\jr\ with no luck, still to much for the exec command
Dipper
And the classpath wildcards?
jitter
Using Java 5, and it is out of my hands to upgrade it (A upgrade is requested to the customer though)
Dipper
+1  A: 

This is a Maven exec plugin bug, it is documented in MEXEC-68, the reporter created a patch so I hope it will be resolved soon.

One workaround would be to add the classpath to the manifest file using this config for the maven-jar-plugin, add the dependencies to a folder and add just that folder to the CLASSPATH envvar.

For example:

<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>

This will add to the manifest something like:

Class-Path: plexus-utils-1.1.jar commons-lang-2.1.jar

If that JARs are in a CLASSPATH folder, you can run your JAR using maven exec plugin hidding the classpath with something like:

mvn exec:exec [...] -Dexec.classpathScope="test"

I used -Dexec.classpathScope="test" to make the plugin ignore the dependencies and add just the ones in scope test.

victor hugo
A: 

This problem is fixed in Netbeans 6.10M1. Please take a look at Bug 188864. If you have an older version, you can still fix this yourself (you just have to edit an xml file inside org-netbeans-modules-maven.jar).

Then, don't forget to check Maven Best Practices (http://wiki.netbeans.org/MavenBestPractices#Binding_Maven_goals_to_IDE_actions) where it is explained how to bind maven goals to IDE actions.

Regards,

Mach

metator