Skip to content

Commit 6618e15

Browse files
committed
fetch Implementation-Version from manifest
1 parent cb418de commit 6618e15

File tree

2 files changed

+11
-9
lines changed

2 files changed

+11
-9
lines changed

pom.xml

+2-3
Original file line numberDiff line numberDiff line change
@@ -43,9 +43,8 @@
4343
<configuration>
4444
<archive>
4545
<manifest>
46-
<mainClass>
47-
com.github.reugn.devtools.Main
48-
</mainClass>
46+
<mainClass>com.github.reugn.devtools.Main</mainClass>
47+
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
4948
</manifest>
5049
</archive>
5150
<descriptorRefs>

src/main/java/com/github/reugn/devtools/controllers/MainController.java

+9-6
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,10 @@
1010
import javafx.scene.input.KeyCode;
1111
import javafx.scene.input.KeyEvent;
1212
import javafx.scene.layout.VBox;
13-
import org.apache.maven.model.Model;
14-
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
1513

16-
import java.io.FileReader;
1714
import java.net.URL;
1815
import java.util.ResourceBundle;
16+
import java.util.jar.Manifest;
1917

2018
public class MainController implements Initializable, Logger {
2119

@@ -60,12 +58,17 @@ public void initialize(URL location, ResourceBundle resources) {
6058
}
6159

6260
private String getVersion() {
61+
String version;
6362
try {
64-
MavenXpp3Reader reader = new MavenXpp3Reader();
65-
Model model = reader.read(new FileReader("pom.xml"));
66-
return model.getVersion();
63+
Class clazz = this.getClass();
64+
String classPath = clazz.getResource(clazz.getSimpleName() + ".class").toString();
65+
String manifestPath = classPath.substring(0, classPath.lastIndexOf("!") + 1) +
66+
"/META-INF/MANIFEST.MF";
67+
Manifest manifest = new Manifest(new URL(manifestPath).openStream());
68+
version = manifest.getMainAttributes().getValue("Implementation-Version");
6769
} catch (Exception e) {
6870
return "NA";
6971
}
72+
return version;
7073
}
7174
}

0 commit comments

Comments
 (0)