Classpaths, packages, jarfiles, and all that gunk. Ch 4, pp 135--144 es.html.

Slides:



Advertisements
Similar presentations
Introduction to Java 2 Programming Lecture 3 Writing Java Applications, Java Development Tools.
Advertisements

Creating Jar Files Jin Hung, Gregory Olds, George Blank, Sun Java Web Site.
Objectives:1. Archiving and Packaging Java Code 2. The jar Program 3. Example Applet JAR Files.
My First Building Block Presented By Tracy Engwirda 28 September, 2005.
Package and Import Yoshi. Michael How many “Michael” in this world? When we only say “Michael”…who? So we have the last name – Michael Jordan – Michael.
1 Ant – Another Neat Tool Representation and Management of Data on the Internet.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
Objectives:1. Archiving and Packaging Java Code 2. The jar Program JAR Files.
Slides prepared by Rose Williams, Binghamton University Chapter 5 Defining Classes II.
By Dr. Jiang B. Liu 12. The Java Beans. Java Beans n JavaBeans is a portable, platform-independent software component model written in Java. It enables.
Java Jar Files Bar-Ilan University תשס"ה by Moshe Fresko.
Packages Where, oh where, is my little lost class file?
Unit 051 Packages What is a Package? Why use Packages? Creating a Package Naming a Package Using Package Members Managing Source and Class Files Visibility.
Applying OO Concepts Using Java. In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The.
Building and Deploying a Simple Web Application. Tomcat and JSP Tomcat is an application server, commonly used to host JSP applications Applications are.
Deploying Java applications as JAR files SE-2030 Dr. Mark L. Hornick 1 How to package an application so that you can run it outside of Eclipse.
עיצוב תוכנה מונחה עצמים תירגול 1. 1.Packages and Paths 2.Jar Files Outline.
Chapter 55 How to Construct JAR files for Program Distribution.
Using Ant to build J2EE Applications Kumar
DAT602 Database Application Development Lecture 15 Java Server Pages Part 1.
Introduction to ant Guy Rixon AstroGrid Consortium Meeting
PACKAGES Mimi OpkinsCECS277. What We’ll Cover  Packages and Import Statements  The Package java.lang  Package Names and Directories  The Default Package.
Access Control Problem A primary consideration in object- oriented design is to “separate the things that change from the things that stay.
Java™ How to Program, 9/e © Copyright by Pearson Education, Inc. All Rights Reserved.
Week71 APCS-AB: Java Control Structures October 17, 2005.
1 Lecture 2: Object Oriented Programming in Java.
Dale Roberts Object Oriented Programming using Java - Packages Dale Roberts, Lecturer Computer Science, IUPUI Department.
Deploying Java applications as JAR files SE-2030 Dr. Rob Hasker 1 Based on material by Dr. Mark L. Hornick.
Spring 2008 Mark Fontenot CSE 1341 Principles of Computer Science I Note Set 2.
CS 11 java track: lecture 1 Administrivia need a CS cluster account cgi-bin/sysadmin/account_request.cgi need to know UNIX
July 2011CMSC 341 CVS/Ant 1 CMSC 341 Java Packages Ant CVS Project Submission.
Deployment via jars and Webstart. How do we distribute our application? Lab says you need to submit CD Lab says you need to submit CD Limitations of CD.
AIP Backup & Restore Sunita Barve NCRA, Pune. AIP The latest version of DSpace 1.7.0, supports backup and restore of all its contents as a set of AIP.
HTML Concepts and Techniques Fifth Edition Chapter 6 Using Frames in a Web Site.
4/1/05F-1 © 2001 T. Horton CS 494 Object-Oriented Analysis & Design Packages and Components in Java and UML.
Android Security Model that Provide a Base Operating System Presented: Hayder Abdulhameed.
Ant & Jar Ant – Java-based build tool Jar – pkzip archive, that contains metadata (a manifest file) that the JRE understands.
CS 61B Data Structures and Programming Methodology July 3, 2008 David Sun.
9.1 Java Packages A collection of classes Allows classes to be grouped arbitrarily Hierarchical structure independent of inheritance Classes can.
(C) 2010 Pearson Education, Inc. All rights reserved. abstract class Employee represents the general concept of an employee. Subclasses: SalariedEmployee,
Core Java Introduction Byju Veedu Ness Technologies httpdownload.oracle.com/javase/tutorial/getStarted/intro/definition.html.
Inheritance. Inheritance - Introduction Idea behind is to create new classes that are built on existing classes – you reuse the methods and fields and.
Plug-in Architectures Presented by Truc Nguyen. What’s a plug-in? “a type of program that tightly integrates with a larger application to add a special.
Lecture 2 February 3, Installing PFE Just unzip the file you download into any directory, such as C:\Program Files\PFE You may right-click on pfe32.exe.
Henrik Bærbak Christensen1 Build Management Clean environment that works...
Review of Previous Classes Declaring Variables - var myVar:DataType = value Data Types – Number, uint, String, Boolean Functions – parameters, return.
1 DIG 3134 Lecture 6: Maintaining State Michael Moshell University of Central Florida Media Software Design.
Packages. Access Specifications Public Available anywhere (public keyword) Only one public class per file allowed Protected Available in subclasses, and.
Programming in java Packages Access Protection Importing packages Java program structure Interfaces Why interface Defining interface Accessing impln thru.
CS116 COMPILER ERRORS George Koutsogiannakis 1. How to work with compiler Errors The Compiler provide error messages to help you debug your code. The.
Java Package Advantage of Java Package
In this class, we will cover: Overriding a method Overloading a method Constructors Mutator and accessor methods The import statement and using prewritten.
3/5/2002e-business and Information Systems1 Java Java Java Virtual Machine (JVM) Java Application Program Interface (API) HW Kernel API Application Programs.
 2005 Pearson Education, Inc. All rights reserved. 1 Classes and Objects: A Deeper Look.
