Im attempting to follow a tutorial here that will help me to modify some source code from the twitter4j executable jar to allow me to use twitters native image upload api, unfortunately Im having a tough time figuring out how this is done because these files arent allowing me to edit them at all in eclipse, here is the tutorial im following seems pretty straight forward but the author didnt include the step of how to edit the files assuming this was common knowledge I can only assume.
You have two options open to you.
1) Get the original source code, and package the jar after making your changes.
2) Unzip the jar (any standard unzipping program should do), make your changes and then repackage the jar.
That said, perusing those links (I didn't go very in depth) suggests that those are libraries you can use - not libraries you are required to modify to get to work. What are you trying to achieve by modifying the library?
Related
I have a Maven project. After I make changes to the project, I package the project up into an Uber Jar file and upload that to my backups. I am wondering, if my computer were to break or I lose all the code to the project, can I get the project back using only the Uber Jar file or would the project be gone forever?
How can I open this Jar file as a project and view all the Java code inside of it?
It would be entirely gone; that jar file contains only class files, not your source files, and you can't 'recover' source files from class files (you can decompile them which is mostly useless for this purpose; all comments, most names, most structure - all gone. You can't feasibly continue your project with this).
As it isn't in there, it's not possible to 'open a jar file and see all java code inside it'.
You'll need to set up backups.
The proper way forward is to first set up version control; this ensures that you don't just have a backup of the latest state of your source files, but every state of it - you can travel back to any time. Protects against code you deleted by accident, and means you can freely remove code you think you no longer need without that nagging feeling of: Yeah but what if.... maybe later? - so stop commenting out stuff you don't need, just get rid of it. It also means if there's a bug, you can time travel to the exact point in time when you added the line, and you can review the changes made by others in a project (presumably you're writing this on your own for now, but at some point you'll work with more people than just yourself!)
Read up on git which is the version control system that 80%+ or so of the community uses, probably best not to spring for exotic options if you aren't familiar. There are a billion tutorials out there to find if you search the web.
Host your git on a site like github or bitbucket which therefore also takes care of backups. Alternatively, host it on your own server (it's not complicated; git is open source). If you can't do that either, just let git write to a local directory and then use e.g. backblaze or something similar to ensure that file is backed up.
Yes, you can view your code by using a decompiler. I have experience mostly with IntelliJ, and this IDE includes a decompiler of its own. In case you lose everything and have only the jar file. You can use this included decompiler to get your source back from your .class files. But instructions on doing that are a story for another question...
If you want to secure your code use GIT. A version control tool that is a must when it comes to programming. Google about it and after a few days of playing around with it, you will never worry about such things.
Right-click on your project.
Select Build Path.
Click on Configure Build Path.
Click on Libraries, select Modulepath and select Add External JARs.
Select the jar file from the required folder.
Click and Apply and Ok.
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 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.
Hi guys
I have an Applet in MyApplet.java file. It uses external .jar libraries and I have to get it work on a Web Browser.
1) I am a complete newbie in writing custom classpath, manifest ecc... which is the correct way to compile my .java file to get the .class?
2) Once i have the .class file, what i have to do in my webspace? where to put the jar files? what i have to write in my html page?
A step by step tutorial would be awesome
There are nice resources out there, for example "The Java Tutorial", which has a section on How to write Applets.
But you seem to need even more basic advise on compiling - so take a look at Getting Started, and later at Deployment. Then come back if you have more concrete problems.