First, I would like to present my understanding of some of the terms.
Countries are geo-political entities, that were defined by specific individuals. Not everyone gets to define their own country or other countries. Also, the definition of countries change over time.
Illegal entry refers to the entry into a country without in a manner contrary to an entry defined by the law of the country. In a representative democracy, the law, also, is usually defined by certain individuals, and not be everyone.
Poverty is a lack or deficiency of personal needs. The amount of money, which is used to fulfill these needs in capitalist societies, is often used as an indicator of poverty.
"Poor resources" and "poorly managed moderate resources" are contradictory in that the former refers to "poor resources" and the latter "moderate resources". Similarly, "rich resources" and "better managed moderate resources" are contradictory in that the former refers to "rich resources" and the latter "moderate resources". For argument's sake, let us first consider that the countries have "poorly managed moderate resources " and "better managed moderate resources". The management of resources, again, rests not equally on all individuals in a country.
It follows, therefore, that not everyone participates in the definition of "countries", "laws", and "management of resources".
At the end of the day, if an individual is in so much poverty (has very little money), then the definitions become irrelevant to the individual's happiness and the individual does not conform to them anymore. This could possibly be the background of individuals who enter a country illegally. I have not experienced it firsthand, so my statements are only conjectures.
The "members of a population from Country B" (let's call them, Population B), who may conform and live by the definition of "countries", "laws", in general and their country and their laws, in particular, would probably think that it is the illegal entry of the "members of a population from Country A" (let's call them Population A) is not just illegal, but also unjust.
Thus, the tricky part is to find a solution that would both address the poverty of Population B as well as the illegality and injustice against Population A.
Now, let us analyze the next statement regarding the resources and their management. In a globalized world, resources (materials, finished goods, and knowledge) are exported and imported among different countries. The price is determined by the buying country and the selling country, demand, and supply. Thus, even countries with less resources can be rich, depending on what type of resources they have. Once they have an economic advantage, it is easier to build upon the economic advantage more and more. The exports and imports are controlled by individuals who manage the resources. By exporting resources to other countries, these individuals gain economic benefits. However, it results in more and more poverty of Population B.
Thus, we can see that if all populations would like to conform to geo-political boundries identified as the countries, and avoid illegal immigration, then
1) either all resources (including human resources) must be produced and used within their own countries (this solution will address the poverty of Population A), or
2) eliminate all borders and dissolve the definition of countries (this solution will address the injustice against Population B).
Reference:
On the Morality and Legality of Borders: Border Policies and Asylum Seekers