Si vous avez besoin pour générer le chemin de classe comme une simple liste des bocaux (sans le chemin complet), vous pouvez implémenter un plugin comme celui de l'exemple ci-dessous. Mon besoin est d'ajouter le classpath dans le manifeste en utilisant une propriété autre que "Class-Path" parce que j'utilise un outil comme Eclipse "JarRsrcLoader" (c'est similaire à One-JAR) et je veux créer un Manifest.MF comme ceci:
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: .
Alors, je définissais un plugin Maven comme ceci:
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());
}
}
Grâce à ce plugin, vous pouvez définir une propriété qui contient la liste des bocaux en verre de classpath:
<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>
et utiliser cette propriété où vous voulez, par exemple pour la création de votre Manifest.mf personnalisé:
<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 explique comment charger le résultat en tant que propriété Maven. Une pièce jointe dans http://jira.codehaus.org/browse/MCOMPILER-97 offre un exemple complet. –