I am relatively new to Eclipse and Java and have a number of tasks I would like to script when I am going to do a software release. They include running JAXB to generate source from an XSD, running javadoc to update the documentation and creating jars for distribution. What is the best way of scripting these tasks...Ant? I need the scripts to be called from our nightly build environment which is CrusieControl.net. We use both C# and Java in house but we have a single build environment on CruiseControl.net
Thanks for any help you can give.
Take a look at here :
How to execute the JAXB compiler from ANT
Javadoc task
Run ant from cc.net
I'll say go for it. We have a similar environment without java, but with tones of tools. Ant is a very useful weapon in your arsenal.
Related
I do not understand the purpose of ant. I read the introduction, but am missing the big picture. I know the following (or at least that I want to use them),
Java
jdbc
hibernate
jsp
servlet container like Tomcat
But I don't see how ant fits in.
Is there some all comprehensive tutorial that tells me how to put all this together?
Why would I want ant? What is the alternative if I don't have ant?
EDIT: So is this sort of the compiling part of its Visual Studio counterpart?
Ant is used as a build system. You do not have to use it--in fact there are quite a few better systems but since ant was one of the first it's still likely to be very common. It generally is used to compile your java files, create wars and often even put the .war files onto the tomcats.
Maven is bigger and tries to do a lot more, but it's also rather strict in it's format and quite heavy--but it's quite common these days as well. Maven can gather all your dependencies automatically which is nice, with ant you still have to download everything yourself.
There are others, but you get the idea.
Response to comment:
I don't use visual studio, but I think it is more limited. For instance, Eclipse can build all your java files into a jar or execute them directly (in fact, it uses ant internally). If you wanted to take your visual stuido "Build configuration" and put it into another tool (Perhaps an automated build system like Jenkins) that doesn't rely on visual studio directly, can you do so?
I guess Ant is the way we code our builds--it's portable betweeen many tools. Visual Studio would be cleaner to "create" your build, but "Exporting" the ability to build would be more difficult (if even possible).
Also ant is portable across operating systems as well as tools. We can switch from Eclipse to Netbeans to IntelliJ without touching our build toolchain.
How would you completely remove visual studio and replace it with slickedit, emacs or vi (if that was your thing, which I'm sure it's not) without starting over from scratch with your build?
For any web application to work you need to package or build all your java code with all the libraries into an web application archive to accomplish this task we need to some tool or library to package into the correct format and some of the libraries which can achieve this is
Apache Ant and Apache Maven
There some good discussions about Ant vs Maven in SO.
You need ant to build the project. Well you can build project using IDE like eclipse etc. But for production purpose and big projects, it always advisable to some build script like ant. Its a script where you can customize what you want to build and what not. you can define what is the output should be like war/jar/ear etc
Other alternative is Maven which is very prevalent and standard now a days
I have a vague memory that I've seen a build system for Java or some other JVM lang which you could run in continous mode (so to speak). This would make the build system run in the background, watching the source dir for changes. As soon as a source file changes, the build system kicks in and re-runs relevant parts of the build process to produce a fresh artifact.
Ring any bells?
Thanks
Is it the gradle daemon?
This keeps gradle running in the background because it has long start up times - and scans the file system to identify when files change.
There are lots of engines that support continual checkouts/building/testing (e.g. Jenkins nee Hudson, CruiseControl, TeamCity etc.).
If you're looking at JVM languages other than Java, then (for example) the Maven Scala plugin supports continuous building and testing upon file changes. e.g.
$ mvn scala:cctest
will run the compile/test cycle in a loop watching for source changes and acting upon them.
If your build tool or language doesn't support this natively, it's trivial to write a shell script to watch a directory structure and execute another script/tool upon change. See this SO question for solutions.
I figured out that it was in fact sbt that I meant. There is another question here on SO relating to how to build Java projects: Use SBT to Build Pure Java Project. Thanks everyone for your help.
If no ant or other build tool, can eclipse itself handle large project?
While eclipse can handle large projects, it is in most cases necessary to use an IDE-independant build tool, like ant or maven:
should be able to produce deployable artifact with one command
should not be tied to a particular IDE. Team members may choose different IDEs
should be usable from command line and continuous integration tools
Without a build tool you lose:
reproducability: Builds from your machine will likely look different from you coworkers. You might have a different plugin installed, a different JDK configured ... a build tool will minimize these dependencies.
continuous integration: No way to do that without a build too.
IDE independence. What if somebody wants to use Netbeans or IDEA because it would help tremendously with the next task?
I am working on an Java assignment for a software design course in my university. It's not really complicated and it includes some classes, interfaces and jUnit test cases. We were now told we should supply a build.xml file as an input for an ant builder. I have never heard of, or used ant before. I also saw Eclipse supports it.
My questions are - What does build.xml do? How does Eclipse builds my project and why not do the same instead of using ant? And most important - how to create this file with Eclipse?
Thanks.
Ant is a build tool based on Java. It is very powerful, and integrates with various other tools you might need to build any imaginable Java application. It is very useful when deploying a Continunous Integration environment with a Continuous Build server.
You are building within Eclipse, and your build process is bound to your IDE - which is perfectly fine for a one-man project but might prove unefficient for a team project. Also, with Ant, you can have a complex build including multiple components and intricate dependencies done in a single step, including unit tests.
You can either create your Ant build from scratch (which is the best way, but it takes quite a while). Otherwise, you can create it with Eclipse using the File/Export menu (under General, select Ant buildfiles).
You should definitely know how to crate a build.xml file from scratch, just so you know what Eclipse does behind the scenes.
I taught a Java class a while ago where I explained the basics of ant.
I need to automate packing of Java EE projects into EAR archive in Eclipse. The most easy way, I think, is using Ant script. But writing of Ant from start is routine and long task. Is there a way to generate Ant script based on my actions in eclipse (like macros in MS Office)?
Or, maybe, exists easier way to do this?
Thanks!
There is nothing I know of that will generate an Ant build file for you. I don't think it is that difficult or long to create an Ant build file. If you have never done it before there is obviously a learning curve to it.
What I think you might be asking is can you have a build file that uses the same build configuration as your Eclipse project so that you don't have to setup your classpaths yourself then the answer is yes. I have never done this myself but I see this link seems to be offering that:
ant4eclipse
Just another thought... You can use Maven instead of Ant. using Maven you can specify packaging type and you don't need to write ant script. This will also lead to simplified build management of your app application.
But writing of Ant from start is
routine and long task.
Ridiculous. It's not a long task. And yes, it is routine. Do it once and forget it.
Laziness is a good trait for a programmer, but this is going too far.