Java: JAR file
JAR is like Zip but for Java files. A JAR file simply contains a bunch of Java files and resources.
Extract a JAR
Open Terminal and type this, changing sample.jar to your jar file’s name:
Export to JAR
In Eclipse, got to File > Export > Java > Jar.
If you’re trying to share source files, include the following option in the export settings: “Export Java source files and resources”.
If you’re exporting your code for someone to use, just export the class files.
Adding a JAR file directly in Eclipse
If you receive a JAR file from someone, you can add the JAR file directly into your Eclipse project. Eclipse will then give you access to the classes without requiring you to extract them from the JAR.
Here’s how you add the JAR to a project in Eclipse. After you create a Java project, create a new folder by going to File > New > Folder. Call it “lib”. Then import the JAR file into the lib folder by going to File > Import > General > File. Alternatively, you could just copy the JAR file manually into that folder by navigating to it in your workspace.
You then need to add the JAR to your class path, which you can do by right-clicking the lib folder and choosing Build Path > Add to Build Path. Alternatively, you can add the JAR file to your project by right-clicking your project and selecting Properties. In the dialog box, select Java Build Path, then click the Libraries tab, and then click Add JARs and browse to the JAR.
For details, see section 25 in the Vogella Eclipse IDE Tutorial.
About Tom Johnson
I'm an API technical writer based in the Seattle area. On this blog, I write about topics related to technical writing and communication — such as software documentation, API documentation, AI, information architecture, content strategy, writing processes, plain language, tech comm careers, and more. Check out my API documentation course if you're looking for more info about documenting APIs. Or see my posts on AI and AI course section for more on the latest in AI and tech comm.
If you're a technical writer and want to keep on top of the latest trends in the tech comm, be sure to subscribe to email updates below. You can also learn more about me or contact me. Finally, note that the opinions I express on my blog are my own points of view, not that of my employer.