There is no contradiction between James and Paul, but for those having a flawed theology, they find themselves in increasingly inextricable contradictions & inconsistencies since the harmony of the whole web is broken. It is no wonder why Martin Luther hated and removed James epistle from his judgement of the Canon, but the contradictions are still not solves, since James was only repeating what Jesus and the other apostles consistently taught that religion alone is worthless, and cannot save you, faith alone is dead. Those who boast in their faith or ancestry while disobeying God are enslaved to sins as God can produce believers from stones (Matt 3:9; Jn 8:33) God is not the God of Jews alone but of the whole world, and he judges everyone according to their heart and works impartially, as Paul expounds upon in details such as Romans 2:6-16. Luther was still left with tons of justification by works doctrine, start with the parables of Jesus, for the criteria of kingdom of heaven, such as the righteous Samaritan being shown superior to the religious priests who have the highest religious yet was having a dead religion (Luke 10). So the problem doesn't go away simply by ripping of James from the NT.
[ESV Romans 3:27-30]
27Then what becomes of our boasting? It is excluded. By what kind of law? By a law of works? No, but by the law of faith. 28For we hold that one is justified by faith apart from works of the law. 29Or is God the God of Jews only? Is he not the God of Gentiles also? Yes, of Gentiles also, 30since God is one—who will justify the circumcised by faith and the uncircumcised through faith.
Paul's arguments about the justification by works were only with respect to the antithesis with the Mosaic law, which Christ ended to liberate them from the law covenant, that is defined as grace. But Luther mistranslated Rom 3:28 as "faith alone" based on his misinterpretation that the frequent phrase works of the law refers to human effort in pleasing God, rather than the works of the Mosaic covenant, hence the opposition to James who explicitly wrote against faith alone to the early heretics who mistook the grace/liberty as faith alone which requires no works, exactly what Luther came up with. It cannot be "faith alone" since Paul is not subtracting works from faith to say justification is by faith alone, as if they could continue solely with their existing faith in God. He is showing two different kinds and criteria of justification, one that is by works of the law covenant, but there were other examples of faith justifications like Abraham's without any work. His argument is that law justification is not eternal and only way of justification. A superior criterion for justification has come that requires faith in Christ that replaced the Mosaic law. It is not related with the scope of faith alone or faith minus works in general formula. Even if one attempts to define the beginning stage of justification as faith alone, he cannot maintain that as a creed since God requires works as necessary for salvation (except for someone like the thief on the cross who did not have anything to offer in life at his death moment). This is why the reformers and their followers have been desperately struggling to defend their creed of faith alone against logic.
If one interprets the anti-works arguments of Paul as human efforts then it is inescapable that any & every moral works are not only unnecessary but needless and even undesirable as the modern unapologetic teachers like Paul Ellis [hyper-grace] teach unlike Luther who later tried to apologetically endorse moral works as a secondary preferable ornamental thing with faith to justify himself to the objectors.
Faith alone that works?
Defensive approaches to faith-alone position by attaching works as subordinate to faith are mere slogans, and they fail as logical contradictions such as "faith alone, but the faith is actually not alone": Luther and Calvin. People often attempt to reinterpret or change the meaning of Faith in the two contexts, but those too are easily seen as desperate attempts to solve the dilemma, like making a superficial distinction of genuine vs ungenuine faith. Arguments like James was talking about justification before men as Daniel Wallace argues:
δικαιόω in James most likely refers to vindication before men after one’s actions are seen, while δικαιόω in Paul refers to forensic declaration of innocence before God;
πίστις in James is mere intellectual assent (“even the demons believe and shudder” [Jas 2:19]), while for Paul it is a full embracing of the Savior as the only way in which one can escape damnation;
These do not give justice to the plain text. Neither of the two were concerned about justification for the world, nor they are concerned about trivial redefining of faith on a semantic and attitude level. They both meant the same sotereological criteria for justification. The difference was with the "works" in both context. Paul is teaching about the futility of Mosaic law after the changing of covenant, while James about the moral works of commands or as the law of Christ which are beyond Mosaic law. Paul's audience were those facing the very first heresy of Torah keeping or circumcision aka Judaizers threat; arguments against law-alone when the law has been replaced and no longer valid. James wrote to those facing the second heresy in the Church that is lawlessness or licentious grace that overlooks overlooks general or moral works; arguments against faith-alone. These heretics were likely influenced by twisting Paul's teachings, as Peter also addressed it, and other apostles also seem to address this second heresy of lawlessness:
[ESV 2 Peter 3:14-17]
14Therefore, beloved, since you are waiting for these, be diligent to be found by him without spot or blemish, and at peace. 15And count the patience of our Lord as salvation, just as our beloved brother Paul also wrote to you according to the wisdom given him, 16as he does in all his letters when he speaks in them of these matters. There are some things in them that are hard to understand, which the ignorant and unstable twist to their own destruction, as they do the other Scriptures. 17You therefore, beloved, knowing this beforehand, take care that you are not carried away with the error of lawless people and lose your own stability.
Luther's faith alone position is built on the premise of the original sin, solely based on the misinterpretation of a general statement no one is righteous (Rom 3:10-11), a warrant to disregard all the law or commandments of God by making man utterly depraved and incapable of doing good. Thus, this theology puts Paul on its center and everyone else including Jesus is kept aside, some even argue that Jesus and James aren't applicable to the Church as their teachings were of the old covenant. It is not difficult to figure that the works are the Mosaic law works which are no longer valid criteria for justification for God due to the change of the covenant, the coming of the promise (Gal 3, Rom 10). Those who still seek to be justified by the law are refusing the promise covenant of grace, hence establishing their own criteria or righteousness that is opposed to God's criteria of righteousness.
Regarding those passages like Ephesians 2:5-8 saying that by grace you have been saved, not by works that anyone should boast, only represents the grace of God under the new covenant, as opposed to the law based righteousness (Rom 10:4-5, 3:27). As it is by definition grace, it does not exclude works considering grace does not mean freedom from any works but only the law of Moses. The providence of grace or sacrifice of Christ is not a result to anyone's good works and believers works do not add to the atonement of Christ. Atonement and obedience are two independent things.
James, does not mean works are tied to salvation in "some way" but in a necessary way as much as the spirit is necessary for the body to be living, so also faith apart from works is dead (v2:26). Faith is just a beginning of justification, not the goal that faith alone would matter, hence nobody ever wrote such a statement but on the contrary condemned it. Paul puts divine-love above faith in 1Cor 13:13. Divine love that is not a feeling but benevolent works for others. Consider this:
[NASB 1 Cor 7:19-20]
Circumcision is nothing, and uncircumcision is nothing, but [what matters is] the keeping of the commandments of God. Each man must remain in that condition in which he was called.
[Galatians 5:6] For in Christ Jesus neither circumcision nor uncircumcision means anything, but faith working through love.
Paul says neither circumcision (the condition of the Jewish believers) nor uncircumcision (condition of the gentile believers) but the commandments alone matters. Circumcision or uncircumcision are mere religious conditions of believers, they matter nothing without obedience to God. Faith working through love that is a work; faith doesn't work, man works. Circumcision was the requirement under the old covenant, faith in Christ has replaced the law now. John, Peter, Jude everyone else wrote the same doctrine repeatedly that following the commandments of Christ or the law of God matters. The view that Paul meant human efforts by the law is a grave misunderstanding that leads to messing with the whole theological web, with endless contradictions.