• Post Reply Bookmark Topic Watch Topic
  • New Topic

Jar/war/compile what's happening?  RSS feed

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello all, I'm still new to Java(and Coding too). I often hear Java Archive(Jar)/ Web Application Resource(war) etc. I tried to give some reading on google, but everything is flying past by my ears. Please provide me some info on my doubts and any good material to do some reading(No buying!! Free stuff please!)

1) When we say compile, java file is converted to byte-code that's read by Java Virtual Machine(JVM). Now what's this packaging into Jar/War etc that I hear about? How does a .class byte-code gets converted to jar. My eclipse IDE also have options of generating jar/war. Can I do it manually?

2) How does Jvm treats these jar/war files?

Thanking in advance to anyone attempting to clarify my doubt. Apologies if the question doesn't make sense!
 
Greenhorn
Posts: 22
1
C++ IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sharath chan wrote: 1) How does a .class byte-code gets converted to jar.

It doesn't. A jar file is just a compressed file, like .zip, which contains .class files.

sharath chan wrote: 2) How does Jvm treats these jar/war files?

In the Java virtual machine (JVM) classloaders will load classes. These classes can be loaded as separate files from the filesystem, from an archive (like a .jar) or from a remote location. So, jars/wars don't have a special meaning in the JVM. It's all about classes.
 
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The page About the Java Technology from Oracle's Java Tutorials explains it with pictures.

The steps are roughly like this:

You write a program by creating one or more *.java source files in a text editor or IDE.

You compile your *.java source code into *.class files, which contain byte code, which are machine instructions that the Java Virtual Machine can execute.

You can now either run your program from the *.class files, or you can package the *.class files into a *.jar file. Real programs often consist of many classes, so it's more convenient to have one jar file that contains all the class files than to have a directory with many class files. A jar file is really just a zip file, to keep the class files together. See Packaging Programs in JAR Files for the details of how this works.

War files are just jar files with some extra information in them, and are meant for Java web applications. You don't run a war file directly; instead, you need an application server, such as Apache Tomcat, or Oracle Glassfish, to run it. The application server is a web server - it can receive network connections from browsers that people are running on their own computer, and then calls the web applications that are deployed into it to handle requests from the connected browsers.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!