1 / 48

Jeg har så vondt i mvn

Jeg har så vondt i mvn. JavaBin , 10. mars, 2011 Johannes Brodwall. mvn intro. mvn intro archetype:generate test – package – install – deploy eclipse:eclipse / idea:idea. $ mvn archetype:generate [INFO] Scanning for projects ...

lindsay
Download Presentation

Jeg har så vondt i mvn

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


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

  2. mvn intro

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

  4. $ mvnarchetype:generate [INFO] Scanning for projects... [INFO] Searchingrepository for pluginwithprefix: 'archetype'. [INFO] ------------------------------------------------------------------------ [INFO] Building Maven Default Project [INFO] task-segment: [archetype:generate] (aggregator-style) [INFO] ------------------------------------------------------------------------ [INFO] Preparingarchetype:generate [INFO] No goals needed for project - skipping [hoosearchetype: ….

  5. [hoosearchetype: 1: remote -> docbkx-quickstart-archetype (-) 2: remote -> multi (-) 3: remote -> simple (-) ... 101: remote -> maven-archetype-quickstart (An archetypewhichcontains a sample Maven project.) ... 375: remote -> javg-minimal-archetype (-) Choose a number: 101: 101 Chooseversion: ... 6: 1.1 Choose a number: 6:

  6. Definevalue for property 'groupId': : no.steria.demo Definevalue for property 'artifactId': : maven-demo Definevalue for property 'version': 1.0-SNAPSHOT: Definevalue 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] projectcreated 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. */ publicclassAppTest extendsTestCase { /** * Createthe test case * * @paramtestName name of the test case */ publicAppTest( StringtestName ) { super( testName ); } /** * @return the suite of tests being tested */ publicstatic Test suite() { returnnewTestSuite( AppTest.class ); } /** * Rigourous Test :-) */ publicvoidtestApp() { 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. compile test-compile $mvndeploy [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 ------------------------------------------------------- Runningno.steria.demo.AppTest Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.029 sec Results : Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 test

  12. package install [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: scp:foo@bar.com:.../maven-demo-1.0-20110310.075455-2.jar [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] ------------------------------------------------------------------------ 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. $mvneclipse:eclipse [INFO] Scanning for projects... [INFO] Searchingrepository for pluginwithprefix: 'eclipse'. [INFO] ------------------------------------------------------------------------ [INFO] Building maven-demo [INFO] task-segment: [eclipse:eclipse] [INFO] ------------------------------------------------------------------------ [INFO] Preparingeclipse:eclipse [INFO] No goals needed for project - skipping [INFO] [eclipse:eclipse {execution: default-cli}] [INFO] Using Eclipse Workspace: C:\Users\johannes\workspace [INFO] Addingdefaultclasspath container: org.eclipse.jdt.launching.JRE_CONTAINER [INFO] Not writing settings - defaultssuffice [INFO] WroteEclipseproject for "maven-demo" to C:\Users\johannes\workspace\tmp\maven-demo. [INFO] Sources for someartifactsare not available. Please run the same goal withthe -DdownloadSources=true parameter in order to checkremoterepositories for sour ces. List ofartifactswithout a sourcearchive: 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. mvnbasics SNAPSHOT vsrelease-versions repositories modules

  17. Jeg har så vondt i mvn

  18. Jeg har så vondt i mvn Transitive dependencies Fragmenterte prosjekter Plugin overbruk

  19. Dependencynightmare

  20. $ mvndependency:tree [INFO] Scanning for projects... [INFO] Searchingrepository for pluginwithprefix: '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!?!!

  21. <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.1</version> <type>jar</type> <scope>compile</scope> <exclusions> <exclusion> <artifactId>servlet-api</artifactId> <groupId>javax.servlet</groupId> </exclusion> </exclusions> </dependency>

  22. “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

  23. Xalan?Hmm... Xerces \- 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 Én metode fra commons-lang Én fra commons-coll Og én fra commons-io Commons-logging….

  24. Dependencynightmare Excludes Votewithyour feet Make it better: Avoidreuse

  25. Fragmenterte prosjekter

  26. 12 moduler? Virkelig? \- 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:3.0.20100224: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

  27. mvn-release-plugin liker ikke SNAPSHOTs

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

  29. Konsistens? Koherens?

  30. Eksempel: Du skal lage støtte for NIO. Hvor? \- 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

  31. Når splitter du prosjekter?

  32. Kun for deployment-behov!

  33. Kun for deployment-behov! \- 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)

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

  35. Plugins

  36. Plugins Java > Mvnplugins antrun-plugin Main-klasser

  37. Portnummer? <plugins> <plugin> <groupId>org.mortbay.jetty</groupId> <artifactId>maven-jetty-plugin</artifactId> <version>6.1.10</version> <configuration> <scanIntervalSeconds>10</scanIntervalSeconds> <stopKey>foo</stopKey> <stopPort>9999</stopPort> </configuration> <executions> <execution> <id>start-jetty</id> <phase>pre-integration-test</phase> <goals> <goal>run</goal> </goals> <configuration> <scanIntervalSeconds>0</scanIntervalSeconds> <daemon>true</daemon> </configuration> </execution> <execution> <id>stop-jetty</id> <phase>post-integration-test</phase> <goals> <goal>stop</goal> </goals> </execution> </executions> </plugin> Jetty versjon? Data sources? Debugging? Flere kontekster? Integrasjon med tester?

  38. importorg.eclipse.jetty.plus.jndi.EnvEntry; importorg.eclipse.jetty.server.Server; importorg.eclipse.jetty.webapp.WebAppContext; … newEnvEntry(jndiDataSource, dataSource); Server server = new Server(0); server.setHandler(newWebAppContext("src/main/webapp", "/myapp")); server.start(); intlocalPort = server.getConnectors()[0].getLocalPort();

  39. intlocalPort = server.getConnectors()[0].getLocalPort(); StringbaseUrl = "http://localhost:" + localPort + "/"; WebDriverbrowser = 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();

  40. <plugin> <artifactId>maven-antrun-plugin</artifactId> <executions> <execution> <configuration> <tasks> <property name="compile_classpath" refid="maven.compile.classpath" /> <java classname="fitnesse.Shutdown" fork="true"> <arg line="-p ${fitnesse.port}" /> <classpath> <pathelementpath="${compile_classpath}" /> </classpath> </java> <java classname="fitnesseMain.FitNesseMain" fork="true" spawn="${fitnesse.spawn}"> <arg line="-p ${fitnesse.port}" /> <classpath> <pathelementpath="${compile_classpath}" /> </classpath> </java> </tasks> </configuration> </execution> </executions> </plugin>

  41. <property name=“mvn_cp" refid="maven.compile.classpath" /> <java classname="fitnesseMain.FitNesseMain"fork="true" spawn="true"> <arg line="-p ${fitnesse.port}" /> <classpath> <pathelementpath="${mvn_cp}" /> </classpath> </java>

  42. Plugins Java > Mvnplugins antrun-plugin Main-klasser

  43. Oppsummering

  44. Oppsummering 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

  45. 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.

  46. Takk for oppmerksomheten johannes@brodwall.com http://johannesbrodwall.com http://sterkblanding.no twitter.com/jhannes

More Related