相关疑难解决方法(0)

在运行时获取Maven工件版本

我注意到在Maven工件的JAR中,project.version属性包含在两个文件中:

META-INF/maven/${groupId}/${artifactId}/pom.properties
META-INF/maven/${groupId}/${artifactId}/pom.xml
Run Code Online (Sandbox Code Playgroud)

是否有推荐的方法在运行时读取此版本?

java maven-2

166
推荐指数
6
解决办法
12万
查看次数

使用thymeleaf和springboot在标题中显示应用程序版本

我想在我的htm页面中显示我的webapp版本,使用类似的东西(百里香内部):

<h4 th:text="${version}">Version</h4>
Run Code Online (Sandbox Code Playgroud)

数据在pom.xml中设置得很好:

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>fr.test.navig</groupId>
    <artifactId>navigo</artifactId>
    <version>2.0.3-SNAPSHOT</version>
...
<!-- Package as an executable jar -->
<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
            <configuration>
                <archive>
                    <manifest>
                        <mainClass>Application</mainClass>
                        <addDefaultImplementationEntries>
                            true
                        </addDefaultImplementationEntries>
                    </manifest>
                </archive>
            </configuration>
        </plugin>
    </plugins>
</build>
Run Code Online (Sandbox Code Playgroud)

我可以在MANIFEST.MF(在META-INF下生成的jar中)中看到它:

实现 - 版本:2.0.3-SNAPSHOT

我试图在控制器中获取应用程序版本并将其设置在ModuleAttribute中:

@ModelAttribute("version")
public String getVersion() {
    logger.info("ModelAttribute to get application version");
    return getClass().getPackage().getImplementationVersion();
}
Run Code Online (Sandbox Code Playgroud)

但getClass().getPackage().getImplementationVersion()价值是null.实际上,package implementationVersion默认情况下不是应用程序的实现版本.

maven spring-boot

5
推荐指数
2
解决办法
6656
查看次数

如何从 *.war/META-INF/MANIFEST.MF 文件中读取 manifest.mf?

使用 maven 编译 *.war 文件,其中包含:

- META-INF
- - MANIFEST.MF
- WEB-INF
- - classes
- - lib
- - web.xml
Run Code Online (Sandbox Code Playgroud)

使用 java.util.jar.Manifest 我想读取清单文件以从那里获取应用程序版本,例如/sf/answers/1473238021/

但Application.class.getResourceAsStream("/META-INF/manifest.mf")返回null。

Application.class.getResource( "" ).getFile() 返回 %WAR%/WEB-INF/lib/javax.ws.rs-api-2.0.jar!/javax/ws/rs/core/

使用 Spring,我实现了 ApplicationContextAware 接口来获取 ApplicationContext 实例。

并applicationContext.getClassLoader().getResourceAsStream( "" )返回%WAR%/WEB-INF/classes。

但我不需要WEB-INF,我需要META-INF目录。如何获得?

java spring web-applications maven

3
推荐指数
1
解决办法
7510
查看次数

spring boot/spring web app嵌入版本号

在Spring应用程序中嵌入唯一版本号的策略是什么?

我有一个使用Spring Boot和Spring Web的应用程序.

它已经足够成熟,我想对它进行版本化并在运行时看到它显示在屏幕上.

spring-mvc spring-boot

1
推荐指数
1
解决办法
3402
查看次数