How does the JRE run a jar

So currently ive been thinking , thinking about compilers and the actual RE. My question is how does the computer know that when I run my .jar to load it into the JRE and not to open it , and if I were to go about creating a similar RE how would this be done.