When St. Paul writes about “works of the law” he was referring to the Jewish ceremonial and ritual laws. He was not referring to the moral law, the 10 commandments.
Jesus taught that to enter heaven we must believe everything God has revealed (have faith) and obey His teachings. When we do this we receive the grace of salvation, and we grow in this grace. If we don’t obey, but commit mortal sin then we lose this grace. If we die unrepentant for our mortal sins, then we end up in hell.
When a Jew becomes a Christian, he is no longer under the law of Moses, but he is under the law of Christ, as taught by His Church.
Just as when someone moves his residence from New York to Florida, after a while he is no longer under the laws of New York, but he is under the laws of Florida. The laws did not change, but the authority of the laws over the person changed.
Now the controversey started when some Jewish Christians known as the Judiazers **said that faith and obedience to God is not enough. **They said that in addition to believing and obeying Jesus, Christians also had to follow the ceremonial and ritual laws of the Law of Moses in order to be saved, (that is circumcision and the Jewish feast days. These were known as the “works of the law”. Notice that God did not say Christians had to follow the Law of Moses, Jesus did not say Christians had follow the Law of Moses, the Church did not say Christians had to follow the Law of Moses. But certain men, on their own, said that Christians had to follow the Law of Moses. By following these laws, the Christian was not doing it out of faith in Jesus, because He never taught that Christians were under the law of Moses. They were not practicing obedience to God, (which is necessary to be saved), because God never taught that Christians had to obey the Law of Moses. The law of Moses was ONLY for the Isrealites. It was not for anyone else.
So if a Christian decided that he had to follow the Law of Moses, then he was not doing it out of faith in Jesus, nor out of obedience to Jesus. He was doing it because of his own reasoning or the reasoning of the Judiazers. He was putting his faith in the opinions of men. He was not trying to obey God, because God never taught that Christians were under the Law of Moses. He was trying to earn his own salvation, he was trying to get to heaven on his own, apart from Grace, which we receive through faith and obedience to God.
Now, some people thought that St. Paul was against the idea of obeying God with the intention of obtaining a reward of final salvation. Of course this was false. St. Paul was against the idea that faith in Jesus and His Church and obedience to God was not sufficient. St. Paul was against the idea that in addition to faith and obedience, Christians must follow the man-made idea, that Circumcision, sabbath observance and other ceremonial laws of the Law of Moses must be followed.
Since these people got confused, James makes it clear that faith and obedience to God are both necessary to enter heaven. (Of course if one dies right after conversion and repentance, then the intention to obey is sufficient. ) So James is writing about works of the moral law, obeying God. Paul was writing about the ceremonial rituals of the Law of Moses, which is NOT obeying God for Christians.
To clear up some things. Before Jesus came, Jews had to follow the law of Moses, out of faith in God. If they did so, they could escape hell. They could not be saved, that is, they could not be made a child of God and have the right to heaven, because Jesus had not yet merited the grace of salvation, so no one could go to heaven yet.
It was not till Jesus died and rose that He merited the grace for our salvation. If we have faith in Jesus, that is if we believe all He taught the apostles, which is handed down in the Church today, then we can receive the grace of salvation, or sanctifying grace through baptism and the other sacraments. If we obey the teachings of Jesus, as He taught the apostles who handed then down through the Church, then we can preserve and grow in this grace. If we die in this grace which saves us, then we will go to heaven to be with Jesus and everyone else in heaven, for eternity.