当前位置: 首页 > news >正文

使用Maven部署WebLogic应用

使用Maven部署WebLogic应用

在Maven项目中部署应用到WebLogic服务器可以通过以下几种方式实现:

1. 使用WebLogic Maven插件 (官方推荐)

Oracle提供了官方的WebLogic Maven插件,这是最直接的部署方式。

基本配置

<build><plugins><plugin><groupId>com.oracle.weblogic</groupId><artifactId>weblogic-maven-plugin</artifactId><version>12.2.1.4.0</version><configuration><adminurl>t3://localhost:7001</adminurl><user>weblogic</user><password>welcome1</password><upload>true</upload><remote>false</remote><verbose>true</verbose><source>${project.build.directory}/${project.build.finalName}.war</source><name>${project.build.finalName}</name></configuration><executions><execution><id>deploy</id><phase>deploy</phase><goals><goal>deploy</goal></goals></execution></executions></plugin></plugins>
</build>

常用命令

  • 部署应用:mvn weblogic:deploy
  • 重新部署:mvn weblogic:redeploy
  • 取消部署:mvn weblogic:undeploy
  • 启动应用:mvn weblogic:start
  • 停止应用:mvn weblogic:stop

2. 使用Cargo插件

Cargo提供了通用的应用服务器部署支持,包括WebLogic。

配置示例

<plugin><groupId>org.codehaus.cargo</groupId><artifactId>cargo-maven2-plugin</artifactId><version>1.9.11</version><configuration><container><containerId>weblogic12x</containerId><type>remote</type></container><configuration><type>runtime</type><properties><cargo.remote.uri>t3://localhost:7001</cargo.remote.uri><cargo.remote.username>weblogic</cargo.remote.username><cargo.remote.password>welcome1</cargo.remote.password></properties></configuration><deployables><deployable><groupId>${project.groupId}</groupId><artifactId>${project.artifactId}</artifactId><type>war</type><properties><context>${project.build.finalName}</context></properties></deployable></deployables></configuration>
</plugin>

常用命令

  • 部署:mvn cargo:deploy
  • 重新部署:mvn cargo:redeploy
  • 取消部署:mvn cargo:undeploy

3. 使用Ant任务通过Maven部署

结合maven-antrun-plugin和WebLogic的Ant任务:

<plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-antrun-plugin</artifactId><version>3.1.0</version><executions><execution><phase>deploy</phase><goals><goal>run</goal></goals><configuration><target><taskdef name="wldeploy" classname="weblogic.ant.taskdefs.management.WLDeploy"classpath="${weblogic.home}/server/lib/weblogic.jar"/><wldeploy action="deploy"verbose="true"debug="false"name="${project.build.finalName}"source="${project.build.directory}/${project.build.finalName}.war"adminurl="t3://localhost:7001"user="weblogic"password="welcome1"targets="AdminServer"upload="true"/></target></configuration></execution></executions>
</plugin>

4. 使用WebLogic Deployer工具

WebLogic 12.2.1及以上版本提供了新的部署工具:

<plugin><groupId>org.codehaus.mojo</groupId><artifactId>exec-maven-plugin</artifactId><version>3.1.0</version><executions><execution><id>deploy-app</id><phase>deploy</phase><goals><goal>exec</goal></goals><configuration><executable>${weblogic.home}/oracle_common/common/bin/wlst.sh</executable><arguments><argument>${basedir}/src/main/scripts/deploy.py</argument><argument>${project.build.directory}/${project.build.finalName}.war</argument></arguments></configuration></execution></executions>
</plugin>

对应的deploy.py脚本示例:

connect('weblogic', 'welcome1', 't3://localhost:7001')
deploy('myapp', '/path/to/app.war', targets='AdminServer')
startApplication('myapp')
disconnect()

安全配置建议

  1. 不要在pom.xml中硬编码密码

    <configuration><user>${weblogic.username}</user><password>${weblogic.password}</password>
    </configuration>
    

    然后在settings.xml中配置:

    <servers><server><id>weblogic-server</id><username>weblogic</username><password>welcome1</password></server>
    </servers>
    
  2. 使用加密密码

    <password>{DES}encrypted_password</password>
    

多环境部署配置

<profiles><profile><id>dev</id><properties><weblogic.adminurl>t3://dev-server:7001</weblogic.adminurl></properties></profile><profile><id>prod</id><properties><weblogic.adminurl>t3://prod-server:7001</weblogic.adminurl></properties></profile>
</profiles>

使用命令指定环境:mvn deploy -Pprod

常见问题解决

  1. ClassNotFoundException: weblogic.Deployer
    确保weblogic.jar在类路径中,可以通过设置weblogic.home属性指定WebLogic安装目录。

  2. 认证失败
    检查用户名/密码是否正确,确保用户有部署权限。

  3. 连接超时
    检查WebLogic服务器是否运行,网络是否通畅,防火墙设置。

  4. 版本不兼容
    确保插件版本与WebLogic服务器版本匹配。

以上方法可以根据项目需求选择使用,官方WebLogic Maven插件通常是最简单直接的选择。

http://www.xdnf.cn/news/495397.html

相关文章:

  • 信贷风控笔记6——风控常用指标(面试准备14)
  • MATLAB学习笔记(六):MATLAB数学建模
  • Uniapp、Flutter 和 React Native 全面对比
  • 分糖果--思维+while判断
  • 基于QT和FFmpeg实现自己的视频播放器FFMediaPlayer(一)——项目总览
  • 芯片生态链深度解析(二):基础设备篇——人类精密制造的“巅峰对决”
  • StarRocks MCP Server 开源发布:为 AI 应用提供强大分析中枢
  • gcc 源码目录文件夹功能简介
  • 从辅助到协作:GitHub Copilot的进化之路
  • 副业小程序YUERGS,从开发到变现
  • String的一些固定程序函数
  • 嵌入式学习笔记 - STM32 使用一个外部触发同时启动两个定时器
  • 谷歌浏览器(Google Chrome)136.0.7103.93便携增强版|Win中文|安装教程
  • 2.1.3
  • 【Linux网络】NAT和代理服务
  • AtCoder AT_abc406_c [ABC406C] ~
  • MySQL相关
  • 数据结构【AVL树】
  • vue2 切换主题色以及单页面好使方法
  • 自己手写tomcat项目
  • Redis INCR 命令详解
  • 学习笔记:黑马程序员JavaWeb开发教程(2025.4.6)
  • C++学习:六个月从基础到就业——C++11/14:列表初始化
  • Java 类和对象
  • 从紫光集团看基本财务分析
  • 构建集成差异化灵巧手和先进机器人控制技术的自动化系统
  • 每日算法刷题Day9 5.17:leetcode定长滑动窗口3道题,用时1h
  • 5000 字总结CSS 中的过渡、动画和变换详解
  • 每日Prompt:生成自拍照
  • php fiber 应用