• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

Deploying servlets as a war file

 
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I've got a query on the way web applications are deployed. I have an application that has several jsp files and serlvets that are in WEB-INF/classes.

When i deploy the application all i do is do a checkout on CVS, make the changes, rebuild the war using ANT and redeploy manually. This works fine but now i am having some doubts on this approach.

Basicaly if i even change one file i have to rebuild the war file meaning i have to recompile everything. I think this is unecessary. i would like to be able to just recompile the one file and redeploy the one file without having to rebuild the whole war file.

1. How do you deploy your application? If you deploy as a war file, do you recompile everything even if the change is to a single file or a configuration file.

2. Could you provide an example on the approach you use from the point a source file comes out from CVS to the point it get to the production environment. (An example with a single file change would be usefull)

2. Do you use any tool to manage this?

I am thinking that if i change one file i should be able to just compile that one file and move it to the WEB-INF/classes folder into the relevant folder. This might work but is there a better way of doing this instead of moving it manually?


Thanks
 
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Yes
2. Just let Ant do its thing
2. Ant
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:1. Yes
2. Just let Ant do its thing
2. Ant



Hi could you point me to an example?

Thanks
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bascially, this is done by a Build tool (so that the manual errors are avoided to the maximum). The build tools need the inputs to do its thing (as Bear specified above) and that is all!

Ant is one famous tool. Look at http://ant.apache.org . One extra info is : Ant is purely Java based. Hence its 100% compatible with Java application

You can go through the website itself for an excellent tutorial and other useful information.
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

O. Ziggy wrote:Hi could you point me to an example?


Not really -- it's not necessary to show you a huge Ant build script.

Just rebuild the war file using Ant and stop worrying about it.


 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:

O. Ziggy wrote:Hi could you point me to an example?


Not really -- it's not necessary to show you a huge Ant build script.

Just rebuild the war file using Ant and stop worrying about it.





This is what i currently do i just rebuild everything and out pops out a war file.
And it does work without any problems.




What i am trying to get at is, i dont want to recompile every single source file everytime a file changes. Which is what the above is doing.

The reason i dont want to do recompile is because there are several modules/subsystems that make up the war file. Everytime i rebuild a war file i have to run several tests on all modules because everything has been recompiled.

Now if i can only deploy a file for a single module e.g. By just updating the war file with the one file change, i wont have to re-test every other module.

Thanks
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Raghavan Muthu wrote:Bascially, this is done by a Build tool (so that the manual errors are avoided to the maximum). The build tools need the inputs to do its thing (as Bear specified above) and that is all!

Ant is one famous tool. Look at http://ant.apache.org . One extra info is : Ant is purely Java based. Hence its 100% compatible with Java application

You can go through the website itself for an excellent tutorial and other useful information.



I do use Ant. My question was whether it was possible to update a war file using Ant without having to recompile everything.

Thanks
 
Bear Bibeault
Sheriff
Posts: 67750
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ant should only be rebuilding the changed files. Otherwise, there's a problem with your script.
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Ant should only be rebuilding the changed files. Otherwise, there's a problem with your script.



Thats interesting.


There is a clean task that runs first before the compilation.



Do you mean that if i dont delete the class files, the recompilation will not occur? What would happen if a class already exists? Does it not recompile and overwrite?
 
drifter
Posts: 1364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Read the ant manual documentation on Javac task:

The source and destination directory will be recursively scanned for Java source files to compile. Only Java files that have no corresponding .class file or where the class file is older than the .java file will be compiled.

 
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There are also some stubble cases (specially if you use static constants) that might create a problem if you don't do a complete build.

Personally I would prefer doing a clean build - at least for the script that is creating the war file for production.
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As i think, if you simply run ANT with out clean command, it builds only modified classes, other classes remain untouched. But this is not a good practice if you are building it for your production. you should clean it every time before creating WAR file. because some times even modified classes do not get any change (i have faced many times)
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks all for the responses.

In what situations might it cause a problem to not go for a clean rebuild? How is this likely to cause a problem. Any example?

Thanks
 
