Presentation is loading. Please wait.

Presentation is loading. Please wait.

Jeg har så vondt i mvn JavaBin, 10. mars, 2011 Johannes Brodwall.

Similar presentations


Presentation on theme: "Jeg har så vondt i mvn JavaBin, 10. mars, 2011 Johannes Brodwall."— Presentation transcript:

1 Jeg har så vondt i mvn JavaBin, 10. mars, 2011 Johannes Brodwall

2 mvn intro

3 archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea

4 $ mvn archetype:generate [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'archetype'. [INFO] [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] [INFO] Preparing archetype:generate [INFO] No goals needed for project - skipping [hoose archetype: ….

5 [hoose archetype: 1: remote -> docbkx-quickstart-archetype (-) 2: remote -> multi (-) 3: remote -> simple (-) : remote -> maven-archetype-quickstart (An archetype which contains a sample Maven project.) : remote -> javg-minimal-archetype (-) Choose a number: 101: 101 Choose version:... 6: 1.1 Choose a number: 6:

6 Define value for property 'groupId': : no.steria.demo Define value for property 'artifactId': : maven-demo Define value for property 'version': 1.0-SNAPSHOT: Define value for property 'package': no.steria.demo: Confirm properties configuration: groupId: no.steria.demo artifactId: maven-demo version: 1.0-SNAPSHOT package: no.steria.demo Y:

7 [INFO] project created from Old (1.x) Archetype in dir: C:\Users\johannes\workspace\tmp\maven-demo [INFO] [INFO] BUILD SUCCESSFUL [INFO] [INFO] Total time: 20 seconds [INFO] Finished at: Thu Mar 10 08:42:16 CET 2011 [INFO] Final Memory: 19M/154M [INFO]

8 /** * Unit test for simple App. */ public class AppTest extends TestCase { /** * Create the test case * testName name of the test case */ public AppTest( String testName ) { super( testName ); } /** the suite of tests being tested */ public static Test suite() { return new TestSuite( AppTest.class ); } /** * Rigourous Test :-) */ public void testApp() { assertTrue( true ); }

9 mvn intro archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea

10 mvn intro archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea

11 $ mvn deploy [INFO] Scanning for projects... [INFO] [INFO] Building maven-demo [INFO] task-segment: [deploy] [INFO] [INFO] [resources:resources {execution: default-resources}] [INFO] [compiler:compile {execution: default-compile}] [INFO] [resources:testResources {execution: default-testResources}] [INFO] [compiler:testCompile {execution: default-testCompile}] [INFO] [surefire:test {execution: default-test}] T E S T S Running no.steria.demo.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 compile test-compile test

12 [INFO] [jar:jar {execution: default-jar}] [INFO] [install:install {execution: default-install}] [INFO] Installing...\maven-demo\target\maven-demo-1.0-SNAPSHOT.jar to $HOME\.m2\repository\ no\steria\demo\maven-demo\ 1.0-SNAPSHOT\maven-demo-1.0-SNAPSHOT.jar [INFO] [deploy:deploy {execution: default-deploy}] Uploading: [INFO] [INFO] BUILD SUCCESSFUL [INFO] [INFO] Total time: 4 seconds [INFO] Finished at: Thu Mar 10 08:54:56 CET 2011 [INFO] Final Memory: 19M/154M [INFO] package install deploy

13 mvn intro archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea

14 mvn intro archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea

15 $ mvn eclipse:eclipse [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'eclipse'. [INFO] [INFO] Building maven-demo [INFO] task-segment: [eclipse:eclipse] [INFO] [INFO] Preparing eclipse:eclipse [INFO] No goals needed for project - skipping [INFO] [eclipse:eclipse {execution: default-cli}] [INFO] Using Eclipse Workspace: C:\Users\johannes\workspace [INFO] Adding default classpath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Not writing settings - defaults suffice [INFO] Wrote Eclipse project for "maven-demo" to C:\Users\johannes\workspace\tmp\maven-demo. [INFO] Sources for some artifacts are not available. Please run the same goal with the -DdownloadSources=true parameter in order to check remote repositories for sour ces. List of artifacts without a source archive: o junit:junit:3.8.1 [INFO] [INFO] BUILD SUCCESSFUL [INFO] [INFO] Total time: 2 seconds [INFO] Finished at: Thu Mar 10 09:02:56 CET 2011 [INFO] Final Memory: 15M/155M [INFO] DdownloadSources

16

17

18 mvn basics SNAPSHOT vs release-versions repositories modules

19 Jeg har så vondt i mvn

20 Transitive dependencies Fragmenterte prosjekter Plugin overbruk

21 Dependency nightmare

22 $ mvn dependency:tree [INFO] Scanning for projects... [INFO] Searching repository for plugin with prefix: 'dependency'. [INFO] [INFO] Building maven-demo [INFO] task-segment: [dependency:tree] [INFO] [INFO] [dependency:tree {execution: default-cli}] [INFO] no.steria.demo:maven-demo:jar:1.0-SNAPSHOT [INFO] \- commons-logging:commons-logging:jar:1.1:compile [INFO] +- log4j:log4j:jar:1.2.12:compile [INFO] +- logkit:logkit:jar:1.0.1:compile [INFO] +- avalon-framework:avalon-framework:jar:4.1.3:compile [INFO] \- javax.servlet:servlet-api:jar:2.3:compile Servlet-api!?!!

23 commons-logging 1.1 jar compile servlet-api javax.servlet

24 “And Maven brought forth a Plague of Apache commons, and there was a flood of all the Libraries of the Internet as a Judgment upon the people” -Dan North, QCon London 2010

25 \- net.sourceforge.htmlunit:htmlunit:jar:2.8:compile +- xalan:xalan:jar:2.7.1:compile | \- xalan:serializer:jar:2.7.1:compile +- commons-collections:commons-collections:jar:3.2.1:compile +- commons-lang:commons-lang:jar:2.4:compile +- org.apache.httpcomponents:httpclient:jar:4.0.1:compile | \- org.apache.httpcomponents:httpcore:jar:4.0.1:compile +- org.apache.httpcomponents:httpmime:jar:4.0.1:compile | \- org.apache.james:apache-mime4j:jar:0.6:compile +- commons-codec:commons-codec:jar:1.4:compile +- net.sourceforge.htmlunit:htmlunit-core-js:jar:2.8:compile +- xerces:xercesImpl:jar:2.9.1:compile | \- xml-apis:xml-apis:jar:1.3.04:compile +- net.sourceforge.nekohtml:nekohtml:jar:1.9.14:compile +- net.sourceforge.cssparser:cssparser:jar:0.9.5:compile | \- org.w3c.css:sac:jar:1.3:compile +- commons-io:commons-io:jar:1.4:compile \- commons-logging:commons-logging:jar:1.1.1:compile Xerces  Xalan? Hmm... Én metode fra commons-lang Commons- logging…. Og én fra commons-io Én fra commons-coll

26 Dependency nightmare Excludes Vote with your feet Make it better: Avoid reuse

27 Fragmenterte prosjekter

28 \- org.eclipse.jetty: jetty-plus :jar:8.0.0.M2:compile +- org.apache.geronimo.specs:geronimo-jta_1.1_spec:jar:1.1.1:compile +- org.eclipse.jetty: jetty-webapp :jar:8.0.0.M2:compile | +- org.eclipse.jetty: jetty-xml :jar:8.0.0.M2:compile | | \- org.eclipse.jetty: jetty-util :jar:8.0.0.M2:compile | \- org.eclipse.jetty: jetty-servlet :jar:8.0.0.M2:compile | \- org.eclipse.jetty: jetty-security :jar:8.0.0.M2:compile | \- org.eclipse.jetty: jetty-server :jar:8.0.0.M2:compile | +- org.mortbay.jetty: servlet-api :jar: :compile | +- org.eclipse.jetty: jetty-continuation :jar:8.0.0.M2:compile | \- org.eclipse.jetty: jetty-http :jar:8.0.0.M2:compile | \- org.eclipse.jetty: jetty-io :jar:8.0.0.M2:compile \- org.eclipse.jetty: jetty-jndi :jar:8.0.0.M2:compile \- javax.mail:mail:jar:1.4.1:compile 12 moduler? Virkelig?

29 mvn-release-plugin liker ikke SNAPSHOTs

30 Hvor ligger PersonDAO? no.steria. person ? no.steria. dao ?

31 Konsistens? Koherens?

32 \- org.eclipse.jetty: jetty-plus :jar:8.0.0.M2:compile +- org.eclipse.jetty: jetty-webapp :jar:8.0.0.M2:compile \- org.eclipse.jetty: jetty-servlet :jar:8.0.0.M2:compile \- org.eclipse.jetty: jetty-server :jar:8.0.0.M2:compile \- org.eclipse.jetty: jetty-http :jar:8.0.0.M2:compile \- org.eclipse.jetty: jetty-io :jar:8.0.0.M2:compile Eksempel: Du skal lage støtte for NIO. Hvor?

33 Når splitter du prosjekter?

34 Kun for deployment-behov!

35 \- no.steria.demo:demo-server-package:jar +- no.steria.demo:demo-web:war +- no.steria.demo:demo-core:jar \- no.steria.demo:demo-client:jar \- no.steria.demo:demo-core:jar (duplikat)

36 Fragmenterte prosjekter Koherens > Konsistens Unngå å splitte Deployment kan kreve splitt

37 Plugins

38 Java > Mvn plugins antrun-plugin Main-klasser

39 org.mortbay.jetty maven-jetty-plugin foo 9999 start-jetty pre-integration-test run 0 true stop-jetty post-integration-test stop Portnummer? Jetty versjon? Data sources? Debugging? Flere kontekster? Integrasjon med tester?

40 import org.eclipse.jetty.plus.jndi.EnvEntry; import org.eclipse.jetty.server.Server; import org.eclipse.jetty.webapp.WebAppContext; … new EnvEntry(jndiDataSource, dataSource); Server server = new Server(0); server.setHandler( new WebAppContext("src/main/webapp", "/myapp")); server.start(); int localPort = server.getConnectors()[0].getLocalPort();

41 String baseUrl = "http://localhost:" + localPort + "/"; WebDriver browser = createWebDriver(); browser.get(baseUrl); browser.findElement( By.linkText("Create person")).click(); browser.findElement( By.name("first_name")).sendKeys("Darth"); browser.findElement( By.name("last_name")).sendKeys("Vader"); browser.findElement( By.name("createPerson")).click();

42 maven-antrun-plugin

43

44 Plugins Java > Mvn plugins antrun-plugin Main-klasser

45 Oppsummering

46 Den som spiser pølsemat (transitive deps) og kjøttmat (fragmenterte prosjekt) hele dagen Han blir så doven og så lat og får så vondt i mvn

47 Oppsummering Meeeeen… den som spiser gullerøtter (excludes) knekkebrød (dependency:tree) og peppernøtter (koherens), tyttebær (mvn-antrun-plugin) og bjørnebær (main klasser) og kålrot (sammenhengende moduler) og persille (Java-kode) han blir så passe mett i magen, glad og lystig hele dagen og så lett i bena at han nesten ikke kan stå stille.

48 Takk for oppmerksomheten twitter.com/jhannes


Download ppt "Jeg har så vondt i mvn JavaBin, 10. mars, 2011 Johannes Brodwall."

Similar presentations


Ads by Google