一些行家技巧和窍门
我正在將使用WebLogic Workshop(是的,使用不受支持的IDE可以正確閱讀)的現有應用程序遷移到Maven。 在旅途中有一些陷阱,我想在這里寫下給那些可能會覺得有用并且特別適合自己的人以作為參考。
整個應用程序使用Apache XMLBeans處理與XML有關的所有事情,這是我遷移到Maven的第一部分。 Maven確實有一個用于XMLBeans的maven插件,下面的代碼片段說明了如何將該插件合并到項目中。
<build><plugins><plugin><groupId>org.codehaus.mojo</groupId><artifactId>xmlbeans-maven-plugin</artifactId><version>2.3.3</version><configuration> <javaSource>1.5</javaSource> </configuration> <executions><execution><phase>generate-sources</phase><goals><goal>xmlbeans</goal></goals></execution></executions></plugin></plugins></build>這里的一個難題是,如果希望生成的XMLBeans代碼具有maxoccurs設置為無界的元素的“列表”數據結構,則需要使用<javaSource> 1.5 </ javaSource>標記。 僅當您的代碼已經使用列表類型時。 沒有此標簽,此插件將僅生成無界元素的數組類型。
接下來,是時候遷移公開應用程序Web服務的模塊了。 當它在WebLogic上運行時,它使用“ jwsc”任務生成了需求工件。 我找不到能滿足此要求的現成的Maven插件,經過一番搜索后,我遇到了通過Maven ant run插件調用ant構建的解決方案。 讓我們看一下pom.xml上所需的配置更改;
<plugin><groupId>org.codehaus.gmaven</groupId><artifactId>gmaven-plugin</artifactId><version>1.3</version><executions><execution><id>set-main-artifact</id><phase>package</phase><goals><goal>execute</goal></goals><configuration><source>project.artifact.setFile(new File(project.build.directory+'/'+project.artifactId+'-'+project.version+'.war'))</source></configuration></execution></executions></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-antrun-plugin</artifactId><version>1.6</version><executions><execution><phase>prepare-package</phase><configuration><target><property name="maven.compile.classpath" refid="maven.compile.classpath" /><property name="maven.runtime.classpath" refid="maven.runtime.classpath" /><property name="maven.test.classpath" refid="maven.test.classpath" /><property name="maven.plugin.classpath" refid="maven.plugin.classpath" /><ant antfile="src/main/ant/build.xml" target="all" /></target></configuration><goals><goal>run</goal></goals></execution></executions><dependencies><dependency><groupId>org.apache.ant</groupId><artifactId>ant</artifactId><version>1.7.1</version><scope>runtime</scope></dependency><dependency><groupId>ant-contrib</groupId><artifactId>ant-contrib</artifactId><version>1.0b2</version><scope>runtime</scope></dependency><dependency><groupId>weblogic</groupId><artifactId>weblogic</artifactId><version>10.3.0</version><scope>compile</scope></dependency><dependency><groupId>weblogic</groupId><artifactId>xmlbeans</artifactId><version>10.3.0</version><scope>compile</scope></dependency><dependency><groupId>weblogic</groupId><artifactId>wlserv</artifactId><version>10.3.0</version><scope>compile</scope></dependency><dependency><groupId>weblogic</groupId><artifactId>jaxwsrt</artifactId><version>10.3.0</version><scope>compile</scope></dependency><dependency><groupId>weblogic</groupId><artifactId>beadescriptor</artifactId><version>10.3.0</version><scope>compile</scope></dependency><dependency><groupId>weblogic</groupId><artifactId>beadescriptorbinding</artifactId><version>10.3.0</version><scope>compile</scope></dependency><dependency><groupId>weblogic</groupId><artifactId>beadescriptorsettable</artifactId><version>10.3.0</version><scope>compile</scope></dependency><dependency><groupId>weblogic</groupId><artifactId>staxb</artifactId><version>10.3.0</version><scope>compile</scope></dependency><dependency><groupId>org.apache.xmlbeans</groupId><artifactId>xmlbeans</artifactId><version>2.4.0</version></dependency><dependency><groupId>weblogic</groupId><artifactId>webservices</artifactId><version>10.3.0</version><scope>compile</scope></dependency><dependency><groupId>com.sun</groupId><artifactId>tools</artifactId><version>1.5.0</version><scope>system</scope><systemPath>${java.home}/../lib/tools.jar</systemPath></dependency></dependencies></plugin><plugin><artifactId>maven-war-plugin</artifactId><version>2.1.1</version><configuration><encoding>UTF-8</encoding></configuration><executions><execution><id>default-war</id><phase>none</phase></execution></executions></plugin>請注意,使用maven install file命令在maven存儲庫中手動安裝了groupId設置為“ weblogic”的依賴項。 所需的jar庫如下:
- wlfullclient.jar(此jar根據此處指定的說明構建)
- webserviceclient.jar
- webservices.jar
- wls-api.jar
- xercesImpl.jar
- xmlParserAPIs.jar
- com.bea.core.descriptor.settable.binding_1.4.0.0.jar
- com.bea.core.descriptor.wl.binding_1.1.0.0.jar
- com.bea.core.descriptor.wl_1.1.0.0.jar
- com.bea.core.xml.beaxmlbeans_1.0.0.0_2-4-0.jar
- com.bea.core.xml.staxb.buildtime_1.3.0.0.jar
- glassfish.jaxws.rt_2.1.3.jar
下一步是將ant build.xml拖放到項目的src / main / ant目錄中。 build.xml如下;
<project name="build-webservice" default="all"><target name="all" depends="build.webService" /><path id="maven_plugin_classpath"><pathelement path="${maven.plugin.classpath}" /></path><path id="maven_runtime_classpath"><pathelement path="${maven.compile.classpath}" /><pathelement path="${maven.runtime.classpath}" /><pathelement path="${maven.plugin.classpath}" /><pathelement path="${weblogic.jar}" /></path><taskdef name="jwsc"classname="weblogic.wsee.tools.anttasks.JwscTask"classpath="${weblogic.jar}"classpathref="maven_plugin_classpath"/><target name="build.webService" description="Compile the web services if not up2date"><!--Eclipse compiles and places classes into target/classes when the workspace is building.If this folder exists when jwsc runs, then any classes that are already compiled will NOTbe included in the final WAR file. Thus, this directory is removed prior to created thewebServices WAR fie.--><delete dir="target/classes" /><jwsc srcdir="${project.build.sourceDirectory}"destDir="target"classpathref="maven_runtime_classpath"keepGenerated="yes"applicationxml="${project.build.directory}/application.xml"fork="true"memorymaximumsize="256m"verbose="true"debug="on"><module contextPath="ws" name="${project.artifactId}-${project.version}"><jwsfileset srcdir="."><include name="**/*.java" /><exclude name="**/*Test.java" /></jwsfileset></module></jwsc> </target> </project>請注意,無需對此build.xml進行任何更改。
接下來,它是關于構建要部署到weblogic的EAR模塊的。 查看由WebLogic Workshop構建的EAR,我可以看到所有必需的第三方庫都被捆綁到了一個名為APP-INF / lib的文件夾中,該文件夾位于EAR的根目錄中。 另外,WAR文件在lib目錄中沒有任何jar文件,我想在使用maven構建EAR時模仿此功能。 以下配置使我能夠做到這一點;
<build><finalName>ErrorXAEAR</finalName><plugins><plugin><artifactId>maven-ear-plugin</artifactId><version>2.10.1</version><configuration><defaultLibBundleDir>APP-INF/lib/</defaultLibBundleDir><skinnyWars>true</skinnyWars><modules><jarModule><groupId>mtn.sa.errorxa</groupId><artifactId>errorxa-ejb</artifactId><bundleDir>/</bundleDir><bundleFileName>ErrorXAEJB.jar</bundleFileName></jarModule><webModule><groupId>mtn.sa.errorxa</groupId><artifactId>errorxa-service</artifactId><bundleDir>/</bundleDir><bundleFileName>ErrorXAService.war</bundleFileName></webModule></modules></configuration></plugin></plugins></build>標簽<skinnyWars>可以使war文件的lib目錄不填充所需的第三方庫,該第三方庫現在捆綁在EAR的APP-INF / lib目錄中。 標記<defaultLibBundleDir>負責將所有必需的庫復制到EAR中名為APP-INF / lib的文件夾中。
關于EAR生成的另一件事是,我不希望maven生成application.xml文件,因為該文件以及weblogic-application.xml已經在項目上生成,因此我想使用它。 為此,我要做的就是將這兩個文件都放到src / main / application文件夾中,并且默認的application.xml被覆蓋。
我發現在構建EAR時,maven的mvndependency:tree工具非常有用,它可以識別和除去通過遞歸依賴關系拖入EAR的不必要的依賴關系。 使用一個簡單的排除標簽,我就可以刪除不需要的庫。
關于這個帖子。 我會不斷更新我可能遇到的任何情況。 下一步是在構建過程中使用maven進行每個應用程序的部署和取消部署。
翻譯自: https://www.javacodegeeks.com/2016/03/maven-tips-tricks.html
總結
- 上一篇: jpa jsf_完整Web应用程序Tom
- 下一篇: 端盒什么意思 端盒指的是什么