应行家算法_一些行家技巧和窍门
應(yīng)行家算法
我正在將使用WebLogic Workshop(是的,使用不受支持的IDE可以正確閱讀)的現(xiàn)有應(yīng)用程序遷移到Maven。 在旅途中有一些陷阱,我想在這里寫下給那些可能會覺得有用的人,特別是對我自己而言作為參考。
整個應(yīng)用程序使用Apache XMLBeans處理與XML有關(guān)的所有事情,這是我要遷移到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設(shè)置為無界的元素的“列表”數(shù)據(jù)結(jié)構(gòu),則需要使用<javaSource> 1.5 </ javaSource>標(biāo)記。 僅當(dāng)您的代碼已在使用列表類型時。 沒有此標(biāo)簽,此插件將僅生成無界元素的數(shù)組類型。
接下來,是時候遷移公開應(yīng)用程序Web服務(wù)的模塊了。 當(dāng)它在WebLogic上運行時,它使用“ jwsc”任務(wù)生成了需求工件。 我找不到能滿足此要求的現(xiàn)成的Maven插件,經(jīng)過一番搜索后,我遇到了通過Maven ant run插件調(diào)用ant構(gòu)建的解決方案。 讓我們看一下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命令將在groupId中設(shè)置為“ weblogic”的依賴項手動安裝在maven存儲庫中。 所需的jar庫如下:
- wlfullclient.jar(此jar根據(jù)此處指定的說明構(gòu)建)
- 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進(jìn)行任何更改。
接下來,它是關(guān)于構(gòu)建要部署到weblogic的EAR模塊的。 查看由WebLogic Workshop構(gòu)建的EAR,我可以看到所有必需的第三方庫都被捆綁到了一個名為APP-INF / lib的文件夾中,該文件夾位于EAR的根目錄中。 另外,WAR文件在lib目錄中沒有任何jar文件,我想在使用maven構(gòu)建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>標(biāo)簽<skinnyWars>可以使war文件的lib目錄不填充所需的第三方庫,該第三方庫現(xiàn)在捆綁在EAR的APP-INF / lib目錄中。 標(biāo)記<defaultLibBundleDir>負(fù)責(zé)將所有必需的庫復(fù)制到EAR中名為APP-INF / lib的文件夾中。
關(guān)于EAR生成的另一件事是,我不希望maven生成application.xml文件,因為該文件以及weblogic-application.xml已經(jīng)在項目上生成,因此我想使用它。 為此,我要做的就是將這兩個文件都放到src / main / application文件夾中,并且默認(rèn)的application.xml被覆蓋。
我發(fā)現(xiàn)在構(gòu)建EAR時,Maven的mvndependency:tree工具非常有用,它可以識別和除去通過遞歸依賴關(guān)系拖入EAR的不必要的依賴關(guān)系。 使用一個簡單的排除標(biāo)簽,我就可以刪除不需要的庫。
關(guān)于這個帖子。 我會不斷更新我可能遇到的任何事情。 下一步是在構(gòu)建過程中使用maven進(jìn)行每個應(yīng)用程序的部署和取消部署。
翻譯自: https://www.javacodegeeks.com/2016/03/maven-tips-tricks.html
應(yīng)行家算法
總結(jié)
以上是生活随笔為你收集整理的应行家算法_一些行家技巧和窍门的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 安卓半透明颜色代码(安卓半透明)
- 下一篇: 多个定时器相互干扰的问题_相互问题