I have two projects in NetBeans that are dependent upon each other, and one references the JAR of the other one. Currently it copies all the JARs it is dependent upon into the dist/lib directory, but I don't want it to copy them--I want it to directly reference the other project's JAR from that dist directory.
How do I do this through NetBeans without manually editing the classpath?
You might want to look into using Maven for your projects. It's a tool that gives you more control over the build process and clarifies your projects' dependencies. The latest versions of Netbeans come bundled with Maven support.
I actually think that this is not possible. The "connection" between projects is for within Netbeans only, while the dist folder is, as its abbreviation suggests, for distribution.
That means that you should be able to simply copy the contents of the dist folder anywhere else, even other machines, and it should work as is (provided there is Java installed, and other such "tiny" dependencies).
If the main JAR in your dist folder would just reference the other dist folder you would not be able to run in on some other machine, unless you would copy the other dist folder in the exact location, etc. which is simply not a good thing to do or to have to do.
So, either go with Maven as MrDrews suggested or accept the libs in dist as a must.
Related
I"m going to have to re-organize my directory/folder structure in order to use git with Eclipse, since repo's are not supposed to be located within the workspace.
Being a git newbie I'd like some confirmation that my intended structure makes sense before I start re-organizing and init'ing repos.
My current workspace includes an Android project, a GAE/J project, some common code shared between them. Aside from some 3rd party libraries, my projects are closely related so I'm going to put them into a single repo.
Here is my proposed structure:
root_dir/
workspace/
.metadata
.git (<--- main git repo for my projects)
GAE_Project/
.project
src/war/etc.
Android_prject/
.project
src/bin/etc.
Shared_Code_Project/
.project
src/etc.
3rd_Party_Lib_Project/
.git (<--- has its own repo)
.project
src/bin/etc.
Based your proposed structure, it would seem that all the projects under workspace is in one repository. Your proposed structure is fine with one caveat that I can see. You may have to ignore the third party project because it is located under workspace (which is the Git repository).
Eclipse projects do not necessarily have to be located within the workspace directory. It can be located anywhere on your system. It may be better to place the third party projects in a different directory.
As long as your repos are outside of your workspace, it doesn't matter where they are relative to the workspace. In your example root_dir contains the workspace and your projects, and I wanted to point out that the workspace could be at /some/random/path and your projects could be /at/totally/different/path, it shouldn't matter where they are relative to each other.
I keep my local repos in ~/dev/git/ in unix and /c/dev/git in Windows.
I keep my workspaces wherever Eclipse wants me to keep them, which is the first directory it pops up for me, sometimes ~/Documents/workspace, or %USERDIR%\workspace. Usually I don't even know where my workspace is, and it doesn't really matter, because the important and interesting part is where my code is.
I've got a Java project hosted on github. My project needs few custom .jar files to be imported. Since I was to be able to run the project anywhere, I want to include jar files inside the git repository. Is there a recommended, conventional place where jar files should be kept, e.g. lib dir of the root project directory?
PS
At the moment I'm not using Maven and I'm not considering it.
The usual case is actually a lib folder. Or webapp/WEB-INF/lib it is a web application.
But ths usual case is bad. I would not put jars in my source management system. If you need to add references to another project, you might consider having a look a git submodules (though you are using Github).
We use Maven to for our web application and we used to use Ant.
When deploying in ANT, you can set it to not use war files and to only copy newly files into the deploy folder. This is a tremendous time saver when working on your local machine.
In Maven, I'd like it to work the same way. Whether there is a change in the main project or one of its dependencies, I'd like it to just recompile and copy the newly changed files. Is there a way to do this?
If you "deploy" by copying files from your project directory to, say, Tomcat webapps directory - do the same in Maven by means of maven-antrun-plugin.
Otherwise, I would recommend to use either cargo-maven2-plugin or tomcat7-maven-plugin.
I'm using the Eclipse "Export... Runnable jar file" feature to package up my Clojure+Java application for deployment.
This works great, magically including various resources and Clojure source files etc.
The one issue I have is that various libraries I have get included multiple times from the "lib" directory dependant projects, e.g. I get four versions of the Clojure jar file due to other projects on the build path that also use Clojure.
This issue is needlessly tripling the size of my .jar file!
Is there any way to easily eliminate these duplicates other than manually deleting from the generated jar?
If there is a natural dependency graph to your projects, I would change your eclipse project settings such that only one project has the jar on the build path and it exports (by export I mean from the "Order and Export" tab in the Configure Build Path dialog) that jar for other projects to see. The other projects then have that "core" project on the build path. I believe this should naturally take care of your problem.
Edit
One comment I have is that having a jar within a jar is rarely a good idea. I would either reconsider packaging it all into a single jar (unless the point of the main file of the jar is to extract its own contents into a folder) or maybe explore the possibility of using the "Extract required libraries into generated JAR" option.
In Eclipse how do I copy the Java Build Path to a different workspace?
Somebody somewhere wrote that if you copy the project then you have copied the build path also. This doesn't seem to be the case.
I've tried copying the entire workspace to a new directory. Opening Eclipse and pointing it to the new directory has all the projects and source files but the build path for my project is empty. It doesn't even have the basic Java source files to build against (java.lang.Object).
Eclipse 3.3.0 (Europa)
Any ideas?
The build path is stored in a file named .classpath in the project's root directory. I don't know of any different way, and copying the directory should also copy that file, of course. How do you copy the project? What OS?
Be very careful...
The workspace itself is just metadata in eclipse that points to your project folders. If the projects are not actually in the workspace directory, you aren't actually copying them, just references to them.
This can happen if you use "Import existing projects into workspace" that are folders in the file system without the "copy into workspace" checkbox checked, or if you create a project using an existing directory.
If you copy that workspace to a different machine, the projecs won't be there.
If you want to share projects, your best bet would be to use source/version control (subversion, for example) and have everyone hook up to the same repository.
Another note on the build paths -- if you have a java project reference an external jar, the absolute path of that jar is stored in the build path. This can be bad if other people who are sharing that project have the jar in a different location on their machine. If this happens, you should look into using Classpath variables or user libraries in eclipse.
Can you comment more on what you're attempting to do when you do the copy?