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
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
+
9
+
The tool can process individual files or recursively scan entire directories, making it useful for:
10
+
- Auditing Java dependencies and libraries
11
+
- Verifying compilation targets in build artifacts
12
+
- Identifying version mismatches in projects
13
+
- Understanding compatibility requirements
14
+
15
+
## Requirements
16
+
17
+
- Perl 5.x or later
18
+
- Standard Perl modules (included by default):
19
+
-`File::Spec::Functions`
20
+
21
+
## Installation
22
+
23
+
1. Clone or download this repository
24
+
2. Make the script executable:
25
+
```bash
26
+
chmod +x JavaInfo
27
+
```
28
+
3. Optionally, add it to your PATH:
29
+
```bash
30
+
sudo cp JavaInfo /usr/local/bin/
31
+
```
32
+
33
+
## Usage
34
+
35
+
```bash
36
+
./JavaInfo <file or directory> [<file or directory> ...]
37
+
```
38
+
39
+
### Examples
40
+
41
+
**Analyze a single class file:**
42
+
```bash
43
+
./JavaInfo MyClass.class
44
+
```
45
+
46
+
**Scan a directory recursively:**
47
+
```bash
48
+
./JavaInfo /path/to/project/target/classes
49
+
```
50
+
51
+
**Process multiple paths:**
52
+
```bash
53
+
./JavaInfo src/main/java build/classes lib/*.jar
54
+
```
55
+
56
+
### Example Output
57
+
58
+
```
59
+
MyClass.class: Java 11 [0/55]
60
+
Utils.class: Java 8 [0/52]
61
+
LegacyCode.class: Java 1.4.2 [0/48]
62
+
```
63
+
64
+
The output format is:
65
+
```
66
+
<filename>: Java <version> [<minor>/<major>]
67
+
```
68
+
69
+
Where:
70
+
-`<filename>` is the path to the class file
71
+
-`<version>` is the Java version (e.g., 8, 11, 17, or 1.4.2 for older versions)
72
+
-`<minor>/<major>` are the bytecode version numbers
73
+
74
+
## Java Version Mapping
75
+
76
+
The tool uses the following mapping between bytecode major versions and Java releases:
77
+
78
+
| 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 |
102
+
103
+
For Java 5 and later, the formula is: **Java Version = Major Version - 44**
104
+
105
+
## Error Handling
106
+
107
+
The script will display error messages and exit if:
108
+
- A file cannot be opened or read
109
+
- A directory cannot be accessed
110
+
- A file is not a valid Java class file (missing the `0xCAFEBABE` magic number)
111
+
112
+
## Contributing
113
+
114
+
Contributions are welcome! Please see [CONTRIBUTING.md](CONTRIBUTING.md) for guidelines.
115
+
116
+
## License
117
+
118
+
See [LICENSE](LICENSE) file for details.
119
+
120
+
## Security
121
+
122
+
For security concerns, please see [SECURITY.md](SECURITY.md).
123
+
124
+
## Code of Conduct
125
+
126
+
This project adheres to a code of conduct. See [CODE_OF_CONDUCT.md](CODE_OF_CONDUCT.md) for details.
0 commit comments