Is it possible to set up a Java project so that it can be built without relying on an IDE? If it is, where can I find any information on how to set up this sort of project?
Bonus points if it's possible to pull this off by writing a single makefile.
> Is it possible to set up a Java project so that it can be built without
> relying on an IDE? If it is, where can I find any information on how to set
> up this sort of project?
> Bonus points if it's possible to pull this off by writing a single makefile.
I've always used a combination of Emacs and make. Given your "single makefile" question, though, I suspect you may have more sophisticated needs than I do. Care to elaborate?
> Is it possible to set up a Java project so that it can be built without
> relying on an IDE? If it is, where can I find any information on how to set
> up this sort of project?
> Bonus points if it's possible to pull this off by writing a single makefile.
> Thanks in advance,
> Rui Maciel
I use Vim to edit, and a batch file to compile and jar up the classes. And often a batch file to start them as well.
David Lamb <dal...@cs.queensu.ca> wrote:
> On 22/04/2012 11:15 AM, Rui Maciel wrote:
>> Is it possible to set up a Java project so that it can be built without
>> relying on an IDE? If it is, where can I find any information on how to set
>> up this sort of project?
>> Bonus points if it's possible to pull this off by writing a single makefile.
> I've always used a combination of Emacs and make. Given your "single > makefile" question, though, I suspect you may have more sophisticated > needs than I do. Care to elaborate?
Not sure if I clarify the OP, or "hijack" his thread, but
suppose you created a working environment in eclipse consisting
of a couple of projects, then what tools are there to create
e.g. an "ant" or "maven"-script from eclipse's own project-
control files, that would allow a headless machine to build
a runnable jar-file with all project-dependencies just like
eclipse does?
Even if the OP didn't mean that, I'd still like to know - so
much for hijacking ;)
> Is it possible to set up a Java project so that it can be built without
> relying on an IDE? If it is, where can I find any information on how to set
> up this sort of project?
> Bonus points if it's possible to pull this off by writing a single makefile.
Very few rely on their IDE to build for serious projects.
They use tools like Ant or Maven to build with.
You can also write the code without an IDE, but why not utilize
the extra support you get from a Java aware IDE.
> Is it possible to set up a Java project so that it can be built
> without relying on an IDE? If it is, where can I find any
> information on how to set up this sort of project?
> Bonus points if it's possible to pull this off by writing a single
> makefile.
Yes of course. The devil will be in the details however.
> On 4/22/2012 11:15 AM, Rui Maciel wrote:
>> Is it possible to set up a Java project so that it can be built without
>> relying on an IDE? If it is, where can I find any information on how to set
>> up this sort of project?
>> Bonus points if it's possible to pull this off by writing a single makefile.
> Very few rely on their IDE to build for serious projects.
> They use tools like Ant or Maven to build with.
> You can also write the code without an IDE, but why not utilize
> the extra support you get from a Java aware IDE.
OP: Be careful that your problem statement doesn't limit your solution space.
Arne knew that makefiles are not literally the best build mechanism for Java, so unlike those others who specifically dicussed make with you, he gave you the idiomatically Java equivalent.
I'm not aware of any prevalence of make in the Java build-and-deployment world.
Ant and Maven are the two most standard mechanisms. Real-life Java build-and-deployment systems are edifices of scripts (shell, Python, Ruby, ...), continuous-integration (CI) platforms, Ant and/or Maven, intelligently-crafted logging (of the builds, not just the program runs), and often much more.
As a solo practitioner you can readily put together a decent ecosystem with open-source tools, e.g., for Java EE:
git version-control repository
Jenkins continuous-integration framework
Ant build system
bash
Python
Junit unit test framework
EasyMock mock objects for testing code
FindBugs find bugs in source code
Glassfish application server
Geronimo, JBoss
Tomcat, Jetty simpler app server
JSPs, no EJBs, JMX, etc., unless plugins
Apache Web Server HTTP server - all kinds of proxy magic, etc.
EclipseLink, OpenJPA JPA - Java Persistence API)
Postgres RDBMS
Your favorite editor(s) and IDE(s)
You certainly do not need an IDE for any of that, and quite frankly, none of your build and test stuff should use any IDE files directly, nor should most editor- or IDE-specific files be in the trunk of your code repository.
With such a suite of tools, I still would add NetBeans or Eclipse (among the free options) or Aptana (based on Eclipse) as an IDE. While an IDE is not essential to system development, it is very helpful.
They not only help with code development, they make great dashboards to manage your libraries, databases, servers, logs, test frameworks, and other tools, and the interactions amongst them. We programmers tend to monomaniacally focus only on how IDEs help code production. They are also very handy, particularly for the solo stages (developer workstation or individual consultant's production box), to manage the myriad operations matters.
On Sun, 22 Apr 2012 16:15:30 +0100, Rui Maciel wrote:
> Is it possible to set up a Java project so that it can be built without
> relying on an IDE? If it is, where can I find any information on how to
> set up this sort of project?
Simple. Do just as you would for, say, a C project but use Ant instead of make.
> Bonus points if it's possible to pull this off by writing a single
> makefile.
Its the norm to use a single build.xml (ant's equivalent of Makefile) to do everything that make will, i.e. build, clean the source structure, install the jarfiles. The only significant differences are that its working with a package hierarchy rather than a set of modules in separate directories and that it will usually run javadocs too.
This is how I usually work with Java projects, often over an ssh session.
-- martin@ | Martin Gregorie
gregorie. | Essex, UK
org |
> On 04/22/2012 09:36 AM, Arne Vajhøj wrote:
>> On 4/22/2012 11:15 AM, Rui Maciel wrote:
>>> Is it possible to set up a Java project so that it can be built without
>>> relying on an IDE? If it is, where can I find any information on how
>>> to set
>>> up this sort of project?
>>> Bonus points if it's possible to pull this off by writing a single
>>> makefile.
>> Very few rely on their IDE to build for serious projects.
>> They use tools like Ant or Maven to build with.
>> You can also write the code without an IDE, but why not utilize
>> the extra support you get from a Java aware IDE.
> OP: Be careful that your problem statement doesn't limit your solution
> space.
> Arne knew that makefiles are not literally the best build mechanism for
> Java, so unlike those others who specifically dicussed make with you, he
> gave you the idiomatically Java equivalent.
> I'm not aware of any prevalence of make in the Java build-and-deployment
> world.
make and Java is like square form and wheels. Not a good mix.
> Is it possible to set up a Java project so that it can be built without
> relying on an IDE? If it is, where can I find any information on how to set
> up this sort of project?
> Bonus points if it's possible to pull this off by writing a single makefile.
Though I use Eclipse for any project of more than a few source files, I don't use it for building. The projects include the necessary scripts to be built stand-alone.
I did explore trying to get 'make' to handle per-file dependencies, and I haven't totally given up yet, but for now I've settled for per-jar dependencies. I have a pre-packaged 'make' include file, and tell it that jar foo depends upon the 'API' of jar bar, and it works out rules that allow compilation of foo to be necessary only if any of foo's sources have changed (of course), or the API of bar has changed - so bar can change internally without necessarily triggering recompilation of foo.
Within a jar, nothing special is going on - it's a clean build.
A jar's API is derived from the class files immediately after compilation. I originally used javap and gawk for this, but javap's text output is not a consistent format from one vendor to the next, and the gawk processing is slow, so I eventually wrote a Java program to parse the class files directly. It's a little faster, and should be more broadly compatible. However, I think it's still substantially slower than simply doing clean builds on all jars unconditionally.
> On 4/22/2012 2:35 PM, Lew wrote:
>> On 04/22/2012 09:36 AM, Arne Vajhøj wrote:
>>> On 4/22/2012 11:15 AM, Rui Maciel wrote:
>>>> Is it possible to set up a Java project so that it can be built without
>>>> relying on an IDE? If it is, where can I find any information on how
>>>> to set
>>>> up this sort of project?
>>>> Bonus points if it's possible to pull this off by writing a single
>>>> makefile.
>>> Very few rely on their IDE to build for serious projects.
>>> They use tools like Ant or Maven to build with.
>>> You can also write the code without an IDE, but why not utilize
>>> the extra support you get from a Java aware IDE.
>> OP: Be careful that your problem statement doesn't limit your solution
>> space.
>> Arne knew that makefiles are not literally the best build mechanism for
>> Java, so unlike those others who specifically dicussed make with you, he
>> gave you the idiomatically Java equivalent.
>> I'm not aware of any prevalence of make in the Java build-and-deployment
>> world.
> make and Java is like square form and wheels. Not a good mix.
it does technically work though, and may make some sense, say, if one is also building a bunch of C code (say, as part of a JNI wrapper for native code or similar), or is generally part of a larger project for which make is already used.
> On 4/22/2012 2:21 PM, Arne Vajhøj wrote:
>> On 4/22/2012 2:35 PM, Lew wrote:
>>> On 04/22/2012 09:36 AM, Arne Vajhøj wrote:
>>>> On 4/22/2012 11:15 AM, Rui Maciel wrote:
>>>>> Is it possible to set up a Java project so that it can be built
>>>>> without
>>>>> relying on an IDE? If it is, where can I find any information on how
>>>>> to set
>>>>> up this sort of project?
>>>>> Bonus points if it's possible to pull this off by writing a single
>>>>> makefile.
>>>> Very few rely on their IDE to build for serious projects.
>>>> They use tools like Ant or Maven to build with.
>>>> You can also write the code without an IDE, but why not utilize
>>>> the extra support you get from a Java aware IDE.
>>> OP: Be careful that your problem statement doesn't limit your solution
>>> space.
>>> Arne knew that makefiles are not literally the best build mechanism for
>>> Java, so unlike those others who specifically dicussed make with you, he
>>> gave you the idiomatically Java equivalent.
>>> I'm not aware of any prevalence of make in the Java build-and-deployment
>>> world.
>> make and Java is like square form and wheels. Not a good mix.
> it does technically work though, and may make some sense, say, if one is
> also building a bunch of C code (say, as part of a JNI wrapper for
> native code or similar), or is generally part of a larger project for
> which make is already used.
I would rather call ant from make or make from ant to handle those
situations.
> On 4/22/2012 7:15 PM, BGB wrote:
>> On 4/22/2012 2:21 PM, Arne Vajhøj wrote:
>>> On 4/22/2012 2:35 PM, Lew wrote:
>>>> On 04/22/2012 09:36 AM, Arne Vajhøj wrote:
>>>>> On 4/22/2012 11:15 AM, Rui Maciel wrote:
>>>>>> Is it possible to set up a Java project so that it can be built
>>>>>> without
>>>>>> relying on an IDE? If it is, where can I find any information on how
>>>>>> to set
>>>>>> up this sort of project?
>>>>>> Bonus points if it's possible to pull this off by writing a single
>>>>>> makefile.
>>>>> Very few rely on their IDE to build for serious projects.
>>>>> They use tools like Ant or Maven to build with.
>>>>> You can also write the code without an IDE, but why not utilize
>>>>> the extra support you get from a Java aware IDE.
>>>> OP: Be careful that your problem statement doesn't limit your solution
>>>> space.
>>>> Arne knew that makefiles are not literally the best build mechanism for
>>>> Java, so unlike those others who specifically dicussed make with
>>>> you, he
>>>> gave you the idiomatically Java equivalent.
>>>> I'm not aware of any prevalence of make in the Java
>>>> build-and-deployment
>>>> world.
>>> make and Java is like square form and wheels. Not a good mix.
>> it does technically work though, and may make some sense, say, if one is
>> also building a bunch of C code (say, as part of a JNI wrapper for
>> native code or similar), or is generally part of a larger project for
>> which make is already used.
> I would rather call ant from make or make from ant to handle those
> situations.
yes, this works as well.
I guess it is probably whichever is more convenient.
>>> it does technically work though, and may make some sense, say, if one is
>>> also building a bunch of C code (say, as part of a JNI wrapper for
>>> native code or similar), or is generally part of a larger project for
>>> which make is already used.
>> I would rather call ant from make or make from ant to handle those
>> situations.
> yes, this works as well.
> I guess it is probably whichever is more convenient.
I found that using one good tool for everything is better than
mixing things.
Also, gnumake can do so many more things than just build source
code. I use it to update my html files and pdf files from
Latex sources, and other such things.
As long as the idea that drives the tool is: Perform this action
to update these prerequisites that this target depends on, then better
to use one tool that does this better and for many other things, not
just .java files.
In my tree, I have .f, .f90, .c, .c++, .java, .tex, and many
other files that I want to 'update' in my tree.
Using one tool for all, is better, because one becomes better
at using this one tool, and things are integrated better.
gnumake+bash is pretty much all what I need.
I tried ant, and found that I am doing the same thing I
am already doing in my Makefile, just had to use different
syntax. (I also did not like XML syntax). Also looked at Ruby
script, and few other things. They all pretty much try to do
what Make allready does but using different syntax.
It is very easy to use gnumake to build Java and make jar files and
all. Here is a link showing Makefile for Java from the best book
on gnumake "Managing Projects with GNU make" by Robert Mecklenburg
As others said. If you are using an IDE with its own build
system. It is better to have your own makefile to build
your tree, independent of what the IDE has. This way, if
you changed IDE, or move your tree somewhere else where
this IDE is not available, you can still build your tree
any where.
On Sun, 22 Apr 2012 16:15:30 +0100, Rui Maciel <rui.mac...@gmail.com>
wrote, quoted or indirectly quoted someone who said :
>Is it possible to set up a Java project so that it can be built without >relying on an IDE? If it is, where can I find any information on how to set >up this sort of project?
see http://mindprod.com/jgloss/ant.html -- Roedy Green Canadian Mind Products
http://mindprod.com When you were a child, if you did your own experiment
to see if it was better to put to cocoa into your cup first
or the hot milk first, then you likely have the programmer gene..
> On 4/23/2012 2:06 AM, Leif Roar Moldskred wrote:
>> Nasser M. Abbasi<n...@12000.org> wrote:
>>> I found that using one good tool for everything is better than
>>> mixing things.
>> [SNIP]
>>> In my tree, I have .f, .f90, .c, .c++, .java, .tex, and many
>>> other files that I want to 'update' in my tree.
>> You see no contradiction here?
> What contradiction?
> I use Makefile to build all the my programs?
> Do you mean, why I use different languages? And I should
> use one programming language? is that what you mean?
> If I can find one programming language that meets all my
> programming needs, then I'll use that one language, but
> have not found one yet.
yeah...
in my case, my project currently uses 5 different programming languages (to a greater or lesser degree, list does not include makefiles), several smaller/special purpose DSLs, and an assortment of specialized file-formats.
> Do you mean, why I use different languages? And I should
> use one programming language? is that what you mean?
> If I can find one programming language that meets all my
> programming needs, then I'll use that one language, but
> have not found one yet.
I'm just saying that "using one good tool for everything" is no more
(nor less) the right approach when it comes to build systems than when
it comes to programming languages.
> Is it possible to set up a Java project so that it can be built without
> relying on an IDE? If it is, where can I find any information on how to set
> up this sort of project?
> Bonus points if it's possible to pull this off by writing a single makefile.
> Thanks in advance,
> Rui Maciel
for small scale projects, a command line works perfectly well.
I would run commands such as: javac net/virtualinfinity/myproject/Main.java
Once in a while I'd have to do a rm `find . | grep ".class$"` and the like to do a "clean" build.
>>>> it does technically work though, and may make some sense, say, if
>>>> one is
>>>> also building a bunch of C code (say, as part of a JNI wrapper for
>>>> native code or similar), or is generally part of a larger project for
>>>> which make is already used.
>>> I would rather call ant from make or make from ant to handle those
>>> situations.
>> yes, this works as well.
>> I guess it is probably whichever is more convenient.
> I found that using one good tool for everything is better than
> mixing things.
Which, if followed religiously, will lead you into a situation where it can get really awkward to do things with tool A which would be extremely easy with tool B.
> Also, gnumake can do so many more things than just build source
> code. I use it to update my html files and pdf files from
> Latex sources, and other such things.
No wonder because make doesn't do *any* of these things. Make evaluates timestamps along dependencies (mostly between files) and invokes other programs that do all the work. GNU make additionally has an extremely large database of predefined rules, has functions and other capabilities.
> As long as the idea that drives the tool is: Perform this action
> to update these prerequisites that this target depends on, then better
> to use one tool that does this better and for many other things, not
> just .java files.
Interestingly GNU make's large built in rule database does not contain anything related to compiling Java. How do you create your Makefiles in a way as to invoke javac only for those files which have changed - especially in light of the fact that one Java source file might create multiple .class files?
> In my tree, I have .f, .f90, .c, .c++, .java, .tex, and many
> other files that I want to 'update' in my tree.
> Using one tool for all, is better, because one becomes better
> at using this one tool, and things are integrated better.
> gnumake+bash is pretty much all what I need.
I'm with Leif: if you drink your own cool aid you should be throwing out all those languages and resort to language [ ] only.
> I tried ant, and found that I am doing the same thing I
> am already doing in my Makefile, just had to use different
> syntax. (I also did not like XML syntax). Also looked at Ruby
> script, and few other things. They all pretty much try to do
> what Make allready does but using different syntax.
I disagree: ant is very different from make. Ant has built in tasks and knows itself how to accomplish them. You can even teach it more tasks via its extension interface. ant rules for building Java projects are almost certainly a lot simpler than the same for make - as that example proves.
> It is very easy to use gnumake to build Java and make jar files and
> all. Here is a link showing Makefile for Java from the best book
> on gnumake "Managing Projects with GNU make" by Robert Mecklenburg
I did not see the advertized Makefile example but found this gem (quoting from that page):
"Code declared to be within the a.b.c package would be compiled to class files in the a/b/c directory. This means that make's normal algorithm for associating a binary file with its source fails."
I am counting 200+ lines in this Makefile. It inefficiently invokes javac on all Java sources and defines functions for things that ant can do out of the box. As a consequence you have to search in different locations to find out which packages go into which jar file. The same is probably 15% of the lines as an ant file. Sorry, but that example is no advertisement for using make to build Java projects.
> Chapter 9 is all about using make for build Java.
> As others said. If you are using an IDE with its own build
> system. It is better to have your own makefile to build
> your tree, independent of what the IDE has. This way, if
> you changed IDE, or move your tree somewhere else where
> this IDE is not available, you can still build your tree
> any where.
Modern IDE's usually have integration with ant and / or maven and will happily generate appropriate build files.
Robert Klemme wrote:
> On 23.04.2012 06:57, Nasser M. Abbasi wrote:
>> I found that using one good tool for everything is better than
>> mixing things.
> Which, if followed religiously, will lead you into a situation where it
> can get really awkward to do things with tool A which would be extremely
> easy with tool B.
This isn't necessarily a problem, particularly if a person is already familiar with tool A while being completely unaware that tool B even existed.
Then there is a significant issue with being forced to learn an entirely new tool just because there might be a single thing that it might be able to handle in a simpler way, and then being forced to deal with a significant list of things where the new tool fails to perform. Unfortunately, this appears to be an undistinguishing feature of every automated build system that has been released.
>> Also, gnumake can do so many more things than just build source
>> code. I use it to update my html files and pdf files from
>> Latex sources, and other such things.
> No wonder because make doesn't do *any* of these things. Make evaluates
> timestamps along dependencies (mostly between files) and invokes other
> programs that do all the work. GNU make additionally has an extremely
> large database of predefined rules, has functions and other capabilities.
There is nothing wrong with this. In fact, I see it as an extremelly valuable feature. It's a pain in the neck to shoe-horn custom build rules to an automated build system which was developed with them as an afterthought.
>> As long as the idea that drives the tool is: Perform this action
>> to update these prerequisites that this target depends on, then better
>> to use one tool that does this better and for many other things, not
>> just .java files.
> Interestingly GNU make's large built in rule database does not contain
> anything related to compiling Java. How do you create your Makefiles in
> a way as to invoke javac only for those files which have changed -
> especially in light of the fact that one Java source file might create
> multiple .class files?
David Lamb wrote:
> I've always used a combination of Emacs and make. Given your "single
> makefile" question, though, I suspect you may have more sophisticated
> needs than I do. Care to elaborate?
There is nothing sophisticated in my needs. The only reason I mentioned makefiles is that I'm already familiar with them. I would prefer to develop a skill which I already have than being forced to start from scratch by being forced to use another tool.
Daniel Pitts wrote:
> Why not use an IDE though? They provide so much!
They also tend to be inferior in a considerable number of aspects, particularly when compared with the features provided by some text editors.
Between being forced to stick with an IDE and managing the build process by hand, the latter option sounds a lot better.
That's a good find, and I appreciate you pointing it out to this list. It's actually been several years since I've dealt with make's build rules in any way, and a small refresher wouldn't be bad for me.
However, in the Java world, ant is the standard build program. (Or maven; however I haven't got into maven yet.) There's no way you can avoid ant. Any project that exists in Java, any deliverable you get from an outside contractor or firm, will invariably use ant. It is simply "the standard."
So I'd recommend you learn to use it. First, it avoids fumbling around making your own static rules, and second you will have to learn it eventually, regardless. So it might as well be on your own terms, and on your own schedule.
I found ant's use of XML off-putting at first as well, but it becomes easier to deal with, and more natural to write, after you've hand written a couple of basic project definitions. Just go for it, and don't sweat the new stuff you'll learn.