이제 제대로 된 것처럼 보입니다. 버전 파일은 'target/classes'에 인쇄되며 런타임에 앱을 볼 때 찾을 수 있습니다.
의 pom.xml에서
(빌드/플러그인) : 가정으로
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>createVersionInfo</id>
<phase>compile</phase>
<goals>
<goal>list</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>com.company.project</groupId>
<artifactId>app-name</artifactId>
<version>${project.version}</version>
<type>war</type>
<overWrite>true</overWrite>
</artifactItem>
</artifactItems>
<sort>true</sort>
<includeScope>compile</includeScope>
<outputFile>target/classes/dependency_versions.txt</outputFile>
</configuration>
</execution>
</executions>
</plugin>
'<excludeScope> 테스트 </excludeScope >'는 작동하지 않습니다. 그것은 모든 것을 배제합니다. 나는 에 대한 설명을 includeScope이 어떻게 든 설명한다고 생각합니다.
빈 문자열은 모든 범위 (기본값)를 나타냅니다. 해석되는 범위는 Maven에서 볼 수있는 범위 ( )가 pom에 지정된 것과 다릅니다. 요약 : 나는 실제로 내 자신의 목록을 채우는하고
InputStream in = this.getClass().getResourceAsStream("/dependency_versions.txt"); // Finds the file from classpath
String content = "";
// Java7 AutoCloseable
try (Scanner scan = new Scanner(in)) {
scan.useDelimiter("\\Z"); // Found this from another SO-thread, enables to read in the whole file at once
content = scan.next();
}
// Iterate the content and collect the information
// \n = line change
for (String row : content.split("\n")) {
row = row.trim();
// Basically removes the 1st two lines of the file that are not wanted
if (StringUtils.isEmpty(row) || row.endsWith(":")) {
continue;
}
StringTokenizer tokenizer = new StringTokenizer(row, ":");
String package = tokenizer.nextToken();
String dependency = tokenizer.nextToken();
String type = tokenizer.nextToken();
String version = tokenizer.nextToken();
String scope = tokenizer.nextToken();
}
을 보여주는 거기 TO :
runtime - scope gives runtime and compile dependencies,
compile - scope gives compile, provided, and system dependencies,
test - (default) scope gives all dependencies,
provided - scope just gives provided dependencies,
system - scope just gives system dependencies.
그리고 자바 측이 코드 조각을 거의 필요로 무엇을 할 것인가 JSF에서 정보를 얻지 만 간결함과 가독성을 위해이 부분을 생략했습니다.
... 실제로 내가 왜 전체 파일을 한 번에 읽고 반복하지 않고 한 번에 한 줄씩 읽으려고하는지 생각하게 만들었지 만 일일 WTF로 남겨 두겠다. ;)