Not logged in.  Login/Logout/Register | List snippets | | Create snippet | Upload image | Upload data

20
LINES

< > BotCompany Repo | #1030868 // changeJavaVersionInClassFile

JavaX fragment (include) [tags: use-pretranspiled]

Uses 1311K of libraries. Click here for Pure Java version (2734L/16K).

1  
!include once #1019934 // BCEL
2  
3  
import org.apache.bcel.classfile.Attribute;
4  
import org.apache.bcel.classfile.SourceFile;
5  
import org.apache.bcel.generic.*;
6  
7  
svoid changeJavaVersionInClassFile(File classFile, int newMajor, int newMinor) ctex {
8  
  JavaClass c = new ClassParser(classFile.getPath(), classFile.getName()).parse();
9  
  int major = c.getMajor(), minor = c.getMinor();
10  
  print("Current Java version of " + classFile + ": " + major + "." + minor);
11  
  if (major == newMajor && minor == newMinor) ret;
12  
  print("  Patching to " + newMajor + "." + newMinor);
13  
14  
  ClassGen g = new ClassGen(c);
15  
  g.setMajor(newMajor);
16  
  g.setMinor(newMinor);
17  
  c = g.getJavaClass();
18  
  c.dump(classFile); // overwrite!
19  
  print("  Done");
20  
}

Author comment

Began life as a copy of #1004069

download  show line numbers  debug dex  old transpilations   

Travelled to 5 computer(s): bhatertpkbcr, mowyntqkapby, mqqgnosmbjvj, pyentgdyhuwx, vouqrxazstgt

No comments. add comment

Snippet ID: #1030868
Snippet name: changeJavaVersionInClassFile
Eternal ID of this version: #1030868/4
Text MD5: f35a5bc55dd1e9359d273af9df82d3b4
Transpilation MD5: b0e2b5d833a0b6dae56f22383df37103
Author: stefan
Category: javax
Type: JavaX fragment (include)
Public (visible to everyone): Yes
Archived (hidden from active list): No
Created/modified: 2021-04-04 20:38:23
Source code size: 738 bytes / 20 lines
Pitched / IR pitched: No / No
Views / Downloads: 131 / 198
Version history: 3 change(s)
Referenced in: [show references]