Se è necessario generare il percorso di classe come un semplice elenco di vasetti (senza il percorso completo), puoi implementare un plugin come quello nell'esempio qui sotto. Il mio bisogno è di aggiungere il classpath nel Manifest usando una proprietà diversa da "Class-Path" perché sto usando uno strumento come "JarRsrcLoader" di Eclipse (è simile a One-JAR) e voglio creare un Manifest.MF in questo modo:
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: .
Così, ho definito un plugin Maven come questo:
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());
}
}
Utilizzando questo plugin, è possibile definire una proprietà che contiene la lista dei barattoli di 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>
e utilizzare questa proprietà dove si vuole, ad esempio per la creazione manifest.mf personalizzato:
<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>
fonte
2014-06-27 07:29:59
http://stackoverflow.com/questions/849389/how-to-read-an-external-properties-file -in-maven spiega come caricare il risultato come proprietà Maven. Un allegato in http://jira.codehaus.org/browse/MCOMPILER-97 offre un esempio completo. –