Extract eclipse project .classpath dependencies into ant script - eclipse

I have a list of Eclipse projects that I would like to compile based on the existing project configuration.
As far as I can tell, if an ant script could read the .classpath files, it would pretty much be able to infer the project dependencies and perform a "javac" compilation in the right order. This would save time in describing the same dependencies again in the ant script or a Makefile.
The dependencies I am interested in are JAR Dependencies, JRE dependencies, and inter-project dependencies. These are -- as far as I can tell -- part of the .classpath XML file.
Any ideas on how Eclipse project dependencies could used in an ant script?

Right click on your Project -> Export
"General/Ant Buildfiles".
Choose the projects and there you go.
Otherwise...
I have some experience with ant4eclipse and it is a hassle to get it stable.
Go check Buckminster or Maven Tycho for a good solution.

I'm currently using Ivy along with Ant, Eclipse and Maven.
I just love the way Ivy works.
Currently, we have a workspace with many projects using Liferay (with Tomcat) for the front-end and Glassfish for the back-end.
We were looking for a way to manage our dependencies a lot better than how we were doing it.
So I took Ivy, replaced all of the classpaths and deployment dependencies in eclipse and was able to build my application using 1 ivy file per project using either Eclipse or Ant.
Ivy integrates like a charm in ant and builds are done either from the workspace or by command line.
I strongly suggest you look at this avenue. Additionnaly, by adding Artifactory, we have a local repository in which the ivy files look for dependencies. This helps us maintain and rule which jars are to be used by developpers. Once everything is setup, we will build our application nightly using Jenkins and these builds will be using our Artifactory repository to resolve dependencies since our build servers do not have access to the internet.
Hope this helped

If you are running the Ant script only from eclipse using the "External Tools Configurations", you can add the variable ${project_classpath} to the Classpath.
Depending on if you are in a plugin project and dependencies you might need to add the
${eclipse_home}.
In case you get an error launching Variable references empty selection: ${project_classpath}, make sure the ant xml file or at least the project is selected. This is important.

I believe the ant4eclipse project provides support for executing Ant builds based on Eclipse metadata files.
However, in my opinion that is doing things back to front. You shouldn't have your build (Ant) depending on your IDE (Eclipse) environment. But it is useful if you can derive your Eclipse environment from your Ant build.
This is an approach used successfully in a team I worked in. We had a helper Ant target which applied XLST to project build.xml files to transform these into Eclipse .classpath files. Thus the Ant build.xml files were the single configuration point for our projects.

Related

Local Project Dependencies and Maven

I'm converting an ant backed Netbeans project into an Maven project. I've got most of the third party libraries set up in the POM, however now I've run into problems with setting up the local dependencies.
With the previous Netbeans way of doing things, it just added a project reference [with links to the source and jar location, rebuilt the dependency if the depedency's source had been changed and hadn't been compiled]. However I'm not sure how to setup up Maven to emulate this behavior. Is it possible?
Example:
Projects/SharedLibrariesResource [Ant based project]
Projects/WebSite [this is a maven based project]
Projects/Client
In this example the website and client projects don't connect to each other, but they do share the SharedLibrariesResource. Website should compile to produce a War with links to the SharedLibrariesResource
The way I understand the question, the Website maven project depends on the ant SharedLibrariesResource project. When Website is built, it should include the SharedLibrariesResource artifacts. The assumption is SharedLibrariesResources produces a jar artifact.
One way to achieve this is to
install SharedLibrariesResource to your local maven repository each time ant builds it
specify this as a dependency in Website pom.
We can use maven ant tasks to achieve the first.

How to get peer project source in eclipse and maven

creating a parent project with only a pom.xml, and lots of sub projects such as:
my-web
my-core
my-backoffice
etc. is easy, and the sonotype eclipse plugin does most of the work.
However, getting one project to know about the source in the other project seems to be hard. E.g. when you are debugging the my-web project, and step into my-core, eclipse doesnt know where to get the source.
Looking in the Java Build Path in eclipse, the maven plugin has added my-core as a folder under "Web App Libraries". I.e. its not using the my-core-0.0.1.SNAPSHOT.jar or similar, its using the raw java files. Great!
But how to tell maven to tell eclipse to look for the source in the same place?
Im not really sure where to start. Im guessing its possible to get maven to put the source in a special jar using the maven-soure-plugin, but this will usually be out of sync with the actual java files which the web project seems to be using directly.
A quick and dirty solution is to manually Edit the Java Build Path for each project, and add my-core and other dependant projects in the "Projects" tab. Is this best practice? Any other suggestions?
A quick and dirty solution is to
manually Edit the Java Build Path for
each project, and add my-core and
other dependant projects in the
"Projects" tab.
If this doesn't happen automatically you have a configuration problem.
My Guess would be that you have a version mismatch between the pom dependencies and the actual project versions. Or your projects have an unusual name template (m2eclipse resolves projects by their artifactId AFAIK)
Either way, what always helps is in your Debug configuration (Run > Debug Configurations ...) select the Source tab and just Add... the selected projects.

eclipse ant integration and code formatting

I have configured Eclipse to use ant for doing the builds by setting the builders in project properties to point to the ant build script.
The build goes thru fine. However in my eclipse project I have not imported the required jars as a part of the project settings. All of this is done in ant's build.xml.
So in the java files, I get red squiglly lines for all the import packages which eclipse is not able to resolve.
How do I make these squiglly lines go away? One way is to import the required jars in eclipse, but then I am maintaining the project at two places, ant build.xml and eclipse
go to Project Properties/Build Path and enter the jars you rely on there.
You could use Ivy to manage your dependencies. If you configure it properly, you will only be defining the jars in one place but both Eclipse and Ant will be able to see them. The eclipse plug-in is IvyDE.

NetBeans -- Is it possible to bypass the IDE-generated Ant build for an existing project?

I have a Java project with sub-projects that is currently built using NetBeans's IDE-generated Ant scripts. I am converting the entire project to a Maven build.
My Maven build works fine from the command line and loads perfectly in Eclipse. However, the only way I can get the project to load as a Maven project in NetBeans is to delete the Ant scripts, i.e. build.xml and the directory nbproject for each sub-project. It seems that as long as I have the old IDE-generated build files, NetBeans recognizes the project as a NetBeans Java project only, not as a Maven Java project, even though there is also a pom.xml file present.
Short of deleting the IDE-generated build files, is there any way to tell NetBeans to load the project as a Maven project?
I have been told that we want to keep the Ant build for a while during the transition to Maven.
Using NetBeans 6.9.1, Maven 2.2.
Any help would be appreciated.
Thanks
Well, the nb ant project metadata has precedence over occurence of pom.xml file (that's how maven projects are recognized and loaded). The whole precedence order hardwired in the IDE, you could only influence it be uninstalling the j2se ant project type for example.
So, yes. You need to get rid of the ant project metadata before you can open the project as maven project. Depending on how and when you delete the metadata, you might need to restart the IDE as well to get the new stuff loaded.
Have you seen http://wiki.netbeans.org/MavenBestPractices? It indicates that you must install the NetBeans maven plugin first. Perhaps that's why your Maven projects aren't recognized.
I must note that I'm not a NetBeans user anymore!
Here is what I ended up doing:
I wrote an Ant script (ironic, huh?) that, for every subproject of my project, renames the file nbproject/project.xml if it exists to nbproject/nb_project_disabled.xml. If nbproject/nb_project_disabled.xml exists instead, the script renames it back to nbproject/project.xml. In this way, the script toggles the opening of the project as a NetBeans Ant build or as a Maven build.
It would be nice if NetBeans, you know, had a setting to open both kinds of projects. Currently (6.9.1), there is just the "Open Project" command. In Eclipse, there is the command "Import Existing Maven Projects" vs. "Import Existing Project Into Workspace" (i.e. native Eclipse format).

What's the best way to manage dependencies with CounterClockwise/Eclipse?

I have a dependency on clj-record in my CounterClockwise project. What's the best way to manage this? Copy the source code or compile to a JAR and add it as a referenced library?
There are tools to help you:
http://github.com/technomancy/leiningen <- project based
http://github.com/liebke/cljr <- dependencies not project based
http://github.com/ninjudd/cake <- alternative build tool
Assuming your dependencies are available in a Maven repo (like central or clojars), you have a couple of options.
First, if you're using Leiningen, there is an eclipse plugin for it now that will manage project dependencies for you, based on the dependencies you define in your project.clj file. The plugin is in beta now, but has been working great for me so far. (Note that it uses Leiningen 2.0 under the covers, though that detail won't matter for many (most?) simple cases.)
If you're using Maven, the m2eclipse plugin makes it so that the dependencies you declare in your Maven pom.xml are automatically added to your eclipse project's build path, and are therefore available in CCW REPLs and such.
there seems to be no pattern for specifying dependencies apart from hacking the code into your project or building a jar externally.
Of course you can, just as with any java project. While dependency resolution isn't tied into eclipse (yet), once you retrieve the deps (via one of the command line tools nickik listed), you can specify which jars are to be included in the java build path of your eclipse project:
Retrieve the deps via cake, leiningen, etc.
Refresh the eclipse project so you see the deps (usually in the lib directory)
Highlight the jars you want eclipse to know about
Right-click, select Build Path > Add to Build Path
That's it. You can fiddle with the build path by going to the Java Build Path section of the project's properties window.