Libraries as JARs2:51 with Chris Ramacciotti
In order to code fancy applications, developers rely heavily on other people's code, or *libraries*. These libraries are made available as JAR files to anyone who wants to use them. In this video, you'll be introduced to the process of using a third-party library in your own code.
Welcome back. 0:00 If you're here now, Im guessing you have IntellaJ installed and ready to go. 0:01 Nicely done. 0:05 If not, be sure to hit up the forum with your questions and 0:06 the community can help you get going. 0:09 The next tool I wanna discuss will be used to manage the third party libraries we 0:12 use in our project. 0:16 Namely, the spring libraries. 0:18 The spring framework that we'll be using is not included in the Java core library. 0:21 That being the case, we'll need to save those libraries into our projects so 0:25 that we can use the familiar import statements 0:29 to reference spring code from the code that we're writing. 0:32 Technically this amounts to adding JAR files to the class path. 0:36 The who and the what now? 0:40 Let's dissect that a little bit, starting with the class path. 0:42 If you've been through some of our previous courses, 0:46 you may have experience using the class path. 0:48 In Java, the class path consists of one or 0:51 more directories that contain all the Java files associated with our project. 0:54 This is an option we can specify, while compiling or running a Java program. 0:59 [NOISE] So if there are outside code libraries, the directory where they're 1:03 saved should be a part of the class path [NOISE] that's given to the Java compiler 1:07 while compiling, and to the Java virtual machine while running. 1:12 Hey, speaking of code libraries, 1:16 let's circle back to another term I mentioned just a few moments ago. 1:18 I said that we'll need to add JAR files to the class path. 1:22 What are these JAR files? 1:26 If you haven't guessed yet, 1:28 these are indeed the code libraries I'm referring to. 1:30 Let's take a closer look. 1:33 JAR stands for Java Archive. 1:35 A JAR file is essentially a bundle of compiled Java code. 1:37 The files are bundled together just like a zip file. 1:42 Except that the Z-I-P extension, a JAR file has the J-A-R extension. 1:45 What this amounts to is that you can write a bunch of Java code then distribute that 1:51 code as an application or library by generating a JAR file. 1:56 Generating one of these can be done from most Java IDEs, including IntelligiJ, or 2:00 from the command line with the JDK's JAR command. 2:05 After generating a JAR file, all developers need to do is 2:09 download the JAR file that you've created and add its location to their classpath. 2:12 Then they can start creating and 2:17 interacting with objects from the classes that you defined. 2:19 Since the JAR file only includes your pipe code, 2:23 they can do this without you ever having to reveal your source code. 2:26 Now, that's pretty cool stuff. 2:30 As a heads up on terminology, I'll be using the terms JAR and 2:32 library synonymously. 2:35 Let's take a short break here and in the next video 2:38 we'll talk about how we're going to fetch all those fancy libraries. 2:41 It turns out that the tool we're gonna use 2:45 is one of the most widely used tools in the industry. 2:47
You need to sign up for Treehouse in order to download course files.Sign up