I need to use a library for my Java code, which comes in a handful (10 of them, to be exact) of .JAR files. No problem here.
The issue is trying to access these libraries' source code/files, so that my IDE can help me not f**k up anything.
See, the library actually did come with source files. One for each .JAR file.
The .JAR files are named in the format <pathToPackage>-<version>.jar, and the source files are named in the format <pathToPackage>.source-<version>.jar, with <pathToPackage> and <version> matching for every .JAR-source file duo.
However, for some unknown reason, only two (2) of them are successfully picked up by the IDE.
I tried with VScode (with the Java Language Support extension), and IntelliJ, both giving the same result.
All of the source files are "proper" source files. I extracted their content in a separate folder, and am using that to navigate the source code.
Here are the files, for reference (grouped by which ones work, and which ones don't):
https://drive.google.com/file/d/1MISJ7vML7WI9BDzPXf7yGtrTWc7MgRjI/view
Related
How can I export files to eclipse project from the target folder?
I lost my project files. All I have is a target folder with binary .class files and static files in html.
Can you somehow build a project out of it?
Not possible. You can't go back to the original source files from just class files. You could decompile them which means you get code stripped of all names and comments except for method/fieldnames, code is mangled and worse, and probably broken. If you must - Here are some decompilers. Not sure if that site truly works (sites that only load over plain jane http are rather suspicious), but even if not, just search the web for any of the decompilers named there and run it on those class files.
As I said, the end result will look horrible, but it's the best you can do.
I have a question, perhaps it was already answered, but i didn't manage to find it and I appologize if the solution already exists (let me know if it is before deleting my thread).
Problem is:
I have created a program on another PC and exported it from eclipse as a .jar file. It works on my main PC when I double click on it but when I import it in Eclipse I can't find the .java file. So i can't edit it.
What I have done so far:
In eclipse I have created a new empty project
I have right clicked,import, archive file, selected the .class files that eclipse sees, but when I am in the Project Explorer in Eclipse I can't find the .java file where the main is. I mean I can click run as a program and it works, but there is no .java file, only .class files. What am I doing wrong?
That cranes.class should be cranes.java. At least on my other PC it is.
Program works fine, but I can't edit it on my main PC. What am I doing wrong?
Thanks and best regards
You need to select the Export Java source files and resources option while creating the jar file and then your Java files will be available on importing the project from the jar file.
This is similar to how you use other libraries. You depend on the Jar file which contains class bytecode (compiled) of java code. You can't edit any of such files directly in the project you are using it. Thought you can always extends functionalities in your current project using simple inheritance concepts.
If you think such functionalities are trivial you should prefer to change in the original project rebuild the jar and use the newer version of jar.
However if you feel similar things for 3rd party library you can
always make changes after taking fork from those library source
code (if open source) and build and use your own version or go
ahead and raise pull request if you are confident about your
changes.
Mostly when you build a jar file, all you have in it are .class files; these are the result of compiling .java files, and so are not editable with text editors.
You CAN create a jar file that contains .java (also known as source) files, and even a jar file that contains both .java and .class files, but if you ask eclipse to create a jar file, by default it is just going to put .class files and files from resource folders in it, not .java files.
Assuming from the question, the jar is a library created by OP, by compiling java files into class files and packing/exporting them. Although the class files can't be edited in any IDE, they can be de-compiled into Java files by using third-party applications.
I personally use IntelliJ for this de-compiling source files authored by me
Note: Although this gives OP the desired functionality, it may lead to violations if the classes are Copyrighted.
As IntelliJ states, they neither encourage nor discourage de-compiling class files and the decision is purely to the user's discretion.
EDIT: It is always recommended to use the original source files for editing. Try to host them on git so that it may be retrieved anytime required
It may be simpler to not use eclipse but jar/zip/tar your project directory on the one computer and simply extract it onto the other, then open that folder as a new project in Eclipse.
Best is the suggestion from #SanjayBharathi to use git and clone the repo on your other machine.
I'm having difficulty with my latest programming project. I have a program in Netbeans which relies upon an external library contained within a jar file. I am expected to use several imports to get the operations I need. While that's all fine and dandy, it also means I can't debug this code to make sure it works. I did see something on StackOverflow about doing a copy-pasta on the jar file into my code, but it uses so many commands and so much code that it would be more helpful to import the whole jar file, if possible.
How do I get Netbeans to recognize that I have an external jar file somewhere that it needs to read from in order to get its information?
Furthermore, I am expected to read in a file via the args[], and I am not sure how to read in command line arguments in Netbeans. How do I do this, and where am I expected to put the file to be read in?
I have figured out my issues and am going to answer this for future reference to anybody with this exact same problem. When you have a NetBeans project, you can open the project hierarchy and get a list of your source packages, test packages, libraries, and test libraries. The Libraries folder is where I needed the jar file.
I can right click on the libraries tab to add a jar/folder. Doing so gave me a file explorer to navigate to where I had my jar saved, and adding it fixed all the warnings for external library imports. The program now knows where to look for all the external libraries. Presumably, I'd have to repeat this if I ever moved the jar file.
As for adding the arguments, I found this under Run>Set Project Configuration>Customize. This brings up a window with the project properties. One of the text boxes will be for "Arguments," and filling this in with your commands will give you those commands as your Args[].
How can I splice files (ANY files, pngs, classes you name it) and folders into a pre-existing jar file ONLY using java code. That means no jar.exe utility. I am planning to make a program that places files/folders into a specific jar file. I have looked at several tutorials on java.util.jar and other jar managing modules but none of them seem to be right for me. Do I have to do this from scratch? Here is an over view of what I am thinking:
Take the desired files and folders from within a specific folder
open the target jar and place the files and folders within, overwriting other files if need be
I'm thinking I have to decompile the jar and then repackage it (ONLY USING JAVA CODE). I don't know what to do.
This one I couldn't find a proper answer.
I have 2 folders. One is called 'src', where
my java source code is located. The other one
is called 'srcGenerated' and has a set of files
created by a code generator. srcGenerated is a
superset of src.
I want to use both folders as my build path on
Eclipse. The problem is the duplicated files in
srcGenerated. Since there is no way to supress
the generation of files that are already in src,
my question is, how to delete the duplicated files
in srcGenerated based on the existing set of files
from src.
Ant or Powershell script preferred.
May not be the easiest one, but this is what I though of.
You can exclude Java files from srcGenerated that you don't want to be included while building.
Here you can exclude all the files that you don't want to be built. I know, it's painstaking if there are hundreds of conflicting Java files. But it definitely works.