title: IntelliJ IDEA - Decompiling/Editing/Recompiling JAR
body: <p>I realize this may seem like a completely stupid question and this question is a &quot;wall of text&quot;, 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. (<em>please reference update(s) at the end of this post</em>)</p>
  <hr />
  <h2>BACKGROUND</h2>
  <p>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.</p>
  <p>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 &quot;<code>src\</code>&quot; 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 (<a href="https://www.codeproject.com/Articles/27610/%2FArticles%2F27610%2FOpening-Jars-with-Visual-Basic" rel="nofollow noreferrer">JarsVB</a>), so I've been able to look over some of the <code>.java</code> 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 <strong>IntelliJ IDEA Community Edition 2018</strong> 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.</p>
  <hr />
  <h2>PROBLEM/GOALS</h2>
  <p>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 &quot;unzipped&quot; JAR containing all the <code>.java</code> and <code>.class</code> 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.</p>
  <p>So, my goals here are as follows:</p>
  <ol>
  <li>(properly) Decompile the existing executable JAR.  (<em>If the <strong>JarsVB</strong> 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 &quot;integrated&quot; way of doing it, I'd be open to that as well.</em>)</li>
  <li>Modify one or more <code>.java</code> files. (<em>I believe I can figure out the syntax well enough to get this part done.</em>)</li>
  <li>Debug/test my changes.</li>
  <li>Recompile the changes into an updated executable JAR for release. (<em><strong>THIS</strong> is where I'm experiencing the most confusion.</em>)</li>
  </ol>
  <hr />
  <h2>WHAT I'VE DONE</h2>
  <p>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 &quot;Project Structure&quot; settings to point to a specific folder, but I can't seem to get it to actually build anything in my specified path.</p>
  <p><a href="https://i.stack.imgur.com/n0fbe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/n0fbe.png" alt="Project Structure -&gt; Project Settings -&gt; Project" /></a></p>
  <p><a href="https://i.stack.imgur.com/VdHqI.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/VdHqI.png" alt="Project Structure -&gt; Project Settings -&gt; Modules" /></a></p>
  <p>I went into one of the <code>.java</code> files and made/saved a small change to test, then went to the <strong>Build</strong> menu and tried all the building options available to me: &quot;Build Project&quot;, &quot;Build Module&quot;, and &quot;Rebuild Project&quot;.  Each time, the event log shows that &quot;All files are up-to-date&quot; (even though I changed one), so I go to my output directory to see what it built, but the folder is empty.</p>
  <p>I looked at the IntelliJ documentation for <strong><a href="https://www.jetbrains.com/help/idea/packaging-a-module-into-a-jar-file.html" rel="nofollow noreferrer">Packaging a Module into a JAR File</a></strong>, which says to</p>
  <blockquote>
  <p>On the main menu, choose <strong>Build</strong> | <strong>Build Artifact</strong></p>
  </blockquote>
  <p>But that option is disabled in my <strong>Build</strong> menu, and when I look in the <strong>Project Structure</strong> dialog, the <strong>Artifacts</strong> section is empty, so I try to add a new setting (<strong>Add</strong> -&gt; <strong>JAR</strong> -&gt; <strong>From modules with dependencies...</strong>), but I'm not sure how to properly set that up either.</p>
  <p><a href="https://i.stack.imgur.com/XeDld.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XeDld.png" alt="Add -&gt; JAR -&gt; From modules with dependencies..." /></a></p>
  <p>I tried to select a <strong>Main Class</strong> from my <code>classes/</code> directory, but it wouldn't actually accept any of the <code>.class</code> files I selected, so I just left it blank.  Then, I did a search for a <code>MANIFEST</code> file, but couldn't find one anywhere so I left that blank as well.  The <strong>Build</strong> menu option is enabled now, but when I tried to <strong>Build Artifact</strong>, 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.</p>
  <hr />
  <h2>FINAL THOUGHTS/QUESTIONS</h2>
  <p>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 &quot;handout&quot; 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.</p>
  <p>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 <code>.java</code> files I got from decompiling with the <strong>JarsVB</strong> and then recompiling the JAR?</p>
  <p>Thanks in advance for any assistance in finding the resources I need to accomplish these goals.</p>
  <hr />
  <h2>EDIT/UPDATE</h2>
  <p>So, looking at the link in the accepted answer in another SO question, <a href="https://stackoverflow.com/questions/1082580/how-to-build-jars-from-intellij-properly">How to build jars from IntelliJ properly?</a>, I figured out at least one part of my issue: Leaving the <strong>Main Class</strong> setting of my <strong>Artifacts</strong> configuration blank was a problem.  Since I hadn't been able to select a <code>.class</code> 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 (<code>namespace.class</code>) I found in the class file that apparently defines the <code>main</code> method for the application, then set the path for the <code>MANIFISET.MF</code> file to my output directory and tried again to <strong>Build Artifact</strong>.</p>
  <p>This time, at least, it <em>DID</em> 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?</p>
  <p>I'm making progress, but I'm sure I'm overlooking something &quot;stupid&quot; at this point that's primarily due to my unfamiliarity with the IDE and developing Java applications in general.</p>
  <h2>UPDATE 2</h2>
  <p>Looking at another SO question - <a href="https://stackoverflow.com/questions/41397753/how-to-create-jar-of-java-package-in-intellij-idea">how to create jar of java package in intelliJ idea</a> - 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 <code>.class</code> files, but when I go look at the <code>.class</code> files in my working directory, none of those have been updated recently, so it looks like I'm still missing a step somewhere.</p>
  <p>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.</p>
  <p>As I said before, I made a small change to one of the <code>.java</code> files, then tried both the <strong>Build Module </strong> and <strong>Rebuild Project</strong> options, but those are still telling me that &quot;All files are up-to-date&quot;.  Even so, I tried adding just the <code>.class</code> files from under my <code>classes\</code> directory to my <strong>Artifact</strong> configuration and tried again to <strong>Build Artifact</strong>.  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.</p>
  <p>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 &quot;spring cleaning&quot;, but that's for another day)</p>
  <p><a href="https://i.stack.imgur.com/m8BwJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/m8BwJ.png" alt="All files/folders added to Artifact configuration" /></a></p>
  <p>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.</p>
  <p>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.</p>