200 likes | 341 Vues
Maven, SVN, Jars, Interfaces. Maven. Why: Dependency managment Build tool (classpath managment) Useful in large projects and in complex projects. Project Object model: pom.xml. (Copied from the lecture notes) <project> <modelVersion>4.0.0</modelVersion>
E N D
Maven • Why: • Dependency managment • Build tool (classpath managment) • Useful in large projects and in complex projects.
Project Object model: pom.xml (Copied from the lecture notes) <project> <modelVersion>4.0.0</modelVersion> <groupId>no.uio.inf5750</groupId> <artifactId>example1</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>INF5750 Example 1</name> <dependencies> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.0.3</version> </dependency> <dependency> <groupId>springframework</groupId> <artifactId>spring</artifactId> <version>1.1.3</version> </dependency> <dependencies> </project>
Groups and artifacts no.uio.inf5750 assignment2 xml-formatter assignment1
Example uses of Maven (Copied from the lecture notes) • Package the source code into an archive $ m2 package • Run the projects unit tests $ m2 test • Creating Eclipse project files $ m2 eclipse:eclipse • Creating IDEA project files $ m2 idea:idea • Clean project $ m2 clean:clean • Install the package into the local repository $ m2 install
Maven repository • Has nothing to do with an SVN repository. • Central repo (maven.apache.org, ibiblio.org, download jars from here) • Local repo (downloaded/installed jars) • Look in ~/.m2/repository
JAR • A zip file for Java code • Bundle lots of files together in a foo.jar file. • May contain a manifest (like a ship’s manifest) • Can be run, if a class is specified in the manifest: java –jar foo.jar • The assignment1 example! • Create archive: jar –cvzf foo.jar <some files> • Extract contents of archive: jar –xvzf foo.jar
Subversion (SVN) • Why SVN? • Multiple people coding on the same project. • Version control: Increment changes, rollback unwanted changes. • CVS is the same type of program, only older.
SVN: Working cycle • Create repository (svnadmin create) • Check out local copy ( svn checkout URL) • Create local files • Add files to version control (svn add <file>) • Commit changes (svn commit) • … • Check status of local copy (svn status) • Check out/Update local copy (svn update) • Change files • Commit changes (svn commit)
SVN: Overview • SVN client • - Local copy • svn CLI (linux/win) • Tortoise SVN + putty (win) • Cygwin (svn through win) • svn checkout • svn add • svn commit • SVN server • Central repo • svnadmin create
SVN: General cycle Client 1 Checkout Commit Central repo Checkout Client 2 Commit
SVN: Conflict! Client 1 Checkout Commit Central repo Checkout Client 2 Commit
SVN: Healthy cycle Client 1 Checkout Commit Central repo Checkout Update Client 2 Commit
SVN: Adding to version control? • What to check in: • Source code • Tests • Resources • What not to check in: • Compiled code • Eclipse files (.project, .whatnot) • Other files specific for the local system • Make SVN ignore files • svn propset svn:ignore –F <file-with-list> -R <PATH>
Java interfaces • Perhaps the most advanced concept in Java? • Code: • A ”class” with only methods, methods which have no body. • Concept: • A contract: If you implement the interface, you must implement the methods defined by it. • Reward: Other classes can treat you as if you are an instance of the interface. • Interface: What. Implementation: How.
Interfaces: Overview Implementation 1 Application Interface Implementation 2
Interfaces: Java examples • Java’s ActionListener concept: • A class can listen to a button if it implements the ActionListener interface and the method public void actionPerformed(ActionEvent e) {…} • Java’s collections framework (e.g. List, Set, etc): • Interface: List. • Implementations: ArrayList, Vector, LinkedList.
Example: RentABike Implementations MemoryRentABike (class) BikeApplication (class) RentABike (interface) DatabaseRentABike (class) FileRentABike (class)
Where to choose the implementation? • Hard code it into the application (highly coupled) • Let a controlling class choose the implementation for the application. (Better, but still coupled) • Decide at run time, depending on situation. Need a registry. • Let Swing inject the implementation into the application (even better… ).
Spring: beans.xml <beans> <bean id=”rentABike” class=”no.uio.inf5750.hanssto.bike.MemoryRentABike”/> <bean id=”BikeApplication” class=”no.uio.inf5750.hanssto.bike.BikeApplication”> <property name=”rentABike”> <ref id=”rentABike”/> </property> </bean> </beans>