Brandon Packard. Why make? So far, you have probably worked on relatively small projects Coding projects can become huge My research consists of 1600.
Java Packages - allow you to group classes as a collection Standard Java library has packages: java.lang and java.util … Also hierarchical: java and javax.
Object Oriented Programming in
Packages When we name a program , we name it by class name…
Java Basics Packages.
JAR Files Objectives: 1. Archiving and Packaging Java Code
Java Packages B.Ramamurthy 11/11/2018 B.Ramamurthy.
Ant.
TOSCA-Metadata (directory )
Packages and Interfaces
TOSCA-Metadata (directory )
From C++ to Java Java history: Oak, toaster-ovens, internet language, panacea What it is O-O language, not a hybrid (cf. C++) compiled to byte-code, executed.
Most Common Grading Issues
Applying OO Concepts Using Java
Classes 5/5 May 14, 2019 ICS102: Classes 5/5.
Plug-In Architecture Pattern
Presentation transcript:

Classpaths, packages, jarfiles, and all that gunk. Ch 4, pp es.html

Administrivia P1 rollout due today (!) Assessments? P2 assigned next Monday Happy full moon Midterm exam: Mar 9, in class Interfaces, abstract classes, concrete classes Swing Parsing Misc Java syntax/semantics

UNM CS Research day Fri, Mar 4 (next Fri) UNM CS research presentations and posters Undergrad and grad research work You’re all invited! See for details and registration

News blurb o’ the day “Cabir” cell phone worm discovered in US Spreads via Bluetooth to phones running Symbian Series 60 OS Phone must be set to “discoverable”, not “hidden” Prints “Caribe” when phone is activated So... What are the design flaws here?

The Java class loader Every class you use must be available to the JVM JVM dynamically loads classes on demand First reference of a class in a program (direct or indirect) new, deserialization, etc. When explicitly requested via java.lang.ClassLoader.loadClass() But how does it find the.class file? Where does it look for the file? What steps take place?

Watching the class loader java -verbose : prints out all class loads Worth trying yourself -- get some of the “behind the scenes view”

CLASSPATH Java uses a “search path” named CLASSPATH Only looks for files on the CLASSPATH Looks in order of elements in CLASSPATH Directories Jar files Zip files

Contents of CLASSPATH CLASSPATH is a colon-separated list of elements: CLASSPATH=$HOME/lib/java/java-getopt jar:$HOME/lib/java/libtdrl.jar:$HOME/private/src/ projects/p1/:. $HOME/lib/java/java-getopt jar $HOME/lib/java/libtdrl.jar $HOME/private/src/projects/p1/. Can be given as command-line option to javac / java ( -classpath ) or via environment var ( $CLASSPATH )

Caveat CLASSPATH also contains some “hidden” elements Java “bootstrap” classes ( rt.jar, etc.) Includes all “standard” Java stuff -- java.lang, java.util, javax.swing, etc. “Extension” classes Contains system-specific add-ons

Coolness of CLASSPATH System-specific (or user-specific) Easy to customize which classes are available Every user/site can have diff classes/packages available Code designer doesn’t have to know anything about the arrangement of the target system Doesn’t even have to know that it has directories! Can load class files over the net, from memory stick on a PDA, etc. Can play clever tricks w/ class loading

Pain of CLASSPATH Can have subtle (or not subtle) bugs when CLASSPATH is set up wrong Can’t find something that “is right there!” Can get wrong (out of date) class User can sabotage your program Can deliberately substitute a class for yours Can subvert your security mechanisms Java provides a SecurityManager API to help you control such subversions Getting it right not trivial

Seems simple enough... Easy, right? Just make sure that all your.class files appear on the CLASSPATH, and life is good But... What does it mean for a jar file to be on the classpath? What about packages?

Jar files Simple version: Jar file is just a Zip archive containing a bunch of.class files Class loader treats entire jar file as a directory If CLASSPATH=foo.jar:bar.jar:. java HelloWorld will look for HelloWorld.class in foo.jar HelloWorld.class in bar.jar HelloWorld.class in current directory (. )

Building jar files Very convenient for shipping around large amounts of code/class files Create jar file w/ jar cf [jarfilename] [files/dirs to put in jar]

Jar files, reprise More complicated version: Jar files can have a “default main class” Can “run” an entire jar file w/ java -jar [jarfilename] But: jar file must contain “manifest” file that specifies default main class If you don’t specify a manifest, jar creates an empty one for you Create a jar file w/ manifest: jar cfm [jarname] [manifestfile] [targetfiles]

Packages Nastier problem: packages Every Java class exists in a “package” Essentially a namespace Allows multiple developers to have classes w/ same base name java.util.Date diff from java.sql.Date “True” name of a class is [packagename].[classname] Java class loader expects class file for java.util.Date to be [CLASSPATH elt]/java/util/Date.class