gaurav kant
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
as i think, you can use ANT with out "clean" command when you are not doing any serious deployment like testing or when work is going on (i.e. coding and you are just checking your code working). But you must go for complete clean and build your project when you want to create WAR for production or deployment on server.
Please correct me if m wrong at any point
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gaurav kant wrote: But you must go for complete clean and build your project when you want to create WAR for production or deployment on server.
Please correct me if m wrong at any point



What is the reason for this? If a file has been compiled why is there a need to recompile it? Especially if it is for a different package/module why recompile it?
 
gaurav kant
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no need to recompile a file that has been compiled earlier. This is for the sake of surety that you have latest classes in you build. Suppose you have a vast number of files and you had made some changes in say 60 or 70 files and if you by chance forget to copy 1 or 2 files in your build, what would be the result ? For this we just compile all the files not to leave even a single file and i think there is no harm to do this just before production. what do you think?

one more thing. ANT compiles only those file that have been modified and never touch unmodified files. clean means delete all those files that you have specified in command (in ant script) from build and run ant command by which ant can recompile and place into your build all those deleted files just to ensure that you have latest code in build.
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

O. Ziggy wrote:Thanks all for the responses.

In what situations might it cause a problem to not go for a clean rebuild? How is this likely to cause a problem. Any example?

Thanks



Also there is one particular case that i can think of that might cause a problem.

Lets say you have a File called Constants.java with a line like,
public static final myName="Sam";

and you are using this constant in another file say xyz.java
print(Constants.myName);

Now you go and make a change to Constants.java and change 'Sam' to 'O.Ziggy'.

Now lets say you run the compile task. This means that your constants file would be recompiled since it has a newer timestamp than the class file. However if the xyz.java file would not be recompiled. (I'm not 100% - does ant work intelligently and re-compile all dependent files?)

If you run such application the see the output - you'll see 'Sam' getting printed instead of 'O.Ziggy'.

--

Another possible pain area. Say you change your system time for some reason while working on a java file. You save the file and run your build script - Since the timestamp of the saved file is older than the time stamp of the compiled file - it won't be re-compiled.

--

Some of the problems I mentioned are stretched too for - but that's why I prefer doing a clean & then build for any production going code - Added safety against some weird and hard to debug cases!
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

gaurav kant wrote:There is no need to recompile a file that has been compiled earlier. This is for the sake of surety that you have latest classes in you build. Suppose you have a vast number of files and you had made some changes in say 60 or 70 files and if you by chance forget to copy 1 or 2 files in your build, what would be the result ? For this we just compile all the files not to leave even a single file and i think there is no harm to do this just before production. what do you think?

one more thing. ANT compiles only those file that have been modified and never touch unmodified files. clean means delete all those files that you have specified in command (in ant script) from build and run ant command by which ant can recompile and place into your build all those deleted files just to ensure that you have latest code in build.



Yes i am thinking for situations where i have only modified one or two files. In situations where i have modified hundreds of files then it wouldnt make sense to do a partial compilation.

Basically i have 3 modules in my application one of which is dependent on by the other two. What i am thinking of doing is if the change is on only one module then there shouldnt be any problems just recompiling the file in that one module. If a file from each module is changed then i should rebuild everything.

 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:

O. Ziggy wrote:Thanks all for the responses.

In what situations might it cause a problem to not go for a clean rebuild? How is this likely to cause a problem. Any example?

Thanks



Also there is one particular case that i can think of that might cause a problem.

Lets say you have a File called Constants.java with a line like,
public static final myName="Sam";

and you are using this constant in another file say xyz.java
print(Constants.myName);

Now you go and make a change to Constants.java and change 'Sam' to 'O.Ziggy'.

Now lets say you run the compile task. This means that your constants file would be recompiled since it has a newer timestamp than the class file. However if the xyz.java file would not be recompiled. (I'm not 100% - does ant work intelligently and re-compile all dependent files?)

If you run such application the see the output - you'll see 'Sam' getting printed instead of 'O.Ziggy'.

--

Another possible pain area. Say you change your system time for some reason while working on a java file. You save the file and run your build script - Since the timestamp of the saved file is older than the time stamp of the compiled file - it won't be re-compiled.

--

Some of the problems I mentioned are stretched too for - but that's why I prefer doing a clean & then build for any production going code - Added safety against some weird and hard to debug cases!



This is interesting and i didnt realise that would happen. Ill have to test it out and see.
What is the reason behind it? Surely if i recompile Constants.java the class file will be updated which is what xyz.java will be using?
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:

O. Ziggy wrote:Thanks all for the responses.

In what situations might it cause a problem to not go for a clean rebuild? How is this likely to cause a problem. Any example?

Thanks



Also there is one particular case that i can think of that might cause a problem.

Lets say you have a File called Constants.java with a line like,
public static final myName="Sam";

and you are using this constant in another file say xyz.java
print(Constants.myName);

Now you go and make a change to Constants.java and change 'Sam' to 'O.Ziggy'.

Now lets say you run the compile task. This means that your constants file would be recompiled since it has a newer timestamp than the class file. However if the xyz.java file would not be recompiled. (I'm not 100% - does ant work intelligently and re-compile all dependent files?)

If you run such application the see the output - you'll see 'Sam' getting printed instead of 'O.Ziggy'.

--

Another possible pain area. Say you change your system time for some reason while working on a java file. You save the file and run your build script - Since the timestamp of the saved file is older than the time stamp of the compiled file - it won't be re-compiled.

--

Some of the problems I mentioned are stretched too for - but that's why I prefer doing a clean & then build for any production going code - Added safety against some weird and hard to debug cases!




Hi,

I did try the test for the statics using the following classes




The output after compiling both files was



I then made a change to TestClass and recompiled just TestClass and the output was




So it looks like the change does get picked up without having to recompile the dependant class. Is there any situation where this wont work?
 
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

O. Ziggy wrote:Is there any situation where this wont work?



It would not work for static final, as Sam Mercs wrote above
 
Misha Ver
Ranch Hand
Posts: 470
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

O. Ziggy wrote:2. Could you provide an example on the approach you use from the point a source file comes out from CVS to the point it get to the production environment. (An example with a single file change would be usefull)



In case you need to change one file for production

1) Get source code from CVS
2) Do the change
3) Test the change
4) Commit updated source code back to CVS
5) Get updated source code from CVS
6) Compile, build and deploy to production

