Eclipse Community Forums - RDF feed
https://www.eclipse.org/forums/
Eclipse Community ForumsCreating A New Eclipse Project Using An Existing JAR File
https://www.eclipse.org/forums/index.php/mv/msg/429354/973692/#msg_973692
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]]>John Otten2012-11-06T14:49:47-00:00Re: Creating A New Eclipse Project Using An Existing JAR File
https://www.eclipse.org/forums/index.php/mv/msg/429354/973869/#msg_973869
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.
]]>David Wegener2012-11-06T17:36:09-00:00Re: Creating A New Eclipse Project Using An Existing JAR File
https://www.eclipse.org/forums/index.php/mv/msg/429354/973925/#msg_973925
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 ]]>John Otten2012-11-06T18:33:12-00:00