I am happy to read Miriam's and Thomas's replies to this question, because it is one that I somewhat unexpectedly faced when I switched from being a professional philosopher to being a professional computer scientist (albeit one with a highly philosophical bent!).
The first time the issue came to light was when I gave a talk to computer and cognitive scientists at the University of Texas at Austin about 20 years ago. One of my hosts was Benjamin Kuipers, a leading researcher in artificial intelligence, who had done groundbreaking work, as a grad student supported by military funding, on "way finding": How to program computers to give and to follow geographic directions. He told me that after he got his Ph.D., he realized that, as a practicing Quaker, he could not in good conscience continue to take military funding, especially if that meant that he would have to fire grad students or postdocs who would be working under his direction if the military asked him to do something against his beliefs and thereby took away his funding. So he changed the entire line of his research to medical applications of AI, which were funded by such organizations as NIH. His full story and arguments in favor of not taking military funding can be found on his website in an article titled "Why Don't I Take Military Funding?" .
The second time the issue came to my attention was when a visitor to our computer science department at the University at Buffalo lectured about autonomous vehicles--automobiles, equipped with AI-programmed computers, that can drive themselves--a project funded by DARPA. During the question session after the presentation, one of my colleagues, Tony Ralston, asked this question: "How can you justify this research when obviously its main purpose is to develop autonomous military vehicles for warfare?" Of great interest to me was that during the reception afterwards, the conversation focused around two groups: students and faculty asking the visitor technical questions, and students and faculty asking Tony Ralston questions about the ethics of militarily-funded research. Another colleague, also a practicing Quaker, suggested that it was OK to take such funding on the grounds that the work she would do was not aimed at killing people--better that the military give their money to her than to someone with other ideas.
My personal decision has been to refuse military support. There have been some negative consequences (lack of funding, etc.), but I feel comfortable with my decision.
But read Kuipers's arguments--they're quite interesting.