tags:

views:

258

answers:

4

I am working on a small team of web application developers. We edit JSPs in Eclipse on our own machines and then move them over to a shared application server to test the changes. I have an Ant script that will take ALL the JSPs on my machine and move them over to the application server, but will only overwrite JSPs if the ones on my machine are "newer". This works well most of the time, but not all of the time. Our update method doesn't preserve file change day/times, so it is possible that an Update on my machine will set the file day/time to now instead of when the file was actually last changed. If someone else worked on that file 1 hour ago (but hasn't committed the changes yet), then the older file on my PC will actually have a newer date. So when I run the Ant script it will overwrite their changes with an older file.

What I am looking for is an easy way to just move the file I am currently working on. Is there a way to specify the "current" file in an Ant script? Or an easy way to move the current file within Eclipse? Perhaps a good plugin to do this kind of stuff? I could go out to Windows Explorer to separately move the file, but I would much prefer to be able to do it from within Eclipse.

A: 

How would Ant know what file was "current"? It has no way of knowing.

You could pass the name of the file into your Ant script (by taking advantage of the fact that any arguments you pass into Ant with -D are automatically parameters in your script)...

ant -Dfile=myfile.jsp update

and have your script look something like...

<copy file=${myfile} todir="blah"/>

...but it would probably be a pain to constantly type in the name of the file on the commandline.

Honestly, the type of problem you've described are inevitable when you have multiple developers sharing an environment. I think that a better approach for you and your team long-term is to have each developer work/test on a local application server instance, before the code is promoted. This removes all headaches, bottlenecks, and scheduling trouble in sharing an app server with other people.

matt b
A: 

You should really use source control any time you have multiple people working on the same thing (well, you should use it any time regardless, but that's a different conversation). This way, when conflicts like this occur, the tool will know and make someone perform the merge so that no one's changes get lost. Then, the test server can run on a clean checkout from source, and each developer can also test the full application locally, because everyone's changes will be instantly available to them through the source repository.

Chris Marasti-Georg
We are using source control. The problem here was not a lack of source control. The problem is that multiple developers have to share a single application server.
Shane
Then why don't you use it to get everyone's latest on the test machine? You are much more likely to forget to copy something if you are relying on a manual process like the one you have accepted.
Chris Marasti-Georg
+1  A: 

Add a target to your ant build file to copy a single jsp using a command line property definition as @matt b described.

Create a new external tool launch profile and use the "String Substitution Preferences" to pass in the reference to the active file in the editor (resource_name).

See Eclipse Help | Java Development User Guide | Reference | Preferences | Run/Debug | Launching | String Substitution

Ken Gentle
This worked. Thanks! For anyone else who wants to do something similar, I used an External Tool Configuration Argument of: -Dresource_name=${resource_name}
Shane
Thanks for the report back, Shane. Answer edited to include the correct reference.
Ken Gentle
A: 

I suggest you to use source control. I prefer Subversion. You can use CruiseControl to make the build automatically whenever someone commits new code.

mrzl