一些行家技巧和窍门

我正在将使用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 NOT
            be included in the final WAR file.  Thus, this directory is removed prior to created the
            webServices 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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值