Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » Java Development Tools (JDT) » Creating A New Eclipse Project Using An Existing JAR File(Decompiling a JAR file to make modifications)
Creating A New Eclipse Project Using An Existing JAR File [message #973692] Tue, 06 November 2012 14:49 Go to next message
John Otten is currently offline John Otten
Messages: 2
Registered: November 2012
Junior Member
Hi,

I have a JAR file which holds approximately 150 class files. It contains a GUI to perform particular tasks and I can run it with "java -jar myFile.jar."

I would like to remove the GUI portion to make it a command line program and would like to use Eclipse in conjunction with a decompiler (jd-gui for example) to do so. Basically, I will need to modify and recompile approximately 10 class files to avoid the various GUI calls. (Unfortunately, the functional code appears to be tightly coupled with the GUI, and I can't just write a separate class to make calls to an API and avoid all the class files containing the GUI.)

Although I have a fair amount of experience using Eclipse with C/C++ code, I don't have as much using Eclipse with Java. The past several days I have been trying various ways to get the JAR file into an Eclipse project such that I can add pertinent .java files (which have been decompiled), modify them, and have the project compile them into .class files which then replace the original .class files.

I expect that some problems are because I am setting the build path incorrectly, but I have tried many different settings, and nothing seems to work quite right. Unpacking the JAR file places two class files in the "default" path (actually the top directory) and the rest of the files are in various directories under com.myCompany.etcA etcB and so on. Sometimes the project can see some of the files, sometimes not, but I haven't figured out a way to get the .java files I create (using the same name as the .class files) to be treated as part of the project. I have tried Import, creating new class files, etc. but I am probably missing something in my procedures.

Does anyone have any experience with a similar situation? Or can someone offer any suggestions on how I might proceed? BTW, I am doing this on Ubuntu, if it matters.

Thanks!
John
Re: Creating A New Eclipse Project Using An Existing JAR File [message #973869 is a reply to message #973692] Tue, 06 November 2012 17:36 Go to previous messageGo to next message
David Wegener is currently offline David Wegener
Messages: 1344
Registered: July 2009
Senior Member
First of all, make sure you go through through the Basic Tutorial in the Java Development User guide (Help->Help Contents.

You need to make sure that you are creating a Java project. You will also need a source folder defined for the Java project. You need to put the .java files in the source folder hierarchy. The .java files have to be in the correct package so you may need to create a package hierarchy using sub folders in your source directory. This should happen automatically if the .java files you import have package statements at the top of them.

Once the .java files are in a source folder, the compiler will be able to compile the .class files to the output folder.


You need to add the .jar file to the Build Path. Make sure that the projects source folders appear on the path in front of the .jar file. This will allow the built .class files to override the .class files in the .jar file. You can set the order of build path entries on the Order and Export tab of the Build Path dialog.
Re: Creating A New Eclipse Project Using An Existing JAR File [message #973925 is a reply to message #973869] Tue, 06 November 2012 18:33 Go to previous message
John Otten is currently offline John Otten
Messages: 2
Registered: November 2012
Junior Member
Thanks David,

I think my main problem was unpacking the .jar file and making the resulting .class files part of the project hierarchy. Your suggestion is much simpler and I am now able to do what I need to.

Thanks again,
John
Previous Topic:After Restart projects missing
Next Topic:How to run Stanford Karel?
Goto Forum:
  


Current Time: Thu Oct 23 18:54:29 GMT 2014

Powered by FUDForum. Page generated in 0.11972 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software