Is there an easy way to copy libraries between projects on netbeans? - java

Often I find that I have a set of JAR files configured as libraries in one Netbeans project and I need the same (or a subset of) those JAR files in another project.
All of the ways I've found to do this so far are very long winded and painful so I am hoping I've missed something simple.
Google found a 6 year old feature request and nothing else really useful: https://netbeans.org/bugzilla/show_bug.cgi?id=118325
At the moment the ways I can think of are:
Create a "Library" for the set of JARS and then use that library in each project. This is probably the neatest way to do this but still involves a lot of steps and seems like massive overkill just to copy a few JAR file references!
Go to source project, right click JAR, select edit. See the library classpath in the popup window. Close window, go to the destination, select add JAR. Can't cut and paste in path so have to hope you remembered it right. Browse to JAR file, add it - repeat for any other JARs that are not in the same folder.
Frustratingly the tooltip that comes up when you hover over the library contains exactly the path you need to add the jar - but there is no way I can find to copy the contents of that tooltip!
This is all made much more painful by the fact that all the windows are modal, you can't cut and paste the path out because it doesn't actually copy as a real path, etc.
All suggestions welcome as this is becoming a frequent annoyance at the moment!

I just found this old question while searching for an answer to the same problem. I Couldn't find any other useful results so I copied the libraries in the nbproject/project.properties file to the same place in my new project.
The only references I found in the whole directory were like this
file.reference.commons-lang3-3.8.1.jar=D:\\Documents\\javaLibraries\\commons-lang\\commons-lang3-3.8.1\\commons-lang3-3.8.1.jar
file.reference. [.....many more]
includes=**
jar.compress=false
javac.classpath=\
${file.reference.commons-lang3-3.8.1.jar}:\
[....many more]:\
This part was just in between what I wanted, so I copied the whole thing but it was the same in the new project.
includes=**
jar.compress=false
So far it's all working fine. You could back up the project.properties file but I already had one nightly.
edit:
You can also copy over the javadoc and sources by copying the lines like
javadoc.reference.commons-lang3-3.8.1.jar=D:\\Documents[more path....]javadoc.jar
source.reference.commons-lang3-3.8.1.jar=D:\\Documents[more path....]sources.jar

Related

How to import JAR file as a project into an IDE?

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.

IntelliJ IDEA - Decompiling/Editing/Recompiling JAR

