Nếu bạn cần phải tạo ra classpath như một danh sách đơn giản của lọ (không có đường dẫn đầy đủ), bạn có thể triển khai một plugin giống như plugin trong ví dụ bên dưới. Nhu cầu của tôi là thêm classpath trong Manifest bằng cách sử dụng một thuộc tính khác với "Class-Path" vì tôi đang sử dụng một công cụ như Eclipse "JarRsrcLoader" (nó tương tự như One-JAR) và tôi muốn tạo một Manifest.MF như sau:
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: .
Vì vậy, tôi định nghĩa một plugin Maven như thế này:
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());
}
}
Sử dụng plugin này, bạn có thể xác định một tài sản, trong đó có danh sách các lọ của 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>
và sử dụng tài sản này bất cứ nơi nào bạn muốn, ví dụ để tạo MANIFEST.MF tùy chỉnh của bạn:
<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>
Nguồn
2014-06-27 07:29:59
http://stackoverflow.com/questions/849389/how-to-read-an-external-properties-file -in-maven thảo luận cách tải kết quả dưới dạng thuộc tính Maven. Phần đính kèm trong http://jira.codehaus.org/browse/MCOMPILER-97 cung cấp một ví dụ hoàn chỉnh. –