All this could be done with ANT.
 
Saifuddin Merchant
Ranch Hand
Posts: 608
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Misha Ver wrote:

O. Ziggy wrote:Is there any situation where this wont work?



It would not work for static final, as Sam Mercs wrote above



And I am not kidding - something similar had really happened - Fortunately for us not in production.
(Build wasn't used that time - just the class file was replaced manually -- but final static's are in-lined at compile time -- You can get some more info on my blog -- http://twisters.quiz4j.com/2009/09/puzzle-53-statically-speaking.html!!)

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By default, Greedy compiler doesn't re-compile the dependent classes. You can turn off this feature by setting ‘false’ to includeDestClasses attribute

Please refer this link for further details
http://ant.apache.org/manual/CoreTasks/javac.html
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok i have changed the above example to change the "name" property to a static final and yes you are right i had to recompile both files for the second file to detect the change.



the output




What exactly is the technical reason for this?
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:

Misha Ver wrote:

O. Ziggy wrote:Is there any situation where this wont work?



It would not work for static final, as Sam Mercs wrote above



And I am not kidding - something similar had really happened - Fortunately for us not in production.
(Build wasn't used that time - just the class file was replaced manually -- but final static's are in-lined at compile time -- You can get some more info on my blog -- http://twisters.quiz4j.com/2009/09/puzzle-53-statically-speaking.html!!)



Hi Sam, Please repost the URL as that is pointing to a 404 page.

Thanks
 
O. Ziggy
Ranch Hand
Posts: 430
Android VI Editor Debian
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Sam Mercs wrote:

Misha Ver wrote:

O. Ziggy wrote:Is there any situation where this wont work?



It would not work for static final, as Sam Mercs wrote above



And I am not kidding - something similar had really happened - Fortunately for us not in production.
(Build wasn't used that time - just the class file was replaced manually -- but final static's are in-lined at compile time -- You can get some more info on my blog -- http://twisters.quiz4j.com/2009/09/puzzle-53-statically-speaking.html!!)



What is the technical reason for this behaviour?
(That link does not work)
 
Those who dance are thought mad by those who hear not the music. This tiny ad plays the bagpipes:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic