-1

Recently I was forced into using Eclipse because of TFS plugins:

I have a few projects that I'm converting to Eclipse projects from Netbeans. Some of these projects reference each other. After starting to convert these projects I quickly found that Eclipse doesn't want to jar projects post-build. So I used an build.xml and created a new 'builder' for each project (whose bright idea was it to not allow me to reuse builders across multiple projects?). After I got all that working I was sitting back thinking about how I would go about building for deployments, and it occured to me that eclipse is not including any of the referenced assemblies in the build output directory. This sucks, because manually creating lib folders and copying over all of the jar files which are required will be error prone, and time consuming. So heres the question. Is there any reasonable way to set up a builder, or property on an eclipse project such that when I build it, it will create a 'dist' directory, containing both the jar'ed project classes, and a lib folder with all of the referenced jars attached to the project?

Franz Kafka
  • 10,623
  • 20
  • 93
  • 149
Mark W
  • 2,791
  • 1
  • 21
  • 44
  • 5
    Switch to maven. Don't rely on your IDE to do the work of a build tool. – Boris the Spider Apr 10 '13 at 20:34
  • Why not, every other IDE ive ever used does this by default? – Mark W Apr 10 '13 at 20:36
  • 6
    Because your code should be able to be built independently of the IDE in which it was written. Netbeans actually uses Ant/Maven in the background and Eclipse can do so too with the correct plugins. – Boris the Spider Apr 10 '13 at 20:39
  • Well thats not even close to an answer I was looking for. – Mark W Apr 10 '13 at 20:42
  • Also I would like to point out that I am already using ANT to create the jar file. – Mark W Apr 10 '13 at 20:44
  • Then maybe [this](http://stackoverflow.com/questions/3373429/eclipse-ant-plugin) will help? – Boris the Spider Apr 10 '13 at 20:46
  • Why don't you create an ant target to do this? – Jean Waghetti Apr 10 '13 at 20:46
  • I would but I dont know how to resolve a list of dependencies using ANT. having a simple MkDir / Copy (or set of them) in a build XML is a viable solution, provided I could figure out how to detect the dependencies. – Mark W Apr 10 '13 at 20:48
  • 1
    Well the references are stored in the .classpath file for the project, im considering just writing a tool which when given the directory of an eclipse project, will parse this XML and create the dist directory for you, then use a builder to execute that app with the projects working directory post build. I looked into XMLProperty task for ant, but I dont know how I would handle multiple references. If anyone has a quick solution, maybe an example build XML that accomplishes something similar to this, it would be appreciated. – Mark W Apr 10 '13 at 21:05
  • For the record, shame on you who upvoted bmorris591's comments. Switch to maven is akin to saying "I dont understand your problem, but you should use something entirely new, which you dont understand to solve a relatively simple problem".... shame on you – Mark W Apr 10 '13 at 21:38
  • 2
    @MarkW: starting a question by criticizing the tool you're requesting help for, and then criticizing everyone who advises you to do the *right* thing and use a build tool to build your project is not the best way to ask for help. Using a build tool independent from the IDE is a best practice, unanymously recognized as such. The fact that all your previous projects don't use one just shows that these projects have been managed in an amateurish way. Learn Gradle, Maven or Ant. – JB Nizet Apr 10 '13 at 21:44
  • I am using a build tool ANT the question wasnt about Maven... read the damn OP – Mark W Apr 10 '13 at 21:54
  • 1
    If you're using ant, then all the dependencies should be in some lib directory in the project itself, and you shouldn't have to parse an XML file to know where they are. And if you're using ant, you should already have these dependencies in a classpath property to be able to compile your project. If you don't have them, then you're not using ant to build your project. If you don't like having all the dependencies in the project itself, then use a build tool which handles dependencies from a repository, like Ant+Ivy, Gradle or Maven. – JB Nizet Apr 10 '13 at 22:02
  • I've read the OP. Twice. And I still think that you want to avoid using a build tool to build your project, although this is what you should be doing. Eclipse doesn't do that for you because that's not the job of an IDE, but the job of a build tool. – JB Nizet Apr 10 '13 at 22:03

1 Answers1

5

Is there any reasonable way to set up a builder, or property on an eclipse project such that when I build it, it will create a 'dist' directory, containing both the jar'ed project classes, and a lib folder with all of the referenced jars attached to the project?

Yes, right-click on the Project and select Export. Type "jar" into the search box and select Runnable JAR file. In the export dialog, select the "Copy required libraries..." option. There should also be an option there to save this export as an Ant script.

I dont know how to resolve a list of dependencies using ANT

Next, you should consider using Ivy. This will add dependency management to your build script. There's probably some learning curve here, but these tutorials should help.

martinez314
  • 12,162
  • 5
  • 36
  • 63
  • Most excellent, someone who understands the question and provided a useful answer :D I will look into Ivy. Thanks! – Mark W Apr 10 '13 at 22:03
  • Well I gave this a shot, but it didnt quite satisfy. I think I can make this work, and probably use the script it generates to learn a bit more about ant. The problem Im having now is that this is not an executable jar, nor will it ever be. Its a class library for use in an IVR, by way of javascript (at least the project im working on converting now is). With the jar file option there isnt an option to copy require libraries, and for the executable jar it wants an entry point or the wizard wont proceed. Im sure I can figure the rest out though, thanks again. – Mark W Apr 10 '13 at 22:13