简体   繁体   中英

How do I automatically embed version information into my Java application?

I'm developing a JavaFX 8 application using IntelliJ, Maven and Git. I have an "about" window which shows the version number and build date. At the moment, I have to manually change these each time I update the code.

Is there any way I can have my build process automatically generate version and date information and embed this into my code so it shows up in the about window?

You can use maven resource filtering.

Prepare file eg. src/main/resources/version.properties with content:

version=${project.version}

and add in your pom:

<build>
    <resources>
        <resource>
            <directory>src/main/resources</directory>
            <filtering>true</filtering>
        </resource>
...
<build>

After build maven replace ${project.version} for current project version.

In your project you can read this file and use in your abut window.

Read more about build timestamp property: How to access maven.build.timestamp for resource filtering

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM