How to get rid of library references issue in netbeans? Java - java

I created a web application and it used several libraries once upon a time. So i added them but later on i found alternative and actually better way to do the same things. So I removed references from my project for those jars and libraries. Everything works fine but when I move the same project to my friend's laptop Netbeans 6.8 simply doesn't let me deploy the project and gives the whole bundle of errors of libraries that I used previously but I don't use it anymore.
I removed all references from build.impl file and then when I deploy it, it works fine. But when I do a clean and build and try to deploy it, build.impl automatically again adds those lines of xml which contains references to libraries and again gives me a whole long list of errors. How do I get rid of this? I am really tired of these silly errors.
Thanks in advance :)

You might think about switching to a build system which does dependency management. Maven is natively supported by Netbeans and solves these problems effectively (you get some new problems in place but thatis another story).
There are others, Ivy, Gradle, ... but are not as integrated in Netbeans.
In the pom.xml you have a listing of dependencies which have their dependencies. Maven will walk the dependency tree and get the jar's from a public repository and stores them in your local repository. 3rd party jars which are not publically available can be stored there too, but your friend will have to add them to his repo too. A little script in the root project folder can do wonders here (or your own shared repo, but that is more heavyweight)
Almost all libs can be removed from the lib folder which reduces the size under version control, speeding it up.
Netbeans, Idea, Eclipse+m2eclipse the synch their files on the POM.
Now maven does have its warts, when you try to do things with it slightly left of what it thinks you should do.

What I would do, is to remove all netbeans specific files and re-create a project from scratch using existing sources on your friends' laptop.

Related

Eclipse has stopped opening the .java, and now it always opens the .class

I am working in Eclipse on a java Spring environment, it is not a new project, I have been working on it for some time, it is composed of several projects, some WEB projects that call other LIB projects. All these projects are linked by means of dependencies in their respective Pom.xml. Until now, when debugging the application, when putting breakpoints, the .java classes of the corresponding project were opened, but now I am not able to, I don't know why now what opens me are the .class, I don't know why now it behaves like this. Any idea?
Do I need to provide more information? I have been working for months now, and it has never happened to me before.
The problem was the following, I have a complex project, which includes several LIB and WEB projects, linked between them by pom.xml
Until now I had only had to use dependencies of the LIBs in the WEB projects.
Now I had a projectA_LIB, a projectB_LIB and a projectB_WEB, I only need the dependency of the projectA_LIB in the projectB_LIB, that is from where I am going to consume it, but that makes that a conflict is created, and for that reason only the RELEASE was opened in the server, and therefore only opened the .class.
The SOLUTION: to declare the dependency of projectA_LIB in projectB_WEB, this way both projects share the same SNAPSHOT and this failure stops occurring, so that degug can be done in the normal way.

How do I make use of a third-party java library github project?

When there's no obvious compiled jars provided on a github project page, I've been downloading the clear code and kludging them into subdirectories in my codebase to make use of third party code (or, most of the time, just not using the code at all). I know that's not the right way to go about this; what is?
There's a popular post about importing github projects into Eclipse:
Importing a GitHub project into Eclipse
...and I've recently learned how to make my own projects depend on one another. Is this the practice, then, to fill up your workspace with projects you're not actually going to work on, so that you can declare dependencies? I remember making dependency references to web resources in the past (itch.io, maybe?) in some configuration, where I didn't have to go download the code. Is there a more elegant solution like that for github?
I'm using Eclipse, and the current library I'd like to use is: https://github.com/FasterXML/jackson
If you're trying to just use FasterXML, the jars are hosted on MvnRepository as well as a lot of other projects.
If a github project's artifact isn't available on MvnRepository or some other online repository you could potentially clone, build the war/jar file yourself, and then manually import it into your project instead of copy and pasting code directly into your project. This would give you access to the library.

Configure Eclipse workspace automatically

I have a eclipse workspace which constitutes of 15 different java projects . To configure the eclipse workspace , every time I need to add the java projects manually and add the dependency and refrences in the java build path.
Adding all the projects and resolving dependency every time becomes a manual and redundant task. I explored on the .classpath inside the every projects which stores the dependency and refrences information.
I would like to automate this redundant process.
Have any one tried doing that , any inputs will be helpful.
I don't need to add same project more than once , but often need to create a new eclipse workspace with new code changes and delivery (I can't take some of the changes in the current work space).In simple terms for e.g if some one need to create eclipse workspace again and again , or multiple people need to create the same workspace for their work . How can we reduce that manual effort?
I am still a little unsure about your motivations but I am going to assume that by new code changes and delivery you mean a different revision/branch of the same code base. For this purpose and for many other reasons, if you are not using source control like SVN or Git, look into it. These tools are priceless and also free.
Eclipse
I don't think this is technically part of your question but I wanted to add it for completeness. If you're implementing the techniques below, it is also handy to have a 'fully loaded eclipse'. I keep a 'fully loaded eclipse' on a network drive somewhere with some plugins pre-loaded so that new additions to the team don't have to download/install the plugins. It's not hard to do since eclipse doesn't need to be 'installed'. You can just copy the eclipse folder to where you want it and run it. Personally I like to include plugins for source control, code style, code coverage and metrics but you should include anything that you use consistently in your project.
The Workspace
To copy an existing workspace (not including any projects, I'll get to that later) all you have to do is copy the .metadata folder from an existing workspace folder to an empty folder that will be your new workspace folder. When you start up eclipse simply choose the new workspace folder and you will have all the same preferences as you had in the other workspace.
I have used this technique before so that when people join a project they can take a copy of a 'clean workspace' I keep on a network drive somewhere that helps them get up and running quickly. Preferably, this 'clean workspace' should not have any preferences that are only personal preferences like having the perspectives setup just the way you like it but should only have preferences like Ant global properties, compiler compliance level, pre-made commonly-used external tool and run configurations etc.
Projects
For the projects themselves, I would recommend checking them into source control including the eclipse .project and .classpath files. The SVN plugin (subclipse) makes it very easy to do this. Then when someone joins your project, all they have to do is check them out as projects in their new 'clean workspace' which is also very easy to do. Since the project you're checking-out already has the .project and .classpath files, all of the dependencies are already setup! Just make sure that all the jars and any other dependencies are checked-in with the projects.
Workspace Setup Procedure
Take a copy of the 'fully loaded eclipse'.
Take a copy of the 'clean workspace'.
Check out the projects into that workspace.
That's it! Your new recruit should be ready to go!
Multiple Code Branches
Now, if I was right to assume that by new code changes and delivery you mean a different branch of the same code base, creating a workspace for a different branch as easy as following the same steps but checking out the required revision or branch instead of the latest version from the trunk. If you don't quite understand what I mean by that, read up on source control.
Cudos
Good on you for taking the time to do this, I have been in projects where it can literally take a day to get setup...
Maybe little late, but stuck into the same problem and found a tool in eclipse marketplace that helps to manage setting up and launching eclipse all time for different branches, new developers or other reasons.
The tool is called yatta.
With this, one can create profiles which can be based on their current running eclipse with all the tools, plugins, workspace, CSM repos and what not.
This profiles can be exported to yatta profile hub which can be public or private and later shared with different developers and can be imported and launched.
You don't say whether you're using a build tool other than Eclipse, but if not you should.
Eclipse is able to parse Ant files to discover the source directories and libraries. And Maven and Gradle can both generate Eclipse project files for you to import.
As a longer-term benefit, using a build tool means that you can easily build and deploy your projects without any need for Eclipse. And it will be easier for new team members to work on the projects, as they won't need to figure out all the dependencies.
If you don't already have people with expertise, I would recommend Maven. It's easy to set up a basic Java build script, and its dependency management features are IMO better than the alternatives. It will, however, force you into its way of doing things, particularly wrt source tree layout.
You should really look into build tools like Maven, Ant, .... Those can generate needed classpath variables for you automatically and can do many more things as well
If you're checking out the projects from CVS / SVN in Eclipse, then it's possible to create a Team Project Set. This is essentially an XML file that will contain a list of projects and their source repository path
It can be exported via File | Export | Team | Team Project Set, and imported into another workspace via File | Import | Team | Team Project Set
There's more information on this feature at this link on Javalobby
Using vagrant it is quite easy to automate setting up an entire desktop development environment.
See the answer I provided to a similar question here, which has links to scripts that automate checking out maven projects, creating an eclipse workspace and importing the projects.

How to make a project "repository/team" ready

I have been working solo on a project for some time, and now, new developers are likely to join the project for various reasons.
I, of course, use a version control software but I am afraid importing my project into Eclipse and making it run might prove a little difficult for new comers, and I want to make it as clean as possible.
When I first took over the project, it took me almost two days to have the project built and run it, I documented every step and fixed the most obvious errors, but not all, and I want the project to run as it is when imported.
The project is a mix of java projects for the backend, a j2ee project for the server and a flex project for the client.
The IDE is going to be Eclipse
The version control software is Perforce
Here are some of the specific problems I have right now, should I fix them, and how ?
Eclipse environment variables are used for libs, all the libs are in a folder in the j2ee project but are used by all the java projects (they have to be set in each IDE the project is imported into)
Runtime JRE is specified in .classpath for each project, so each projects property must be edited when trying to build the project in another environment
Apache server is specified in j2ee project property
To avoid exporting the jars of all the java projects into the j2ee project each time I modify the code, there are linked folders in the j2ee projects, linked to each java project bin folders
For (4) I will probably have to use maven, but is it possible to fix problem (1) (2) and (3) without using maven ?
The alternative is to have a one page set up instruction document
Also do you have any other general or specific advices as to how organize this whole mess.
Thank you
Dependency management is a must - use Maven. If you can't use maven, because you are already using ant, go with Ivy.
Make the project buildable with one click - be int ant build all or mvn package. Maven provides integration with the IDE (via the plugin).
Don't reply on IDE metadata. like .project and .classpath. You can still commit them to ease Eclipse users though, but don't restrict the IDE.
Provide build-on-save. Either using Eclipse WTP, or using the FilSync plugin (it sounds like a hack, but is pretty cool)
Use build profiles (maven provides them automatically) - to create different builds for different environments
It's not always possible to configure everything in your maven (or ant/ivy) scripts. For any additional actions, like installing app server - document then in a single file in the root of your project, describing step by step what should be installed, with what config options, etc. Thus the developers have only one place to look at and follow. The document can (and better) be plain .txt
A sidenote: use Continous Integration - download Hudson or TeamCity and configure it to build a project
From my very recent experience - we had a project we've been working on for 6 months. A colleague of mine had to re-import the project on a new machine. It took him 20 minutes. The project is configured with Maven.

How to manage Libraries/jar files in eclipse?

I might be missing something but how do you manage Java projects in eclipse that need a lot of Jar files. I know maven manages libraries well if there are new updates but maybe I'm missing something, is there a way that eclipse can update new jar files (it would be especially useful for projects using apache-commons, say).
I don't want to sound like asking for a feature request, but I'm looking at if there are ways to keep libraries jar files that a Java project uses to keep them updated automatically the way maven does. With more languages coming with this type of features, finding the right Jar files probably should be easier than this.
Eclipse doesn't manage your jar versions for you, and as far as I know it won't do any auto-updating of jars that have newer versions out there. There's simply not enough information or infrastructure for Eclipse to recognize that a given jar you've added to the classpath is eligible for updating and that you want it updated.
However, there is a Maven plugin for Eclipse called M2Eclipse, which will read a POM and construct a classpath out of jars it finds in the local repository and any remote repositories you've configured. It behaves largely like Maven does in terms of finding the latest version for a given jar (if you've specified a version range in your POM).
You can create user libraries and change their content when new versions are available. That way you do not at least need to change the build path of every project. Or you can load sources of the libraries from their svn and use their trunk version. Remember that you can select multiple projects and svn update them at once.

Categories