Was not even Rahab the prostitute justified by works when she received the messengers and sent them out another way?James was among the books spoken against by the early church before finally being admitted to the canon of Scripture. Of the books which were originally disputed, few were criticized in such strong language as James. His teachings on faith and works were suspect, and he was thought to give support to the sects which taught full compliance with Jewish law (including such things as clothing and dietary restrictions).
I understand the concern with the book of James. I'm aware of the part where James looks very much as if he is insisting that there is a certain "earned righteousness" going on, a status before God based on righteous acts that someone could claim as his own. But that's until you consider his examples. I'm not sure that we have really appreciated the shock value of James' choices of examples. He lists only two examples of people justified for what they did. One was a patriarch; the other was a prostitute. She wasn't a reformed prostitute, or a former prostitute; she was a prostitute. When we read about the spies and the prostitute (Joshua chapter 2), we can and should give the spies the benefit of the doubt as to what they were doing with a prostitute; but we cannot extend the same treatment to the prostitute. She was identified as a prostitute, someone known for her sexual immorality.
When the Hebrew spies came to her, she told the authorities that the spies had left, while in fact she was hiding them. This was her righteous act. It was not exactly pure on its own merits; it involved a lie. But it was an act of faith all the same. James could easily have mentioned that she was justified by works when she reformed her life; he did not. He makes his example "the prostitute justified by works".
Anyone who has read the book of James (or the rest of Scripture, for that matter) knows that there is no implication that being a prostitute is a good thing, or even that lying is a good thing. If we consider James' examples, it is difficult to imagine that he is arguing that we earn eternal life or deserve eternal life. He is simply arguing that faith that does nothing is dead. A faith which does not affect how you act is not faith in any meaningful sense at all. However, it is an abuse of the book of James to turn it into an insult to genuine faith; James makes his own point:
I will show you my faith by what I do.