I am trying to enhance a library. The library is in the Referenced folder of eclipse. I presume in that folder I can't just edit the code so I guess I have to import the whole .jar file as kind of a project, but how can I do it in eclipse .....
The right way to do it is to find/download the source code for the library. The ugly way to do it is to decompile the library.
After that, edit the source code, and run against your custom version.
You probably need some sort of Java code decompiler to get the source code for that library and then make an eclipse project based on its source. It will be tedious and you will need to setup the dependencies and all that. However you might want to see if the source for that project is already somewhere on internet, eg open source libraries. One better approach could also be extending that library by means of extending classes and that.
Related
Is there a way to make changes in jar which doesnot have source code in it and rebuild it with this change as a jar in eclipse.
You can look into using Java decompilers; in order to turn the .class files within the JAR archive back into .java source code. The process and some tools for that are outlined here.
But: understand that *decompiling" can be a tough business! Plus: there is always the question if the licence terms of the library you are using allows you to do that. Being able to do something isn't the same as being allowed to do that!
Finally: keep in mind that a JAR is just a deployment artifact. A lot of libraries are open source, and you can most often download that source and build the corresponding JARs completely on your own.
I am working with Paho project for Android. According to the instructions, while testing Android sample app, it is required to have both AndroidService.jar and JavaClient.jar included in the project. I import them in Android Studio and the app is working perfectly.
However, and that is my problem, I want to edit these precompiled java classes. But the problem is that, since they are imported as .jar files and that they are already compiled, they are uneditable in Android Studio.
I have the source code of the libraries I want to include into the project. Unfortunately, when I import them in the Android Studio, I get bunch of errors (which I do not usually get when I import .jar files).
The methods I tried up until now are to copy the source java classes into the project by creating new classes with same names and content. I also tried to import the whole source project as the module to my project. I get same errors. I also know about this great fork of the Paho project which lets you just to import whole project in Android Studio and it simply works. However, the AndroidService classes are still uneditable.
As I said, I have the needed source code. I can generate these .jar files without any problem from the source and then import them in the project. That method works. But to edit the java classes, then to compile them, then to import them in the Android Studio to test everything, and to do it every time when I change something, is a bit tiring. That is why I am asking for help.
Please, let me know if you know some approach which will let me to edit these two "libraries" while I am still in Android Studio, so I can test changes I make immediately.
P.S. I have been Googling this so much and I believe that there is no ready solution for these online. However, If you find one, I will be really happy if you point to it.
Fist of all I have no idea why you want to edit the Paho Android Service because it doesn't make to much sense. You are able to overwrite every class if necessary. Any way you would need to change the Android Service build from Maven to Gradle to include the source into you project.
To help you out I have just done that and pushed to the "withSouce" branch of my repository. https://github.com/sandro-k/org.eclipse.paho.android.service.sample/tree/withSource
If you now want to replace the compile org.eclipse.paho:org.eclipse.paho.client.mqttv3:1.0.2 with your sources as well you have to replace that with a local dependency as well.
Jar files are really just compressed (zipped) versions of .class files (and a few other essential documents). Class files are compiled .java files. The only way to edit these jar files would be to unzip the jar with a program such as 7zip or WinRAR, then decompile the class to get the source code, edit it, and recompile. Decompiling is a very difficult, time consuming process, and would require external software. Your best bet would be to continue the process you've been using.
Note: If you still wish to decompile, you might want to check out Cavaj, a free java decompiler. But beware, it may not return the exact source code used in the jar.
Sources: Experience
I'm programming in Java, and I usually prefer git when programming in Python. So I want to use it for Java too. I'm using Eclipse, but other people may use Netbeans or IntelliJ IDEA or whatever. How is this usually managed when putting Java code into version control?
I'm making a game which uses the library LWJGL, and that library needs to be added to the project file to be used. Therefore, I still need to check the project file into my project.
Short answer, it doesn't matter at all. Create a file called .gitignore in the root of your project file to ignore your IDE's project files or anything like that, then add your code into the git repository. For example, a good Eclipse .gitignore can be found here.
That way the other collaborators won't see your project files, and if they do the same with their .gitignore for their IDE, you won't see theirs.
I created a simple project using WindowBuilder in Eclipse and my goal is to send it by email. I don't know what kind of computer the person is using, so I exported my project into a 'Runnable JAR File' and checked the option 'Extract required libraries into generated JAR'.
The problem is that the generated JAR file is 20MB in size!!! The project has only one simple window - nothing complicated or fancy.
I found that some people use ProGuard to include only what is really needed.
I would like to know if there is a way to optimize it 'manually'? Are there libraries that are automatically included when creating a WindowBuilder project, and how may I determine which libraries I can remove?
Thank you.
I've had the same Problem using WindowBuilder. My solution was to look for the imports in my .java file, e.g.: import org.eclipse.swt.SWT;
In the Project Explorer in Eclipse you can see that there are much more imports than needed. Those 'Build Paths' can be removed carefully.
Simply rightclick on a .jar import like "com.ibm.icu_52.1.0.v201404241930.jar" and click on "Build Path" and "Remove from Build Path". Unfortunately, you can't remove or delete the packages inside the .jars.
But using this method, I managed to reduce the size from 20.7MB to 3.87MB. It's something...
Like fge said, send the source. Or upload the .jar to dropbox if you require you partner to access all of the files in the .jar.
If you don't like dropbox, find some other cloud storage solutions through a google search. Github or Bitbucket could also be an alternative to dropbox.
Cheers.
Use the Eclipse plugin FatJar. FatJar shows you which libraries are getting imported and allows you to specify which .jars, libraries, etc., that you want built into your JAR.
FatJar
Your jarfile is too big due of the project template. Create a sample java project, then use windowdbuilder components. Do not create a project Swing Template, by this way eclipse is gonna import all eclipse gui toolkits.
Tried it out with my way, my application's length equals to 3Ko against 24MO with the template project
As I do more and more coding in Java I am creating a library of methods that I use often. Is there a way in Eclipse to set it so that I can import these methods from the source folder of the library project to other projects without copying them to each individual project?
I know there is something that I can do with the Build Path, but when I try to add the source for my library I get a package error in the project it is linked to.
Thanks
Don't import/copy the code from another project--the point is to use the output of the shared project. Just indicate that the project depends on the other project; don't think about the shared project's source.