How to modify code in one package of an existing legacy .jar file w/o compiling all other packages in the .jar using IntelliJ
After lots of mental hernias(and time), I found out how to do this and am posting this solution so others can do it faster.
How to modify code in one package of an existing legacy .jar file w/o compiling all other packages in the .jar using IntelliJ
1. In Ubuntu Linux extract all files from the legacy .jar using the Archive Manager
Right-click on .jar to invoke Archive Manager
2. Create the project using the wizard.
3. Put the package(directory) to modify in the “src” directory
4. Put all other extracted directories and files in a new .jar file
Example:
5. (base) nexus@Lanny:~/Documents/XXX$ jar cf nameOfJar.jar README.md xxx.db org META-INF layout xxx free engines
5. Create a directory, named "lib", in the project directory
6. Put the newly created .jar file in this lib directory
7. Right click on the project name > Click on "Open Module Settings". A dialog window will open.
8. In this window, on the left you'll see 'Libraries', click on it. You'll see your lib folder here. If you don't see it, follow steps 6 and 7, else go to step 8.
9. Add a "Java library" by clicking the “+” button. You can name it as per your wish.
10. Add your .jar file in the right box.
11. Click on module settings on the left and then 'Dependencies' on the right and add that Java library as dependency to your module by clicking green + on the right most.
12. Create a Run/Debug configuration to Run the “main” method in the project module
Problems encountered and their solutions:
Problem 1: Typical javax.x.x references not working
Solution 1: The JDK version was too current for the legacy code being used. Change the JDK version to an older one.
Problem 1.1: When installing OpenJDK 8 with sudo apt install openjdk-8-jdk, an error occurs:
dpkg: error processing package oracle-java11-installer-local (--configure):
installed oracle-java11-installer-local package post-installation script subprocess
returned error exit status 1
Errors were encountered while processing:
oracle-java11-installer-local
E: Sub-process /usr/bin/dpkg returned an error code (1)
Solution 1.1: sudo dpkg --list | grep -i jdk (to see all JDKs installed)
sudo rm /etc/apt/sources.list.d/*java* (too see all that's installed)
sudo apt remove openjdk* (still resulted in: Errors were encountered while
processing: oracle-java11-installer-local
E: Sub-process /usr/bin/dpkg returned an error code(1))
sudo rm -rf /var/cache/oracle-jdk11-installer-local
sudo rm /var/lib/dpkg/info/oracle*
sudo apt purge oracle-java11-installer*
sudo apt-get remove --purge icedtea-* openjdk-*
sudo apt autoremove
sudo dpkg --list | grep -i jdk (roo see that all is gone, for clean JDK installation)
sudo apt install openjdk-8-jdk
update-java-alternatives --list
sudo update-alternatives --config java
java -version
Problem 2: IntelliJ not recognizing JDK changes: (How to change JDK throughout IntelliJ)
Solution 2:
On the menu, clicks File -> Project Structure.
Platform Settings -> SDKs , add and point to the JDK 13 installed folder.
Project Settings -> Project , change both Project SDK and Project language level to JDK xx.
Project Settings -> Modules , change the language level to JDK xx.
Please sign in to leave a comment.