I'm using some apache libraries in my code. At the moment I'm hitting a variety of problems that I need to debug. However the problem is when I pass data into one of said Apache libraries, when I try to step into the method call using netbeans it simply does the processing in the background and doesn't step into the code I want to view.
Does anyone know how I configure the IDE so that I can debug the apache code as well? Right now I just associate the JAR's with the project by adding them as libraries.
You need to attach a source jar (e.g. commons-lang-2.4-sources.jar) to your dependency, instructions here
I should also recommend using Maven2 to manage your project dependencies, I've not used Netbeans for at least 5 years, but both Eclipse & IntelliJ have Maven plugins which will import all your dependencies and link them to sources/javadoc jars automatically.
Related
I've written programs in several languages and have tutored students in computer science, but just starting to learn Java on my MacBook. Regarding this question, I'd be happy with any answer that points me to available information or tutorials that address my question; I'm capable of understanding advanced things.
I've been searching for the right IDE for me as well as something I can use with my students, and I've tried IntelliJ, Eclipse, and VS Code. Along the way I've installed external JARs to provide extra capabilities, such as Apache Commons.
Things are getting confusing. I've lost track of how I got to the present state in each IDE. I'd like to understand better how to know the overall Java environment that any given project is using on each of these IDEs, including any external JARs and where they are located. And I'd like to know if they borrow from the Java system environment.
My goal is to understand how my own system got to the way its currently configured, to update my configuration on a project-by-project basis, and to help my students get a matching configuration.
I'd also like advice on the right way, or simplest/cleanest way, to install external JARs.
Maven
Question: I'd also like advice on the right way, or simplest/cleanest way, to install external JARs.
If you really wanna work in a organised way and wanna focus completely on coding rather than looking for dependencies to work with , then try building your projects with Apache Maven. The magic wand of Maven projects are pom.xml file where all magic happens depending upon your wish.
Maven is a build automation tool used primarily for Java projects. Maven addresses two aspects of building software:
Describes and manages how software is built.
Describes and manages dependencies (various libraries used by your code).
Why Maven:
De facto standard
Able to compile, test, pack and distribute source code ( different Goals)
Robust dependency management (Most important from my point of view)
Extensible via plugin
Good community support and many fan boys around.
The big 3 IDEs (IntelliJ, NetBeans, and Eclipse) all having good
support for Maven, letting you use Maven as a substitute for their
own proprietary project definition and build process.
Maven famously caches all of its dependencies in the ~/.m2
directory, which is sometimes called the local Maven repository.
Maven local repository keeps your project's all dependencies (library jars,
plugin jars etc.). When you run a Maven build, then Maven automatically
downloads all the dependency jars into the local repository. It helps to
avoid references to dependencies stored on remote machine every time a
project is build.
You can simply deploy your project as JAR, WAR, or EAR file and use it on different IDEs or as standalone.
All IDEs need a way to know your project's dependencies. You can either tell them that yourself or let a build tool do that.
Manual dependency handling: by adding the jars to your project. This is probably the fastest way when working on a small project, with one developer, on a specific IDE, with few dependencies. Usually when telling the IDE that this .jar is a dependency of your project, the IDE stores that reference to a project-specific file (eg. in Eclipse the .classpath file which you can edit with a txt editor and see the dependencies yourself). However, it kind of locks your application to your IDE. Most IDEs have cross-IDE support for import and migration, but using both IDEs at the same time can be confusing when a dependency is added to one and has to be repetitively added to other as well. Furthermore, your dependencies have dependencies on their own. By adding manually your jars you are responsible to find and download their own dependencies as well.
Use a build tool: There are 3 standard such tools right now: Apache Ant with Ivy, Apache Maven and Gradle. All of them have support in the major IDEs for Java: IntelliJ IDEA, Eclipse and NetBeans. All of them use some extra build-tool specific files to store your project's configuration and subsequently configure your IDE and the IDE-specific files. That way, your project becomes IDE-agnostic, the IDE outsources the dependency handling to the build tool. These tools will download any direct or transitive dependencies of your project in a local directory or you can compile jars in a specified folder. From those, Ant is the oldest (with Ivy adding dependency handling support), Maven was developed after that and Gradle is the newest and probably the most flexible. In production however Maven is by far the most established one right now.
It would be also useful to look up the Standard Directory Layout. If you adhere to that, it will be easier to work/start with either Maven or Gradle.
Finally, you can search and find most of the free libraries in Maven-Central where conveniently their Ivy/Maven/Gradle script is added as well for you to use on your build-tool script. In many cases a .jar is provided as well if you prefer to manually add it as a dependency.
Regarding VS Code, I think it supports these tools through plugins but I'm not sure.
I've just started Android development coming from a strong web and iOS development background. One thing I don't really understand is how to best import third party open source projects in my source.
In web development most projects has a bower package and in iOS most open source projects has a podspec that makes it really easy to import. But I don't see this as much in Java projects.
So, now I want to use jess-anders/two-way-gridview. What would be the best way to get this into my own app. I would very much like to avoid having to mix the third party source code and res files with my own.
I use IntelliJ IDEA.
If I understand correctly, then what you need is Maven, which is used for dependency management in Java projects.
You define your dependencies inside a pom.xml file. Here is an example of such pom file (see the < dependencies > tag ).
Generally, when you need to use a 3rd-party library, you look it up in the Maven Central Repository, from which Maven looksup by default when you specify a dependency, and copy the < dependency > element into you pom.xml file.
NOTE: I don't know why, but right now the Maven site is down. You'll have to check back later. In the meantime try looking for some tutorials on google.
If you need to import libraries which aren't in the Maven Repo, then you need to go to File>Project Structure>Libraries and click on the '+' symbol and add your .jar files from the your filesystem.
You need to do this on every machine that needs to work on this project, and also include the jars in your final apk. I do not konw how to do the latter.
I am a newbie, Please bear if i am silly. I have created a java project in eclipse which uses includes multiple jars like Apache Commons DBCP, dbutils, commons pool and some mysql jdbc driver. Instead of adding these jar directly to the project, i want to create different user libraries one for each and add the respective jars and its source and its javadoc into it.
So i created the user libraries and added the respective things in it and added those user libraries into project. Everything is fine upto that. But I want to work with same project in my home machine and when i imported that into eclipse in my home machine, those user libraries are empty. I undestood eclipse stores those info in the workspace and in my new workspace i am not able to use that libraries.
So i tried creating a new folder "lib" in the project and added all those jar into that folder which will always go with the project and when i creating the user libraries, this time while adding the jars i selected the option add jar-> workspace->lib->... and added those jar into the user library assuming that the lib folder is within the project and so the user libraries stay accros the workspaace but i failed again. Its working out. So how can use the libraries in different workspaces without importing and exporting... Please help me...
I do know ${project_loc} will give the project location. So is there anything i can say ${project_loc}/lib/commons-dbcp.jar to the user libraries.
I think you are viewing Package Explore
Open the Project Explorer instead.
I'd rather suggest to look at Apache Maven, which does allow you to configure dependencies for your project and build it (almost) everywhere.
It also has some plugins for integrate with Eclipse, so you can share your project easily without copying libraries manually.
I installed ZK Studio plugin for eclipse and have used it to create a new ZK based webapp. However, inside my /WebContent/WEB-INF/lib folder, there are a number of .jar files that were included automatically (beloning to the zk framework). I'm assuming this was done by selecting "create a new ZK project". However, when it comes time to deploy this to the webserver, I only want to include the libraries I actually need and use. Is there a way of finding that information out so I can shrink the size of my .WAR file?
Thanks!
These are called "transitive dependencies" - libraries that required by libraries that you use. The libraries that you use can't work without their dependencies, so ultimately you need all of the jars in WEB-INF/lib.
Maven is a dependency-management tool that tells you what are the transitive dependencies, (via a dependency graph). I would recommend using maven, although it would require some effort to introduce it in the current project.
Take a look at The Content of ZK Binary Distribution
then you can remove the library you don't need :)
I created a Web application in Netbeans 6.5. Now I want to use the Joda Time library. I want to share this library via subversion, because I don't want my team mates to be dependend on some Netbeans configuration.
Just to get the project working, I first added the library to the Netbeans library (Tools->Library). This worked OK. The JAR is added to the classpath, and is also deployed.
But when I create a shared library (via Project Properties->Libraries->Browse/New Libraries Folder), the JAR is not in the classpath. I get the error message package org.joda.time does not exist on the code import org.joda.time.*.
Any ideas?
What is the scope of this library? Is this library used for just this particular web-application?
If so, can we put the library in the WEB-INF/lib directory and check that into subversion as well?
Libraries in the WEB-INF/lib directory should be automatically added to the classpath of the project.
Here is what I did:
Tools -> Library -> New Library...
called the library joda-time
add added the joda-time-1.6.jar file to it
Project -> Properties -> Libraries
under the compile tab
Add library...
selected joda-time
(Edit, think I see the issue now - but perhaps not).
You need to add the library to the compile libraries AND add it to the distribution libraries. Or am I misunderstanding the question?
when creating a 'new project', there is an option to enable 'dedicated folder for libraries'. That way, the libraries will also be committed to the repository and your peer developer can checkout your project with all the libraries, your project has dependencies upon, thereby eliminating netbeans configuration bound.
In scenario where a project depends on JARs which can be placed in different locations for different users, a named IDE variable can be used.
http://wiki.netbeans.org/NewAndNoteWorthyNB65#section-NewAndNoteWorthyNB65-VariableBasedPathsInJ2SEJ2EEProjects
Another option would be to use the Maven plugin which already works quite well in NetBeans 6.5. A Intranet repository for the Artifact Jar files could be placed on a file server, or managed through a Maven Proxy like Nexus.
This blog entry describes a hack that worked in NetBeans 5. I don't know if it will work in NetBeans 6.5. I also don't know if this will work if you are building files nightly on a server.
http://blogs.oracle.com/gjmurphy/entry/using_netbeans_free-form_projects_as
I remember setting up shared libraries like this 8 years ago in JBuilder. I wish Netbeans had it by now.