480 likes | 649 Views
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 ...
E N D
Jeg har så vondt i mvn JavaBin, 10. mars, 2011 Johannes Brodwall
mvn intro archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea
$ 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: ….
[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:
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:
[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] ------------------------------------------------------------------------
/** * 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 ); } }
mvn intro archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea
mvn intro archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea
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
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
mvn intro archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea
mvn intro archetype:generate test – package – install – deploy eclipse:eclipse/idea:idea
$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
mvnbasics SNAPSHOT vsrelease-versions repositories modules
Jeg har så vondt i mvn Transitive dependencies Fragmenterte prosjekter Plugin overbruk
$ 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!?!!
<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>
“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
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….
Dependencynightmare Excludes Votewithyour feet Make it better: Avoidreuse
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
mvn-release-plugin liker ikke SNAPSHOTs
Hvor ligger PersonDAO? no.steria.person? no.steria.dao?
Konsistens? Koherens?
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
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)
Fragmenterte prosjekter Koherens > Konsistens Unngå å splitte Deployment kan kreve splitt
Plugins Java > Mvnplugins antrun-plugin Main-klasser
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?
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();
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();
<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>
<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>
Plugins Java > Mvnplugins antrun-plugin Main-klasser
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
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.
Takk for oppmerksomheten johannes@brodwall.com http://johannesbrodwall.com http://sterkblanding.no twitter.com/jhannes