提交 d9e17b05 编写于 作者: zhouweidong's avatar zhouweidong

项目支持打war包

上级 8b1491fc
......@@ -15,6 +15,7 @@ TARGET=PSSYSAPP
<artifactId>${pub.getCodeName()?lower_case}-app-${app.getPKGCodeName()?lower_case}</artifactId>
<name>${pub.getCodeName()?lower_case?cap_first} Gateway ${app.getPKGCodeName()}</name>
<description>${pub.getCodeName()?lower_case?cap_first} ${app.getPKGCodeName()}</description>
<packaging>${r'${project.packaging}'}</packaging>
<dependencies>
<dependency>
......@@ -31,11 +32,12 @@ TARGET=PSSYSAPP
</#if>
</dependencies>
<#if pub.getPSDeployCenter()?? && pub.getPSDeployCenter().getPSRegistryRepo()??>
<properties>
<project.packaging>jar</project.packaging>
<#if pub.getPSDeployCenter()?? && pub.getPSDeployCenter().getPSRegistryRepo()??>
<docker.image.prefix>${pub.getPSDeployCenter().getPSRegistryRepo().getConnStr()}</docker.image.prefix>
</properties>
</#if>
</properties>
<profiles>
......@@ -160,6 +162,82 @@ TARGET=PSSYSAPP
</plugins>
</build>
</profile>
<profile>
<id>${app.getPKGCodeName()?lower_case}-war</id>
<properties>
<project.packaging>war</project.packaging>
</properties>
<build>
<resources>
<resource>
<directory>${r'${basedir}'}/src/main/webapp</directory>
<!--注意此次必须要放在此目录下才能被访问到 -->
<targetPath>META-INF/resources</targetPath>
<includes>
<include>**/**</include>
</includes>
</resource>
<resource>
<directory>${r'${basedir}'}/src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>exec-yarn-run-install</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>yarn</executable>
<workingDirectory>../../app_${app.getPKGCodeName()}</workingDirectory>
</configuration>
</execution>
<execution>
<id>exec-yarn-run-build</id>
<phase>prepare-package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>yarn</executable>
<arguments>
<argument>build</argument>
</arguments>
<workingDirectory>../../app_${app.getPKGCodeName()}</workingDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>${pub.getCodeName()?lower_case}-app-${app.getPKGCodeName()?lower_case}</finalName>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
<mainClass>${pub.getPKGCodeName()}.${app.getPKGCodeName()?lower_case}.${app.getPKGCodeName()}Application</mainClass>
<outputDirectory>../../</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
......
<#ibiztemplate>
TARGET=PSSYSAPP
</#ibiztemplate>
<#assign packageType="">
<#if app.getPSDCMSPlatform()??>
<#assign appPlatform=app.getPSDCMSPlatform()>
<#if appPlatform.getUserParam("ibiz.deploy.packagetype","")??>
<#assign packageType = appPlatform.getUserParam("ibiz.deploy.packagetype","")>
</#if>
</#if>
<#if packageType!=''>
package ${pub.getPKGCodeName()}.${app.getPKGCodeName()?lower_case};
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
* 提供外部容器启动服务能力
*/
@Slf4j
public class ${app.getPKGCodeName()}Application extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
log.info("--正在使用外部容器启动服务--");
return builder.sources(${app.getPKGCodeName()}Application.class);
}
}
</#if>
\ No newline at end of file
<#ibiztemplate>
TARGET=PSSYSTEM
</#ibiztemplate>
<#assign packageType="">
<#comment>前端应用微服务平台配置</#comment>
<#if sys.getAllPSDevSlnMSDepApps()??>
<#list sys.getAllPSDevSlnMSDepApps() as depApp>
<#if depApp.getPSDCMSPlatform()??>
<#assign appPlatform=depApp.getPSDCMSPlatform()>
<#if appPlatform.getUserParam("ibiz.deploy.packagetype","")??>
<#assign packageType = appPlatform.getUserParam("ibiz.deploy.packagetype","")>
</#if>
<#break>
</#if>
</#list>
</#if>
<#comment>服务接口微服务平台配置</#comment>
<#if sys.getAllPSDevSlnMSDepAPIs()??>
<#list sys.getAllPSDevSlnMSDepAPIs() as depSysApi>
<#if depSysApi.getPSDCMSPlatform()?? >
<#assign sysApiPlatform=depSysApi.getPSDCMSPlatform()>
<#if sysApiPlatform.getUserParam("ibiz.deploy.packagetype","")??>
<#assign packageType = sysApiPlatform.getUserParam("ibiz.deploy.packagetype","")>
</#if>
<#break>
</#if>
</#list>
</#if>
<#if packageType!=''>
package ${pub.getPKGCodeName()}.core.util.config;
import com.alibaba.cloud.nacos.registry.NacosAutoServiceRegistration;
import com.sa.ajgl.util.errors.BadRequestAlertException;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.ApplicationArguments;
import org.springframework.boot.ApplicationRunner;
import org.springframework.stereotype.Component;
import org.springframework.util.ObjectUtils;
import org.springframework.util.StringUtils;
import javax.management.MBeanServer;
import javax.management.ObjectName;
import javax.management.Query;
import java.lang.management.ManagementFactory;
import java.util.Set;
/**
* 外部容器启动服务时,自动注册服务到nacos
*/
@Component
@Slf4j
public class NacosRegisterConfig implements ApplicationRunner {
@Autowired(required = false)
private NacosAutoServiceRegistration registration;
@Value("${r'${server.port:8080}'}")
Integer port;
@Override
public void run(ApplicationArguments args) {
if (registration != null && port != null) {
try {
String containerPort = getContainerPort();
if(!StringUtils.isEmpty(containerPort)){
log.info("正在尝试将应用程序注册到nacos,端口号为:{}",containerPort);
registration.setPort(new Integer(containerPort));
registration.start();
}
} catch (Exception e) {
throw new BadRequestAlertException("应用程序注册到nacos失败,"+e,"","");
}
}
}
/**
* 获取外部容器端口
*/
public String getContainerPort() throws Exception {
String port = null;
MBeanServer beanServer = ManagementFactory.getPlatformMBeanServer();
Set<ObjectName> objectNames = beanServer.queryNames(new ObjectName("*:type=Connector,*"), Query.match(Query.attr("protocol"), Query.value("HTTP/1.1")));
if(!ObjectUtils.isEmpty(objectNames)){
port = objectNames.iterator().next().getKeyProperty("port");
}
return port;
}
}
</#if>
\ No newline at end of file
......@@ -15,6 +15,7 @@ TARGET=PSSYSSERVICEAPI
<artifactId>${pub.getCodeName()?lower_case}-provider-${api.getCodeName()?lower_case}</artifactId>
<name>${pub.getCodeName()?lower_case?cap_first} Microservice ${api.getCodeName()}</name>
<description>${pub.getMemo()?default(pub.getName())} ${api.getName()}</description>
<packaging>${r'${project.packaging}'}</packaging>
<dependencies>
<dependency>
......@@ -26,9 +27,12 @@ TARGET=PSSYSSERVICEAPI
<#if pub.getPSDeployCenter()?? && pub.getPSDeployCenter().getPSRegistryRepo()??>
<properties>
<project.packaging>jar</project.packaging>
<#if pub.getPSDeployCenter()?? && pub.getPSDeployCenter().getPSRegistryRepo()??>
<docker.image.prefix>${pub.getPSDeployCenter().getPSRegistryRepo().getConnStr()}</docker.image.prefix>
</#if>
</properties>
</#if>
<profiles>
<profile>
......@@ -118,6 +122,43 @@ TARGET=PSSYSSERVICEAPI
</plugins>
</build>
</profile>
<profile>
<id>${item.codeName?lower_case}-war</id>
<properties>
<project.packaging>war</project.packaging>
</properties>
<build>
<resources>
<resource>
<directory>${r'${basedir}'}/src/main/resources</directory>
<includes>
<include>**/**</include>
</includes>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<finalName>${pub.getCodeName()?lower_case}-provider-${item.codeName?lower_case}</finalName>
<jvmArguments>-Dfile.encoding=UTF-8</jvmArguments>
<mainClass>${pub.getPKGCodeName()}.${item.codeName?lower_case}.${sys.codeName}${item.codeName}Application</mainClass>
<outputDirectory>../../</outputDirectory>
</configuration>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
<#ibiztemplate>
TARGET=PSSYSSERVICEAPI
</#ibiztemplate>
<#assign packageType="">
<#if item.getPSDCMSPlatform()?? >
<#assign sysApiPlatform=item.getPSDCMSPlatform()>
<#if sysApiPlatform.getUserParam("ibiz.deploy.packagetype","")??>
<#assign packageType = sysApiPlatform.getUserParam("ibiz.deploy.packagetype","")>
</#if>
</#if>
<#if packageType!=''>
package ${pub.getPKGCodeName()}.${item.codeName?lower_case};
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.servlet.support.SpringBootServletInitializer;
/**
* 提供外部容器启动服务能力
*/
@Slf4j
public class ${sys.codeName}${item.codeName}Initializer extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder builder) {
log.info("--正在使用外部容器启动服务--");
return builder.sources(${sys.codeName}${item.codeName}Application);
}
}
</#if>
\ No newline at end of file
Markdown 格式
0% or
您添加了 0 到此讨论。请谨慎行事。
先完成此消息的编辑!
想要评论请 注册