5

I realize this may seem like a completely stupid question and this question is a "wall of text", but I'm feeling like I've gotten way out of my depth here and need some guidance. I've read several SO questions on this topic, but still can't seem to find one that addresses this particular situation. (please reference update(s) at the end of this post)


BACKGROUND

Our company has an application that was built in Java and released as an executable JAR package by a developer who passed away a couple of years ago. Since then, there has been minimal need for even looking at that code, let alone making any changes. That's been really good because I do my programming in VB.NET (Visual Studio) and, while I can read and make sense of Java code, I'm not proficient in actually writing/debugging that code.

However, a recent issue has come up that forced me to try to take a look at this Java code due to some internal changes in organization and data structure. I've looked in his "src\" directory and found older versions of his original code but wasn't able to find the most recent version anywhere. I found some code that made it possible for me to extract the JAR that's currently being used to a local directory on CodeProject (JarsVB), so I've been able to look over some of the .java files when trying to figure out what query is being used for some random operation. I don't know what tool(s) the original developer used to create the project/JAR, so I've installed the IntelliJ IDEA Community Edition 2018 as an IDE, and it's worked for me so far to simply view the code so I can understand a bit about what it's doing.


PROBLEM/GOALS

Unfortunately, now there is a need for me to make a change to the Java code and update the JAR, and this is where I can't seem to make heads or tails of what I need to do. I have my local copy of the code from the "unzipped" JAR containing all the .java and .class files (along with all the other resources), but I'm not sure how to go from that to modifying the code and recompiling the executable JAR.

