You need to create 3 files, and they are web.xml, pom.xml, weblogic.xml(optional) in your existing react project. we put all file in the root directory of the react project.
Mainly to tell which version of WebLogic we are using, and the context-root of the project. If you are cool with the context-root as your war file name, you can skip this part.
what is context-root? https://wwww.your_domain.com/context_root/… ←–the 'path' right after your domain name is context-root. In the following config, our context-root would be myapp
.
<?xml version="1.0" encoding="UTF-8"?> <wls:weblogic-web-app xmlns:wls="http://xmlns.oracle.com/weblogic/weblogic-web-app" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd http://xmlns.oracle.com/weblogic/weblogic-web-app http://xmlns.oracle.com/weblogic/weblogic-web-app/1.9/weblogic-web-app.xsd"> <wls:context-root>myapp</wls:context-root> <wls:weblogic-version>12.2.1</wls:weblogic-version> <wls:container-descriptor> </wls:container-descriptor> </wls:weblogic-web-app>
To tell the container that this is a web app. Change YOUR COOL APP NAME
yourself.
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>YOUR COOL APP NAME</display-name> <error-page> <error-code>404</error-code> <location>/index.html</location> </error-page> </web-app>
This file is shamelessly heavily copy from https://www.megadix.it/blog/create-react-app-servlet/. If you want to know the details, place him a visit.
This pom build the react project, and then copy the built files, the weblog.xml, and the web.xml in to the resulting war file. Of course, you need to update the info to suit your project.
If your react code is kind of broken, and cannot pass the CI testing, you can set it to false for a while for a quick dirty test.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>YOUR_PROJECT_GROUP_ID</groupId> <artifactId>YOUR_ARTIFACT_ID</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>war</packaging> <name>YOUR_PEOJECT_NAME</name> <description>YOUR_PEOJECT_DESCRIPTION</description> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <npm.output.directory>build</npm.output.directory> </properties> <build> <finalName>cmdctr-webapp-${project.version}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-war-plugin</artifactId> <version>3.3.1</version> <configuration> <webResources> <resource> <directory>${npm.output.directory}</directory> </resource> <resource> <directory>${basedir}</directory> <includes> <include>weblogic.xml</include> </includes> <targetPath>WEB-INF/</targetPath> </resource> </webResources> <webXml>${basedir}/web.xml</webXml> </configuration> </plugin> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <version>3.0.0</version> <executions> <!-- Required: The following will ensure `npm install` is called before anything else during the 'Default Lifecycle' --> <execution> <id>npm install (initialize)</id> <goals> <goal>exec</goal> </goals> <phase>initialize</phase> <configuration> <executable>npm</executable> <arguments> <argument>install</argument> </arguments> </configuration> </execution> <!-- Required: The following will ensure `npm install` is called before anything else during the 'Clean Lifecycle' --> <execution> <id>npm install (clean)</id> <goals> <goal>exec</goal> </goals> <phase>pre-clean</phase> <configuration> <executable>npm</executable> <arguments> <argument>install</argument> </arguments> </configuration> </execution> <!-- Required: This following calls `npm run build` where 'build' is the script name I used in my project, change this if yours is different --> <execution> <id>npm run build (compile)</id> <goals> <goal>exec</goal> </goals> <phase>compile</phase> <configuration> <executable>npm</executable> <arguments> <argument>run</argument> <argument>build</argument> </arguments> </configuration> </execution> </executions> <configuration> <environmentVariables> <CI>true</CI> <!-- The following parameters create an NPM sandbox for CI --> <NPM_CONFIG_PREFIX>${basedir}/npm</NPM_CONFIG_PREFIX> <NPM_CONFIG_CACHE>${NPM_CONFIG_PREFIX}/cache</NPM_CONFIG_CACHE> <NPM_CONFIG_TMP>${project.build.directory}/npmtmp</NPM_CONFIG_TMP> </environmentVariables> </configuration> </plugin> </plugins> </build> <profiles> <profile> <id>local</id> <activation> <activeByDefault>true</activeByDefault> </activation> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <configuration> <environmentVariables> <PUBLIC_URL>http://localhost:8080/${project.artifactId}</PUBLIC_URL> <REACT_APP_ROUTER_BASE>/${project.artifactId}</REACT_APP_ROUTER_BASE> </environmentVariables> </configuration> </plugin> </plugins> </build> </profile> <profile> <id>prod</id> <build> <plugins> <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>exec-maven-plugin</artifactId> <configuration> <environmentVariables> <PUBLIC_URL>https://www.YOUR_DOMAIN.COM:PORT_NUMBER/YOUR_CONTEXT_ROOT </PUBLIC_URL> <REACT_APP_ROUTER_BASE>/${project.artifactId}</REACT_APP_ROUTER_BASE> </environmentVariables> </configuration> </plugin> </plugins> </build> </profile> </profiles> </project>