You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+32-25Lines changed: 32 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,6 +7,7 @@ A Perl utility to extract Java version information from compiled Java class file
7
7
JavaInfo reads Java `.class` files and identifies the Java version used to compile them. It works by examining the bytecode header of each class file, specifically the magic number (`0xCAFEBABE`) and the major/minor version numbers that indicate the Java compiler version.
8
8
9
9
The tool can process individual files or recursively scan entire directories, making it useful for:
10
+
10
11
- Auditing Java dependencies and libraries
11
12
- Verifying compilation targets in build artifacts
12
13
- Identifying version mismatches in projects
@@ -39,34 +40,39 @@ The tool can process individual files or recursively scan entire directories, ma
39
40
### Examples
40
41
41
42
**Analyze a single class file:**
43
+
42
44
```bash
43
45
./JavaInfo MyClass.class
44
46
```
45
47
46
48
**Scan a directory recursively:**
49
+
47
50
```bash
48
51
./JavaInfo /path/to/project/target/classes
49
52
```
50
53
51
54
**Process multiple paths:**
55
+
52
56
```bash
53
57
./JavaInfo src/main/java build/classes lib/*.jar
54
58
```
55
59
56
60
### Example Output
57
61
58
-
```
62
+
```text
59
63
MyClass.class: Java 11 [0/55]
60
64
Utils.class: Java 8 [0/52]
61
65
LegacyCode.class: Java 1.4.2 [0/48]
62
66
```
63
67
64
68
The output format is:
65
-
```
69
+
70
+
```text
66
71
<filename>: Java <version> [<minor>/<major>]
67
72
```
68
73
69
74
Where:
75
+
70
76
-`<filename>` is the path to the class file
71
77
-`<version>` is the Java version (e.g., 8, 11, 17, or 1.4.2 for older versions)
72
78
-`<minor>/<major>` are the bytecode version numbers
@@ -76,35 +82,36 @@ Where:
76
82
The tool uses the following mapping between bytecode major versions and Java releases:
77
83
78
84
| Major Version | Minor Version | Java Version |
79
-
|--------------|---------------|--------------|
80
-
| 45 | 0-3 | 1.0.2 |
81
-
| 45 | 4+ | 1.1.8 |
82
-
| 46 | - | 1.2.2 |
83
-
| 47 | - | 1.3.1 |
84
-
| 48 | - | 1.4.2 |
85
-
| 49 | - | 5 |
86
-
| 50 | - | 6 |
87
-
| 51 | - | 7 |
88
-
| 52 | - | 8 |
89
-
| 53 | - | 9 |
90
-
| 54 | - | 10 |
91
-
| 55 | - | 11 |
92
-
| 56 | - | 12 |
93
-
| 57 | - | 13 |
94
-
| 58 | - | 14 |
95
-
| 59 | - | 15 |
96
-
| 60 | - | 16 |
97
-
| 61 | - | 17 |
98
-
| 62 | - | 18 |
99
-
| 63 | - | 19 |
100
-
| 64 | - | 20 |
101
-
| 65 | - | 21 |
85
+
|-------------|-------------|------------|
86
+
| 45 | 0-3 | 1.0.2 |
87
+
| 45 | 4+ | 1.1.8 |
88
+
| 46 | - | 1.2.2 |
89
+
| 47 | - | 1.3.1 |
90
+
| 48 | - | 1.4.2 |
91
+
| 49 | - | 5 |
92
+
| 50 | - | 6 |
93
+
| 51 | - | 7 |
94
+
| 52 | - | 8 |
95
+
| 53 | - | 9 |
96
+
| 54 | - | 10 |
97
+
| 55 | - | 11 |
98
+
| 56 | - | 12 |
99
+
| 57 | - | 13 |
100
+
| 58 | - | 14 |
101
+
| 59 | - | 15 |
102
+
| 60 | - | 16 |
103
+
| 61 | - | 17 |
104
+
| 62 | - | 18 |
105
+
| 63 | - | 19 |
106
+
| 64 | - | 20 |
107
+
| 65 | - | 21 |
102
108
103
109
For Java 5 and later, the formula is: **Java Version = Major Version - 44**
104
110
105
111
## Error Handling
106
112
107
113
The script will display error messages and exit if:
114
+
108
115
- A file cannot be opened or read
109
116
- A directory cannot be accessed
110
117
- A file is not a valid Java class file (missing the `0xCAFEBABE` magic number)
0 commit comments