So, my goals here are as follows:

  1. (properly) Decompile the existing executable JAR. (If the JarsVB solution I mentioned above did what it was supposed to do, I should already have this part handled, but if there's a better, more "integrated" way of doing it, I'd be open to that as well.)
  2. Modify one or more .java files. (I believe I can figure out the syntax well enough to get this part done.)
  3. Debug/test my changes.
  4. Recompile the changes into an updated executable JAR for release. (THIS is where I'm experiencing the most confusion.)

WHAT I'VE DONE

I've been looking at the documentation for IntelliJ to try to figure out how to make this all happen, but I feel like I'm missing stuff. I set my "Project Structure" settings to point to a specific folder, but I can't seem to get it to actually build anything in my specified path.

Project Structure -> Project Settings -> Project

Project Structure -> Project Settings -> Modules

I went into one of the .java files and made/saved a small change to test, then went to the Build menu and tried all the building options available to me: "Build Project", "Build Module", and "Rebuild Project". Each time, the event log shows that "All files are up-to-date" (even though I changed one), so I go to my output directory to see what it built, but the folder is empty.

I looked at the IntelliJ documentation for Packaging a Module into a JAR File, which says to

On the main menu, choose Build | Build Artifact

But that option is disabled in my Build menu, and when I look in the Project Structure dialog, the Artifacts section is empty, so I try to add a new setting (Add -> JAR -> From modules with dependencies...), but I'm not sure how to properly set that up either.

Add -> JAR -> From modules with dependencies...

I tried to select a Main Class from my classes/ directory, but it wouldn't actually accept any of the .class files I selected, so I just left it blank. Then, I did a search for a MANIFEST file, but couldn't find one anywhere so I left that blank as well. The Build menu option is enabled now, but when I tried to Build Artifact, again, I get nothing in my output directory. In fact, the only files I can find that have changed are in my local working directory. I'm just dumbfounded at this point.


FINAL THOUGHTS/QUESTIONS

I've tried to provide as much detail here as I could think of about all the things I've tried and gone through to get this JAR updated, but if there's a question about anything, please let me know. I'm not looking for a "handout" and I don't expect anyone to do this for me, but I'm also not wanting to become a Java developer just for the sake of making some minor changes to an application that will eventually be replaced by a .NET application. I simply am not familiar enough with the tools or Java development in general to know how to get to where I want to be from where I am.

My decompiled source files are in a totally separate directory from the original, production JAR file because, when I recompile this time, I want to completely recreate the JAR. Am I understanding the Java development process correctly in editing one of the .java files I got from decompiling with the JarsVB and then recompiling the JAR?

Thanks in advance for any assistance in finding the resources I need to accomplish these goals.


EDIT/UPDATE

So, looking at the link in the accepted answer in another SO question, How to build jars from IntelliJ properly?, I figured out at least one part of my issue: Leaving the Main Class setting of my Artifacts configuration blank was a problem. Since I hadn't been able to select a .class file and I wasn't sure how to correctly populate that field, I hadn't given the IDE enough information to operate correctly. I entered the namespace and class (namespace.class) I found in the class file that apparently defines the main method for the application, then set the path for the MANIFISET.MF file to my output directory and tried again to Build Artifact.

This time, at least, it DID produce a JAR in my defined output directory, but it's only 1KB in size. As stated above, the source files are in a completely separate directory from the original JAR file from which they were decompiled. The output directory, too, is completely separate from the location of the original JAR file. Do I need a copy of the original JAR file in the output path for recompiling to work correctly?

I'm making progress, but I'm sure I'm overlooking something "stupid" at this point that's primarily due to my unfamiliarity with the IDE and developing Java applications in general.

UPDATE 2

Looking at another SO question - how to create jar of java package in intelliJ idea - I learned that I have to individually add the necessary files for repackaging into the JAR. However, this brings up the question, what files do I add? The linked question identifies the .class files, but when I go look at the .class files in my working directory, none of those have been updated recently, so it looks like I'm still missing a step somewhere.

Another question this brings up is, are there certain conventions for Java development of which I need to be aware when preparing my environment? I have my output path set to a completely separate folder than any working or production code, so I'm wondering if something in that setup might potentially cause issues.

As I said before, I made a small change to one of the .java files, then tried both the Build Module and Rebuild Project options, but those are still telling me that "All files are up-to-date". Even so, I tried adding just the .class files from under my classes\ directory to my Artifact configuration and tried again to Build Artifact. I got a bit larger file (approx. 5MB), but when I try to execute the JAR, it just doesn't appear to do anything, let alone actually launch the application.

I tried again by adding the root folder of my local copy of the source adding everything the root folder contains. (yes, the directory probably needs some "spring cleaning", but that's for another day)

All files/folders added to Artifact configuration

This time, I got a much larger file this time (approx. 21MB), so I thought I might have fixed the problem. Unfortunately, no such luck. The JAR still doesn't appear to execute.

For reference, the original JAR file from which the code was decompiled is approx. 59MB in size so, either IntelliJ is doing an incredible job with compression, or there's yet another step I haven't yet found. I'm sure this is all a matter of getting my IDE configured correctly, but I just can't seem to find the right combination of settings.

Community
  • 1
  • 1
G_Hosa_Phat
  • 976
  • 2
  • 18
  • 38
  • You need to research decompilation and compilation in IntelliJ. There are plenty of resources out there. – James Conway Jan 11 '19 at 16:41
  • Thank you. I've been researching for a few days now, but I've not been able to find the resources that give me clear direction on how to actually do it. Perhaps my google-fu is just too weak for this challenge but, as I'm totally unfamiliar with the tools and the procedures, I'm just getting more confused the further I go. – G_Hosa_Phat Jan 11 '19 at 16:46
  • That's hard to believe. I just searched for 'decompile jar intellij' and the first result was https://plugins.jetbrains.com/plugin/7100-java-decompiler-intellij-plugin. Try that. Regarding recompiling that, that is a very basic skill to learn in intelliJ so I suggest you check their website or other web resources on how to do this. – James Conway Jan 11 '19 at 16:48
  • 1
    Thank you again. As I stated, I've been going through the documentation, but much of it seems to assume a basic familiarity with the environment I do not have. I am continuing to go through the documentation while this question is open, and I'm sure it will start to make sense at some point but, as evidenced by the question, I've been doing those things I know how to do. While I'm certain there are things I'm missing, but I'm simply looking for a "nudge" in the right direction to accomplish my goals. – G_Hosa_Phat Jan 11 '19 at 17:02
  • 1
    Just to follow up, the link provided is to an outdated, no longer maintained plug-in for decompiling JAR files in IntelliJ. As I stated in my question, I believe I may have handled the decompilation process through the **JarsVB** code, but I'm not 100% certain if what I have will work for my stated objectives (since I seem to be having a problem with recompiling). – G_Hosa_Phat Jan 11 '19 at 19:48
  • That doesn’t matter... the plugin can still be used as far as I know. Just use some googling. – James Conway Jan 11 '19 at 19:57
  • @G_Hosa_Phat were you ever able to figure out the issue ? – Kharl Mccatty Dec 30 '20 at 00:22
  • @KharlMccatty unfortunately, no. I had to move on to other projects and leave this until I have the time to actually learn how to use IntelliJ. As stated, I'm sure I'm probably just overlooking something, but I'm not familiar enough with either the tools or the Java development process in general to know where else to look. – G_Hosa_Phat Dec 30 '20 at 16:07
  • @G_Hosa_Phat thanks for the response – Kharl Mccatty Dec 30 '20 at 17:32

0 Answers0