Using XOM with NetBeans - java

I am attempting to install XOM so I can use it in my Java apps. The only problem is, I don't know where I can place it so NetBeans can find it. It would make sense to put it where the other .classes files are, but I can't seem to find them either.
The README file for XOM says to install it to the Classpath variable, but I don't know what that is.
So, how do I install XOM, and what is "Classpath"?

You can use the NetBeans Library Manager (Tools|Libraries) to create a new library, add the Xom jar file (and all dependencies) to it and use this library in a new Java project.
To do this, use the Properties dialog for the project, navigate to the libraries page, and choose your new Xom library using "Add Library..."

Related

How to add a .zip library to Eclipse

I need to add an external library named ControlFX in my project. Here is the official link to download it: https://github.com/controlsfx/controlsfx
The issue is that this file is .zip type. So, I'm really confused about how can I add it as a library to my project (it doesn't include.jar files inside).
Any idea, please?
Check out How to add external library properly in Eclipse? if you want to add it manually, but it's very much not advised if you don't know what you're doing.
If you want to learn the proper way to use external resources look into how to use Maven or Gradle to incorporate libraries into your projects.

What is the "right" way to add libraries on Netbeans?

I'm a using Netbeans 8.1 to code in Java, when I want to add an external library (such as XStream, JDateChooser, etc) I find the .jar online and I add it to my project through the right clicking in Libraries --> add JAR/Folder.
After this I write my code and everything works fine until I finish my project and I want to export it into a .jar with Clean and Build
I think this maybe because I give an absolute path to the libaray instead of a relative one but I'm not sure.
PS: The library that I'm having trouble with is XStream 1.4.7
All the libraries included should pack in a jar file after build. The simplest approach is to click right on your project, select Properties and The project properties. In the new window opened find Categories and Libraries. The in the right side you may see the button Add library/JAR. Probably it's the same way.
Also you can create a Maven project and import all the libraries through dependencies.

Browse JDK Source Code in Eclipse Like GrepCode

I like the way you can browse the source code of a library in GrepCode. Is there any way I can do the same in Eclipse?
I know that I can open the declaration of a class and look through it, but there seems to be no way I can search for something (a method, for example) in the Declaration window.
What I am really looking for is a way to browse the source code of the standard library just like I browse the source code of a class I am writing. It doesn't necessarily have to be the source that ships along with my JDK; I am happy to look at some other version as well.
What would be the best way to achieve this? Will I have to download OpenJDK and add it as a project in Eclipse?
You can install Java Decompiler plugin for Eclipse, such as JD-Eclipse
You could also use the src.zip file that ships alongside Oracle's JDK (located for example at something similar to C:\Program Files\Java\jdk{version} in Windows) and load it on Eclipse build path as a library (src.zip contains sources files for the java., javax. and some org.* packages, but not for com.sun.* packages)
Or you could download the whole bundle of source code for JDK at http://download.java.net/openjdk/jdk6/ (for JDK 1.6) and do the same
I think one of the good alternative for what you are looking for is zGrepCode. It allows you to browse Java Open Source projects as you are doing it in Eclipse by providing interlinking.
http://zgrepcode.com
Here is the place I found about this wonderful free tool.
https://dzone.com/articles/grepcode-is-down-whats-next?fromrel=true
Actually I just went with the Search feature in Eclipse. Since I wanted to look at the source code for classes in the JRE libraries, I just do Search --> Java and select the appropriate options (see the attached screenshot).
I would think that this Search feature could also be used to search in the libraries included in your build path too.
Pretty sure that m2eclipse allows source browsing, see: Get source jar files attached to Eclipse for Maven-managed dependencies
Intellij also has a maven plugin available that allows browsing.

How to install jar library?

I've downloaded the ANTLR Java runtime libraries. It's a jar file. It contains "org.antlr.runtime". Where do I put it so that the Java compiler can find it? Do I need to extract it? I'm using NetBeans (for now), if relevant.
Assuming you can find your jdk folder, You can move the .jar file into the jdk\jre\lib\ext folder, where other .jar files are placed. After doing so, NetBeans should be able to run files with access to the library
For NetBeans you go to your Projects Tab and then right-click on the project you want the library added to then click Properties. Go to the Libraries bullet then on the right side click on Add JAR/Folder. No need to extract it. All you have to do is right click in the editor window and click Fix Imports.
For use outside of NetBeans you have to add it to your Java classpath.
For java command line you need to add it to your class path however in Netbeans you just need to add it as a library. It can be anywhere. Google to find out how to do these things.
In fact in netbeans, you can just say you need this in your maven project and it will do the download of the jar and its source/documentation as required.

Dependency bundle (jar-files/sources/API docs) in Eclipse

I'm developing various in-house extensions for JIRA, the issue tracker we use. So far I worked with Netbeans and everything worked like a charm. However, now I need to switch to Eclipse and I'm having struggle setting up the environment for this development project.
First a clarification why I'm using the approach I'm describing here: building JIRA (in an IDE) is not easily done and I'm absolutely not interested in wasting my time to figure out how to do it. Besides, I don't need to build it, I just want to develop extensions and be able to use the IDE's auto-completion and help support (API docs). Atlassian (the company that develops JIRA) provides a "development" package, but it's just a sorry excuse rather than a real solution.
What I did with Netbeans was to create a library bundle with all relevant jar-files, the Java source files and the API documentation. This way I could use auto-completion, "jump to" the source and the API docs would pop-up when needed.
It seems Eclipse doesn't offer such a functionality, at least I couldn't figure out how to add the sources and the API docs to a "User Library" (which I'd then add as a dependency to my project just as with Netbeans).
My next approach was to create a separate project that holds all the stuff and mark that project as a dependency of my project. This works, but it leaves me with another issue: now I get 37k errors reported (all within the "dependency project"). As said, correctly setting up building for this dependency is a major struggle and not my original goal, therefore I'd happily ignore these errors. Automatic building is turned off and changing the "Errors/Warnings" settings under "Java Compiler" for the project didn't change a thing, so I'm kind of lost now.
Okay, let me try to phrase this as questions:
Maybe I just didn't find it: Is there a way to create a dependency bundle (call it whatever you want) in Eclipse that -- besides just carrying jar-files -- gives me the ability to use the API docs and "jump to" the declaration in the sources?
If not, what's the common practice to do in such a situation?
If the "dependency project" solution is the way to go, how can I completely disable compiler errors for that project?
Check this for illustration with images
Add the source code for jar
Add the Javadoc for a jar
Or just right-click on the jar file in the Package Explorer view. Select "Properties" then set the according paths in the "Java Source Attachment" and the "Javadoc Location" field.
When you create user libs via window->preferences->java-build path->user libraries you can specify which jar you need, sources (in archive or folder) && javadoc (from internet, or local, or from archive). Then you can use this lib in your project via context menu on project->Build path->add library->user library-> choose your lib.
Here you acn pick up more info Eclipse help

Categories