weblogic安装部署war包——windows

时间:2023-12-10 17:30:08

### weblogic安装部署war包——windows
#### 下载weblogic安装包
[csdn下载地址](https://download.csdn.net/download/luozhuang/10558048)
[官网下载地址](https://www.oracle.com/technetwork/middleware/weblogic/downloads/index.html)(这是快速安装版)
#### 安装weblgic
参考[WebLogicServer12.2.1.3服务器安装配置步骤详解](https://jingyan.baidu.com/article/4d58d54164eff49dd4e9c095.html)

**注意**
安装weblogic的jar包需要放置在jdk的home路径下,然后cd到该路径,在执行该jar。不然在执行java-jar命令时报错不是有效的 JDK Java 主目录。

#### weblogic部署普通war包
[weblogic使用方法]()
**注意**
这里不需要额外的配置,直接将打好的包上传即可。部署成功之后访问路径为**http://ip:端口号/上下文根**。上下文根一般指war包名称

#### weblogic部署springboot的war包
**注意,这里指的是纯springboot,不确定自己的项目部是不是纯springboot的时候,就用上面的方式**

[参考网址](https://blog.csdn.net/wonderful_life_mrchi/article/details/77915757)

修改项目的pom文件改为打war包,并排除到springboot-start-web中的tomcat,加上单独的tomcat,设置域为provided

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<exclusions>
<exclusion>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>

**实现WebApplicationInitializer**,入口类继承SpringBootServletInitializer类并实现WebApplicationInitializer类,然后重写configure方法。直接复制改方法即可。最后打成war包部署。

package com.example;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.web.WebApplicationInitializer;

@SpringBootApplication
public class DemoApplication extends SpringBootServletInitializer implements WebApplicationInitializer {
@Override
public SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(DemoApplication.class);
}
public static void main(String[] args) {
SpringApplication.run(DemoApplication.class, args);
}
}

#### 可能会出现的问题
##### 问题一 XXXX.<init>()

<2019-4-19 下午11时21分13,962秒 CST> <Error> <Console> <BEA-240003> <Administrat
ion Console encountered the following error: weblogic.application.ModuleExceptio
n: java.lang.NoSuchMethodException: com.famessoft.oplus.cac.CacApp.<init>()
at weblogic.application.internal.ExtensibleModuleWrapper.start(Extensibl
eModuleWrapper.java:140)
at weblogic.application.internal.flow.ModuleListenerInvoker.start(Module
ListenerInvoker.java:124)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleSta
teDriver.java:233)
at weblogic.application.internal.flow.ModuleStateDriver$3.next(ModuleSta
teDriver.java:228)
at weblogic.application.utils.StateMachineDriver.nextState(StateMachineD
river.java:45)
at weblogic.application.internal.flow.ModuleStateDriver.start(ModuleStat
eDriver.java:78)
at weblogic.application.internal.flow.StartModulesFlow.activate(StartMod
ulesFlow.java:52)

**解决方法**
**这是因为我的项目不是纯正的springboot项目,这是用Jhipster自动创建的。所以不能用weblogic部署springboot项目的方法来部署。这样就会画蛇添足,直接用原来的包即可**

##### 问题二 java.lang.ClassNotFoundException: com.querydsl.core.dml.UpdateClause

<2019-4-19 上午12时48分47,065秒 CST> <Warning> <Deployer> <BEA-149004> <Failures
were detected while initiating deploy task for application "oplus-cac".>
<2019-4-19 上午12时48分47,067秒 CST> <Warning> <Deployer> <BEA-149078> <Stack tr
ace for message 149004
weblogic.management.DeploymentException: java.lang.ClassNotFoundException: com.q
uerydsl.core.dml.UpdateClause
at weblogic.application.internal.BaseDeployment.throwAppException(BaseDe
ployment.java:132)
at weblogic.application.internal.BaseDeployment.prepare(BaseDeployment.j
ava:244)
at weblogic.application.internal.SingleModuleDeployment.prepare(SingleMo
duleDeployment.java:52)
at weblogic.application.internal.DeploymentStateChecker.prepare(Deployme
ntStateChecker.java:158)
at weblogic.deploy.internal.targetserver.AppContainerInvoker.prepare(App
ContainerInvoker.java:65)
Truncated. see log file for complete stacktrace
Caused By: java.lang.ClassNotFoundException: com.querydsl.core.dml.UpdateClause
at weblogic.utils.classloaders.GenericClassLoader.findLocalClass(Generic
ClassLoader.java:1029)
at weblogic.utils.classloaders.GenericClassLoader.findClass(GenericClass
Loader.java:990)
at weblogic.utils.classloaders.ChangeAwareClassLoader.findClass(ChangeAw
areClassLoader.java:104)
at weblogic.utils.classloaders.GenericClassLoader.doFindClass(GenericCla
ssLoader.java:611)

**解决方法**
**这是因为我们的项目引用了jpa相关的包没有被加载到,weblogic找不到这个包。需要把 `querydsl-core-4.1.4.jar`和`querydsl-jpa-4.1.4.jar`这两个包放到`D:\Oracle\Middleware\Oracle_Home\user_projects\domains\base_domain\lib`(weblogic的home目录下)。经反复测试,不需要像网上说的添加weblogic.xml或者其他设置。。**

pom文件即

<!-- https://mvnrepository.com/artifact/com.querydsl/querydsl-jpa -->
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-jpa</artifactId>
<version>4.1.4</version>
</dependency>
<dependency>
<groupId>com.querydsl</groupId>
<artifactId>querydsl-core</artifactId>
</dependency>