I realize this may seem like a completely stupid question and this question is a "wall of text", but I'm feeling like I've gotten way out of my depth here and need some guidance. I've read several SO questions on this topic, but still can't seem to find one that addresses this particular situation. (please reference update(s) at the end of this post)
BACKGROUND
Our company has an application that was built in Java and released as an executable JAR package by a developer who passed away a couple of years ago. Since then, there has been minimal need for even looking at that code, let alone making any changes. That's been really good because I do my programming in VB.NET (Visual Studio) and, while I can read and make sense of Java code, I'm not proficient in actually writing/debugging that code.
However, a recent issue has come up that forced me to try to take a look at this Java code due to some internal changes in organization and data structure. I've looked in his "src\" directory and found older versions of his original code but wasn't able to find the most recent version anywhere. I found some code that made it possible for me to extract the JAR that's currently being used to a local directory on CodeProject (JarsVB), so I've been able to look over some of the .java files when trying to figure out what query is being used for some random operation. I don't know what tool(s) the original developer used to create the project/JAR, so I've installed the IntelliJ IDEA Community Edition 2018 as an IDE, and it's worked for me so far to simply view the code so I can understand a bit about what it's doing.
PROBLEM/GOALS
Unfortunately, now there is a need for me to make a change to the Java code and update the JAR, and this is where I can't seem to make heads or tails of what I need to do. I have my local copy of the code from the "unzipped" JAR containing all the .java and .class files (along with all the other resources), but I'm not sure how to go from that to modifying the code and recompiling the executable JAR.
So, my goals here are as follows:
(properly) Decompile the existing executable JAR. (If the JarsVB solution I mentioned above did what it was supposed to do, I should already have this part handled, but if there's a better, more "integrated" way of doing it, I'd be open to that as well.)
Modify one or more .java files. (I believe I can figure out the syntax well enough to get this part done.)
Debug/test my changes.
Recompile the changes into an updated executable JAR for release. (THIS is where I'm experiencing the most confusion.)
WHAT I'VE DONE
I've been looking at the documentation for IntelliJ to try to figure out how to make this all happen, but I feel like I'm missing stuff. I set my "Project Structure" settings to point to a specific folder, but I can't seem to get it to actually build anything in my specified path.
I went into one of the .java files and made/saved a small change to test, then went to the Build menu and tried all the building options available to me: "Build Project", "Build Module", and "Rebuild Project". Each time, the event log shows that "All files are up-to-date" (even though I changed one), so I go to my output directory to see what it built, but the folder is empty.
I looked at the IntelliJ documentation for Packaging a Module into a JAR File, which says to
On the main menu, choose Build | Build Artifact
But that option is disabled in my Build menu, and when I look in the Project Structure dialog, the Artifacts section is empty, so I try to add a new setting (Add -> JAR -> From modules with dependencies...), but I'm not sure how to properly set that up either.
I tried to select a Main Class from my classes/ directory, but it wouldn't actually accept any of the .class files I selected, so I just left it blank. Then, I did a search for a MANIFEST file, but couldn't find one anywhere so I left that blank as well. The Build menu option is enabled now, but when I tried to Build Artifact, again, I get nothing in my output directory. In fact, the only files I can find that have changed are in my local working directory. I'm just dumbfounded at this point.
FINAL THOUGHTS/QUESTIONS
I've tried to provide as much detail here as I could think of about all the things I've tried and gone through to get this JAR updated, but if there's a question about anything, please let me know. I'm not looking for a "handout" and I don't expect anyone to do this for me, but I'm also not wanting to become a Java developer just for the sake of making some minor changes to an application that will eventually be replaced by a .NET application. I simply am not familiar enough with the tools or Java development in general to know how to get to where I want to be from where I am.
My decompiled source files are in a totally separate directory from the original, production JAR file because, when I recompile this time, I want to completely recreate the JAR. Am I understanding the Java development process correctly in editing one of the .java files I got from decompiling with the JarsVB and then recompiling the JAR?
Thanks in advance for any assistance in finding the resources I need to accomplish these goals.
EDIT/UPDATE
So, looking at the link in the accepted answer in another SO question, How to build jars from IntelliJ properly?, I figured out at least one part of my issue: Leaving the Main Class setting of my Artifacts configuration blank was a problem. Since I hadn't been able to select a .class file and I wasn't sure how to correctly populate that field, I hadn't given the IDE enough information to operate correctly. I entered the namespace and class (namespace.class) I found in the class file that apparently defines the main method for the application, then set the path for the MANIFISET.MF file to my output directory and tried again to Build Artifact.
This time, at least, it DID produce a JAR in my defined output directory, but it's only 1KB in size. As stated above, the source files are in a completely separate directory from the original JAR file from which they were decompiled. The output directory, too, is completely separate from the location of the original JAR file. Do I need a copy of the original JAR file in the output path for recompiling to work correctly?
I'm making progress, but I'm sure I'm overlooking something "stupid" at this point that's primarily due to my unfamiliarity with the IDE and developing Java applications in general.
UPDATE 2
Looking at another SO question - how to create jar of java package in intelliJ idea - I learned that I have to individually add the necessary files for repackaging into the JAR. However, this brings up the question, what files do I add? The linked question identifies the .class files, but when I go look at the .class files in my working directory, none of those have been updated recently, so it looks like I'm still missing a step somewhere.
Another question this brings up is, are there certain conventions for Java development of which I need to be aware when preparing my environment? I have my output path set to a completely separate folder than any working or production code, so I'm wondering if something in that setup might potentially cause issues.
As I said before, I made a small change to one of the .java files, then tried both the Build Module and Rebuild Project options, but those are still telling me that "All files are up-to-date". Even so, I tried adding just the .class files from under my classes\ directory to my Artifact configuration and tried again to Build Artifact. I got a bit larger file (approx. 5MB), but when I try to execute the JAR, it just doesn't appear to do anything, let alone actually launch the application.
I tried again by adding the root folder of my local copy of the source adding everything the root folder contains. (yes, the directory probably needs some "spring cleaning", but that's for another day)
This time, I got a much larger file this time (approx. 21MB), so I thought I might have fixed the problem. Unfortunately, no such luck. The JAR still doesn't appear to execute.
For reference, the original JAR file from which the code was decompiled is approx. 59MB in size so, either IntelliJ is doing an incredible job with compression, or there's yet another step I haven't yet found. I'm sure this is all a matter of getting my IDE configured correctly, but I just can't seem to find the right combination of settings.

Importing the entire AOSP inside eclipse

I've downloaded the full AOSP source for my device, and was trying to import it inside eclipse to make some changes to the framework (basically it includes an alertDialog that shows when a button in the system bar is pressed and i want to edit it).
I've followed the guide on the AOSP Documentation, and also imported in my build path the android-common_intermediates/javalib.jar but i still get some errors, to be specific I get errors with some fields that should have been defined in one R.java file and I have no idea of how to find the proper R file, i even doubt it's there, maybe is it generated in a second moment or is it in another path and then my compiler script moves it to the right path?
Presuming you heed the warnings in the comments above and still want an answer to the question, I may be able to help. I frequently see similar problems, when I use eclipse to view Android source. There are several projects that are, apparently, not built in response to "make" but that are still included by the .classpath file. My solution is to make them by hand.
Once you've sourced build/envsetup.sh, the command "mm" will build the project in the directory you are in. I start eclipse, find the projects whose resource definitions are missing, cd into them one by one, and use "mm" to build them.
I believe that you will find that they are all projects in the "packages" directory.
So far, this has always worked, for me.

Netbean's Project Structure

Hi I am using Netbeans for quite a while, But still I am not familiar with the Netbeans's project structure and other things like Ant, Maven, different xml files, manifest etc etc.
Can anyone redirect me to any other resources or any book that's gonna give me a very basic insight about what all of this things means and how they all fit together.
EDIT I have googled about each topic but, they give me an idea about what they are. But, I dont understand how they fit together.
Say, in A NB project, there are 4 items, inside the project folder
nbproject (folder)
src (I understand this hold just the packages in a folder-ed fashion)
build.xml
manifest.mf
I dont understand, what this build.xml and manifest.mf file does
inside nbproject
private (hold netbeans preference info)
build-impl.xml
genfiles.properties
project.properties
project.xml
I guess these xml files are some sort of a script, but how they work and when, what the feed into is unknown to me.
build.xml - Contains instructions to build your application. You need to learn about Ant to understand the content.
manifest.mf - Is information that will end up in the jar produced as part of compiling your project. You need to search Java documentation for more explanation. Typically, you don't need to fiddle with these files.
project.properties project.xml - These contain general information about your project in NetBeans (i.e., things which are not really related to the compilation process -> Preferences, etc...).
In general, you don't need to worry about these files. NetBeans takes care of them.

Install [java library] in Eclipse

I just downloaded Eclipse several hours ago, and needed to add Java3D to the classpath. Installing it went without a hitch, but Eclipse can't seem to find the documentation folders so that it can give super-IDE functionality, such as autocomplete and method signatures.
While I know how I would add them individually, this lead me to the question; what is the "correct" way to install a Java library in Eclipse? Is there a special directory format I should follow? Is there a plugin that already did this for me? (The answer to that is yes, but I don't know how to use it, or whether or not it's appropriate).
Thanks!
Edit 1: It seems to me that someone down-voted the question. May I ask why?
Edit 2: So after monkeying around with the JARs, it seems that manually setting the doc path for each JAR in the library seems to be the least-error prone way.
when you add a .JAR(library) to your project in the LIBRARIES tab for your project, you have the option of attaching the javadoc directory for the jar.
So, go to the LIBRARIES tab of the "java build path" for your projects. select your jar. expand the (+) sign and you will see that you can set the javadoc. path.
good luck,
I think I've got it (had the same issue as you). Better late than never.
Go here - http://java3d.java.net/binary-builds.html and download the documentation zip (j3d-1_5_2-api-docs.zip).
Extract the directory anywhere on your HD (Right in the Java3d folder is fine).
Link the Jar's JavaDoc listing to that Folder (java build path >> Libraries >> expand the Jar Listing >> JavaDoc Location >> browse to the folder location, then validate). Do it for each j3d Jar.
That should integrate the J3D Javadoc.
As far as I know (haven't used 3.4 very much thus far), Eclipse has two options for the automatic showing of Javadocs. The first is a JavaDoc jar to attach to the jar file. The second is having the javadoc in a source jar which is attached to the jar to show the source.
A directory, if I recall correctly, will not provide autocompletion of javadoc. However, if you press "F1", you will be able to access the javadoc via the help menu.
You might try placing the documentation directory into a jar file, and attaching it to the jar file and see if that tricks Eclipse.
I cheat; All my java projects are built with maven, so I use maven to generate an eclipse project, with classpaths etc already setup, with a simple 'mvn eclipse:m2eclipse'.

Categories

Resources