Wenn Sie den Classpath als einfache Liste der Gläser (ohne den vollständigen Pfad) erzeugen müssen, Sie können ein Plugin wie das im Beispiel unten implementieren. Ich brauche den Klassenpfad im Manifest mit einer anderen Eigenschaft als "Class-Path", weil ich ein Tool wie Eclipse "JarRsrcLoader" verwende (ähnlich wie One-JAR) und ich möchte eine Manifest.MF wie folgt erstellen:
Manifest-Version: 1.0
Rsrc-Class-Path: ./ ssm-core-0.0.1-SNAPSHOT.jar commons-codec-1.9.jar
commons-io-2.4.jar ehcache-2.8.3.jar spring-beans-4.0.5.RELEASE.jar s
sm-standalone-cryptlayer-0.0.1-SNAPSHOT.jar shiro-core-1.2.3.jar comm
ons-beanutils-1.8.3.jar bcprov-jdk15on-1.50.jar javacsv-2.0.jar ssm-f
ile-persistence-0.0.1-SNAPSHOT.jar spring-context-4.0.5.RELEASE.jar s
pring-aop-4.0.5.RELEASE.jar aopalliance-1.0.jar spring-core-4.0.5.REL
EASE.jar commons-logging-1.1.3.jar spring-expression-4.0.5.RELEASE.ja
r slf4j-log4j12-1.7.7.jar slf4j-api-1.7.7.jar log4j-1.2.17.jar
Built-By: ctasso
Build-Jdk: 1.7.0_10
Class-Path: .
So definiert ich ein Maven Plugin wie folgt aus:
public void execute() throws MojoExecutionException, MojoFailureException {
try {
MavenArchiver mavenArchiver = new MavenArchiver();
ManifestConfiguration config = new ManifestConfiguration();
config.setAddClasspath(true);
Manifest manifest = mavenArchiver.getManifest(project, config);
String classPath = manifest.getMainAttributes().getValue("Class-Path");
getLog().debug(String.format("Setting the classpath property %s to %s",classpathVarName,classPath));
project.getProperties().put(classpathVarName, classPath);
} catch (DependencyResolutionRequiredException e) {
throw new MojoFailureException(e.getMessage());
} catch (ManifestException e) {
throw new MojoFailureException(e.getMessage());
}
}
dieses Plugin verwenden, können Sie eine Eigenschaft definieren, die die Liste der Gläser des classpath enthält:
<plugin>
<groupId>it.cineca.plugins</groupId>
<artifactId>classpath-maven-plugin</artifactId>
<version>0.0.1-SNAPSHOT</version>
<executions>
<execution>
<id>set-classpath</id>
<phase>package</phase>
<goals>
<goal>setcp</goal>
</goals>
<configuration>
<classpathVarName>cineca.classpath</classpathVarName>
</configuration>
</execution>
</executions>
</plugin>
und diese Eigenschaft verwenden, wo immer Sie, zum Beispiel für die Erstellung Ihrer benutzerdefinierte MANIFEST.MF wollen:
<archive>
<manifestEntries>
<Rsrc-Class-Path>./ ${cineca.classpath}</Rsrc-Class-Path>
<Class-Path>.</Class-Path>
<Rsrc-Main-Class>it.cineca.cpd.starter.TestStarter</Rsrc-Main-Class>
<Main-Class>org.eclipse.jdt.internal.jarinjarloader.JarRsrcLoader</Main-Class>
</manifestEntries>
</archive>
http://stackoverflow.com/questions/849389/how-to-read-an-external-properties-file -in-maven erläutert, wie das Ergebnis als Maven-Eigenschaft geladen wird. Ein Anhang in http://jira.codehaus.org/browse/MCOMPILER-97 bietet ein vollständiges Beispiel. –