I would start by suggesting having a meeting with the PI. Even if he really wants to push you away from the project, the meeting will be useful in order to understand his line of reasoning (or lack thereof). Don't beat around the corner, ask him directly questions like: "Why do you believe I don't deserve to be part of this project?"; "Given the considerable amount of work I put into it, how much is enough to deserve authorship?"; "Why do you try to train people in order to learn a procedure I am an expert at, instead of using my skills?". Just remember humans are very broken and inefficient machines in general, and sometimes the way someone answers a question (tone of voice, movements, eye contact) are more important than the answer itself, especially when we're dealing with very proud and dismissive people. Straightforward discussions are the best way to solve any problem in life, especially in science, but one has to learn what to look for during this type of interactions. It is likely that you will be able to infer that this PI simply doesn't like you (happens a lot), or thinks your work is of low quality, or maybe he/she will even be honest and give you a full answer. No matter what happens, this is the first thing to try IMHO.
Now, assuming that not much was gained from a direct approach and given that you have the support of other postdocs involved in the project, you can always invoke the fact that all authors in a paper have to agree about who should be listed as an author. In practice the final word either falls on the PI or on his boss (a director, a professor, etc), but it is rare to see a paper in which e.g. 3 out of 4 authors claimed X should be a coauthor, and in the end this person wasn't listed. There should be a consensus here. Unfortunately sometimes the other postdocs will agree that you should be an author but will not be willing to place themselves in the PI's line of fire by trying to insist on this. In this case you might try to talk to the PI's boss, especially if you now know the PI doesn't like you. There's a chance the PI will be reprehended and somehow forced to list you as an author, but what is certain is that from now on the PI won't simply dislike you... He/she will very likely hate your guts.
If talking to the PI directly, gathering public support or even talking to the PI's boss don't work, as you mentioned there is sometimes the possibility of contacting the journal directly. I would very much advocate that this is a very, very bad idea. You would be messing up the lives of all authors, not only the PI. You would also cause problems to the journal's editorial board, who have zero to gain in being involved in authorship disputes. This could lead the journal to include the authors (and you as well, and sometimes even your institute!) in some sort of "these people are trouble" list, and this is the last thing you want - especially in the beginning of your scientific career. Honestly, do not include the journal in this matter, unless you want to really start a war that has a huge probability of downing you in its end.