How to set REACT_APP_ROUTER_BASE for react app when configured with Jetty server - reactjs

I have created a test react project and were trying to host it on Jetty server. My pom.xml looks like this :
<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">
<!--
Adapted from:
https://gist.github.com/phillipgreenii/7c954e3c3911e5c32bd0
-->
<modelVersion>4.0.0</modelVersion>
<groupId>it.megadix</groupId>
<artifactId>create-react-app-hello-world</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<npm.output.directory>build</npm.output.directory>
</properties>
<build>
<finalName>${project.artifactId}</finalName>
<plugins>
<!-- Standard plugin to generate WAR -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>2.1.1</version>
<configuration>
<webResources>
<resource>
<directory>${npm.output.directory}</directory>
</resource>
</webResources>
<webXml>${basedir}/web.xml</webXml>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.3.2</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>http://153.214.189.19:8080/${project.artifactId}</PUBLIC_URL>
<REACT_APP_ROUTER_BASE>/${project.artifactId}</REACT_APP_ROUTER_BASE>
</environmentVariables>
</configuration>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
I have built this project using Maven.
[INFO] Building war: C:\Users\gpoo\source\repos\react\hello-world\target\create-react-app-hello-world.war
[WARNING] Warning: selected war files include a WEB-INF/web.xml which will be ignored
(webxml attribute is missing from war task, or ignoreWebxml attribute is specified as 'true')
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 01:54 min
[INFO] Finished at: 2022-06-02T12:52:44+05:30
[INFO] ------------------------------------------------------------------------
PS C:\Users\gpoo\source\repos\react\hello-world>
On jetty have created a .xml file, which sets the context manager.
[root#node1 webapps]# cat create-react-app-hello-world.xml
<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
"http://www.eclipse.org/jetty/configure.dtd">
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<Set name="contextPath">/create-react-app-hello-world</Set>
<Set name="war">/tmp/create-react-app-hello-world.war</Set>
</Configure>
In spite of this, i am unable to get the output:
GET http://153.214.189.19:8080/static/js/main.f64f7128.chunk.js net::ERR_ABORTED 404 (Not Found)
Please guide me.

Related

Gatling : Scala - Could not find or load main class Engine

I am getting error Could not find or load main class Engine while running the simulation through command line. I used below command to create the jar file.
mvn clean scala:compile assembly:single package
Folder Structure
src
test
resources
scala
testrunner
testsimuation1.scala
Engine
IDEPathHelper
Recorder
Maven - 3.6.3
Intellij - 2021.1
Scala - 2.13.10
Gatling - 3.9.0
JDK - 1.8
Below is the POM.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>io.gatling.demo</groupId>
<artifactId>gatling-maven-plugin-demo-scala</artifactId>
<version>3.9.0</version>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<gatling.version>${project.version}</gatling.version>
<gatling-maven-plugin.version>4.2.9</gatling-maven-plugin.version>
<maven-jar-plugin.version>3.2.0</maven-jar-plugin.version>
<scala-maven-plugin.version>4.8.0</scala-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>io.gatling.highcharts</groupId>
<artifactId>gatling-charts-highcharts</artifactId>
<version>${gatling.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/test/resources</directory>
</resource>
</resources>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<pluginManagement>
<plugins>
<plugin>
<groupId>io.gatling</groupId>
<artifactId>gatling-maven-plugin</artifactId>
<version>${gatling-mvn-plugin.version}</version>
<configuration>
<configFolder>src/test/resources</configFolder>
<simulationsFolder>src/test/scala</simulationsFolder>
<resultsFolder>src/results</resultsFolder>
<simulationClass>testrunner.testsimuation1</simulationClass>
<jvmArgs>
<jvmArg>-Dsimulation=testsimuation1</jvmArg>
<jvmArg>-Xmx6g</jvmArg>
<jvmArg>-Xms2g</jvmArg>
</jvmArgs>
</configuration>
</plugin>
<plugin>
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>4.4.1</version>
<executions>
<execution>
<id>scala-compile-first</id>
<phase>process-resources</phase>
<goals>
<goal>add-source</goal>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>io.gatling.app.Gatling</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I tried moving src/test -> src/main but it threw the compilation error. Using this tool for the first time and struggling to resolve the issues.
I tried few solutions from other threads. It didn't help.
Thanks
The Engine class is only supposed to be used as a helper to launch with a "Right Click" when using your IDE.
Using this tool for the first time and struggling to resolve the issues.
You're using maven. The way you're supposed to be running Gatling with maven is to run mvn gatling:test, see gatling-maven-plugin's documentation.
Whatever else you're doing with maven-assembly-plugin is custom development, not really related to Gatling.
Note: if you're looking for handling Gatling deployments, Gatling Enterprise is an option.

How can I correctly install the extend QrScanner

I already installed the extend, but the documentation says that I have to reload the app (I've tried everything and can't do it), before it was only necessary to refresh the CN1Libs, how should I do it now?
private void lectorCodigoQR() {
if (CodeScanner.isSupported()) {
CodeScanner.getInstance().scanQRCode(new ScanResult() {
#Override
public void scanCompleted(String contents, String formatName, byte[] rawBytes) {
// Mostrar
}
#Override
public void scanCanceled() {
System.out.println("cancelled");
}
#Override
public void scanError(int errorCode, String message) {
System.out.println("err " + message);
}
});
} else {
Dialog.show("Error", "Su dispositivo no soporta el lector de QR", "Continuar", null);
}
}
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>com.innova507.taxi507</groupId>
<artifactId>taxi507</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.innova507.taxi507</groupId>
<artifactId>taxi507-common</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- Add your cn1lib dependencies to this section -->
<dependencies>
<dependency>
<groupId>com.codenameone</groupId>
<artifactId>codenameone-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>taxi507-cn1-codescan</artifactId>
<groupId>com.innova507.taxi507</groupId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
<!-- INJECT DEPENDENCIES -->
</dependencies>
<!-- The following are profiles to cover special cases -->
<profiles>
<!-- A profile to install Codename One support libraries to your home directory
if they aren't installed yet. -->
<profile>
<id>install-codenameone</id>
<activation>
<file>
<missing>${user.home}/.codenameone/guibuilder.jar</missing>
</file>
</activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="install-cn1">
<available file="${user.home}/.codenameone/guibuilder.jar" property="codenameone.present"/>
<mkdir dir="${user.home}/.codenameone"/>
<mkdir dir="${project.build.directory}/codenameone/tmpProject"/>
<get src="https://www.codenameone.com/files/updates/UpdateCodenameOne.jar"
dest="${user.home}/UpdateCodenameOne.jar"
skipexisting="true"/>
<java jar="${user.home}/UpdateCodenameOne.jar" fork="true">
<arg value="${project.build.directory}/codenameone/tmpProject"/>
<arg value="force"/>
</java>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- A profile to add kotlin support. Activated if the src/main/kotlin
directory exists -->
<profile>
<id>kotlin</id>
<activation>
<file>
<!-- To enable Kotlin, add the following file to the project base dir -->
<exists>${basedir}/src/main/kotlin</exists>
</file>
</activation>
<properties>
<kotlin.version>1.3.72</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-annotations-jvm -->
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
</dependency>
<dependency>
<groupId>com.codenameone</groupId>
<artifactId>java-runtime</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/codenameone_settings.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
<args>
<arg>-no-reflect</arg>
<arg>-no-jdk</arg> <!-- No JDK -->
</args>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
<args>
<arg>-no-reflect</arg>
<arg>-no-jdk</arg> <!-- No JDK -->
</args>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>javase</id>
<activation>
<property>
<name>codename1.platform</name>
<value>javase</value>
</property>
</activation>
<properties>
<codename1.targetPlatform>javase</codename1.targetPlatform>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<longClasspath>true</longClasspath>
<arguments>
<argument>-Xmx1024M</argument>
<!--<argument>-Xdebug</argument>
<argument>-Xrunjdwp:transport=dt_socket,address=8888,server=y,suspend=n</argument>-->
<argument>-classpath</argument>
<classpath />
<argument>${exec.mainClass}</argument>
<argument>${cn1.mainClass}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!--
For running in simulator in process use:
mvn cn1:java -P simulator
Fro running in simulator in forked process use:
mvn cn1:simulator -P simulator
-->
<id>simulator</id>
<properties>
<codename1.targetPlatform>javase</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending iOS debug builds use:
mvn cn:build -P ios-debug
-->
<id>ios-debug</id>
<properties>
<!-- Build server target type -->
<codename1.targetType>iphone</codename1.targetType>
<!-- Used for identifying native interfaces. Should match correct subdirectory of native -->
<codename1.targetPlatform>ios</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending iOS debug builds use:
mvn cn:build -P ios-release
-->
<id>ios-release</id>
<properties>
<!-- Build server target type -->
<codename1.targetType>iphone</codename1.targetType>
<codename1.production>true</codename1.production>
<!-- Used for identifying native interfaces. Should match correct subdirectory of native -->
<codename1.targetPlatform>ios</codename1.targetPlatform>
<codename1.appStoreBuild>true</codename1.appStoreBuild>
</properties>
</profile>
<profile>
<!--
For sending Javascript builds use:
mvn cn:build -P javascript
-->
<id>javascript</id>
<properties>
<codename1.targetType>javascript</codename1.targetType>
<codename1.targetPlatform>javascript</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending Android builds use:
mvn cn:build -P android
-->
<id>android</id>
<properties>
<codename1.targetType>android</codename1.targetType>
<codename1.targetPlatform>android</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending Windows UWP builds use:
mvn cn:build -P uwp
-->
<id>uwp</id>
<properties>
<codename1.targetType>windows</codename1.targetType>
<codename1.targetPlatform>win</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending Windows desktop builds use:
mvn cn:build -P windows
-->
<id>windows</id>
<properties>
<codename1.targetType>desktop_windows</codename1.targetType>
<codename1.targetPlatform>javase</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending Mac Desktop builds use:
mvn cn:build -P mac
-->
<id>mac</id>
<properties>
<codename1.targetType>desktop_macosx</codename1.targetType>
<codename1.targetPlatform>javase</codename1.targetPlatform>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/codenameone_settings.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.codenameone</groupId>
<artifactId>codenameone-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-gui-sources</id>
<phase>process-sources</phase>
<goals>
<goal>generate-gui-sources</goal>
</goals>
</execution>
<execution>
<id>cn1-process-classes</id>
<phase>process-classes</phase>
<goals>
<goal>compliance-check</goal>
<goal>css</goal>
<!--<goal>compile-javase-sources</goal>-->
</goals>
</execution>
<execution>
<id>attach-test-artifact</id>
<phase>test</phase>
<goals>
<goal>attach-test-artifact</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I have included an image of the tree where it shows the menu on the pom and I don't see a way to update it. I am also including the pom.xml (if it has the extension included)
https://drive.google.com/drive/folders/1LVBZPMCTTTEZxEYfwrh3S2_fPzyktTiN
This is an answer from Steve Hannha:
I just created a fresh project in the cn1 intializr with "NetBeans" selected as the IDE.
Opened project in NetBeans 12.3 on Windows 10.
Opened CN1 Settings.
Installed Codename One Scanner library.
Initially the text editor wasn't giving me any autocomplete or error-underlines on anything, even from cn1 core classes.
I right-clicked on the "common" module, and selected "Resolve Project Problems"
I got a dialog with errors like "Some dependency artifacts are not in the local repository".
When I pressed the "Resolve..." button in that dialog, it downloaded the dependencies and things started to magically work.

Codename One - GifImage not supported

I am developing a simple Android-Mobile-App that uses a Gif. It's a Maven project.
I have imported the Animated-Gif-Support library and used the code form here.
Unfortunately, when I paste the sample code into my project, Eclipse can't find the method and returns the error: GifImage cannot be resolved.
hi.add(BorderLayout.CENTER, new ScaleImageLabel(GifImage.decode(getResourceAsStream("/giphy-downsized.gif"), 1177720)));
I have restarted Eclipse and refreshed the libraries, all to no avail.
Any suggestions?
Code from pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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>
<parent>
<groupId>com.example.minhaagenda</groupId>
<artifactId>minhaagenda</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.example.minhaagenda</groupId>
<artifactId>minhaagenda-common</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<!-- Add your cn1lib dependencies to this section -->
<dependencies>
<dependency>
<groupId>com.codenameone</groupId>
<artifactId>codenameone-core</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<artifactId>minhaagenda-AnimatedGifSupport</artifactId>
<groupId>com.example.minhaagenda</groupId>
<version>1.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
<!-- INJECT DEPENDENCIES -->
</dependencies>
<!-- The following are profiles to cover special cases -->
<profiles>
<!-- A profile to install Codename One support libraries to your home directory
if they aren't installed yet. -->
<profile>
<id>install-codenameone</id>
<activation><file><missing>${user.home}/.codenameone/guibuilder.jar</missing></file></activation>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-antrun-plugin</artifactId>
<version>3.0.0</version>
<executions>
<execution>
<phase>validate</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<target name="install-cn1">
<available file="${user.home}/.codenameone/guibuilder.jar" property="codenameone.present"/>
<mkdir dir="${user.home}/.codenameone"/>
<mkdir dir="${project.build.directory}/codenameone/tmpProject"/>
<get src="https://www.codenameone.com/files/updates/UpdateCodenameOne.jar"
dest="${user.home}/UpdateCodenameOne.jar"
skipexisting="true"/>
<java jar="${user.home}/UpdateCodenameOne.jar" fork="true">
<arg value="${project.build.directory}/codenameone/tmpProject"/>
<arg value="force"/>
</java>
</target>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<!-- A profile to add kotlin support. Activated if the src/main/kotlin
directory exists -->
<profile>
<id>kotlin</id>
<activation>
<file>
<!-- To enable Kotlin, add the following file to the project base dir -->
<exists>${basedir}/src/main/kotlin</exists>
</file>
</activation>
<properties>
<kotlin.version>1.3.72</kotlin.version>
<kotlin.compiler.incremental>true</kotlin.compiler.incremental>
</properties>
<dependencies>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.jetbrains.kotlin/kotlin-annotations-jvm -->
<!-- https://mvnrepository.com/artifact/org.jetbrains/annotations -->
<dependency>
<groupId>org.jetbrains</groupId>
<artifactId>annotations</artifactId>
<version>13.0</version>
</dependency>
<dependency>
<groupId>com.codenameone</groupId>
<artifactId>java-runtime</artifactId>
<scope>provided</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/codenameone_settings.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/main/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/main/java</sourceDir>
</sourceDirs>
<args>
<arg>-no-reflect</arg>
<arg>-no-jdk</arg> <!-- No JDK -->
</args>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<sourceDirs>
<sourceDir>${project.basedir}/src/test/kotlin</sourceDir>
<sourceDir>${project.basedir}/src/test/java</sourceDir>
</sourceDirs>
<args>
<arg>-no-reflect</arg>
<arg>-no-jdk</arg> <!-- No JDK -->
</args>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
<profile>
<id>javase</id>
<activation>
<property>
<name>codename1.platform</name>
<value>javase</value>
</property>
</activation>
<properties>
<codename1.targetPlatform>javase</codename1.targetPlatform>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<configuration>
<executable>java</executable>
<longClasspath>true</longClasspath>
<arguments>
<argument>-Xmx1024M</argument>
<!--<argument>-Xdebug</argument>
<argument>-Xrunjdwp:transport=dt_socket,address=8888,server=y,suspend=n</argument>-->
<argument>-classpath</argument>
<classpath />
<argument>${exec.mainClass}</argument>
<argument>${cn1.mainClass}</argument>
</arguments>
</configuration>
</plugin>
</plugins>
</build>
</profile>
<profile>
<!--
For running in simulator in process use:
mvn cn1:java -P simulator
Fro running in simulator in forked process use:
mvn cn1:simulator -P simulator
-->
<id>simulator</id>
<properties>
<codename1.targetPlatform>javase</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending iOS debug builds use:
mvn cn:build -P ios-debug
-->
<id>ios-debug</id>
<properties>
<!-- Build server target type -->
<codename1.targetType>iphone</codename1.targetType>
<!-- Used for identifying native interfaces. Should match correct subdirectory of native -->
<codename1.targetPlatform>ios</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending iOS debug builds use:
mvn cn:build -P ios-release
-->
<id>ios-release</id>
<properties>
<!-- Build server target type -->
<codename1.targetType>iphone</codename1.targetType>
<codename1.production>true</codename1.production>
<!-- Used for identifying native interfaces. Should match correct subdirectory of native -->
<codename1.targetPlatform>ios</codename1.targetPlatform>
<codename1.appStoreBuild>true</codename1.appStoreBuild>
</properties>
</profile>
<profile>
<!--
For sending Javascript builds use:
mvn cn:build -P javascript
-->
<id>javascript</id>
<properties>
<codename1.targetType>javascript</codename1.targetType>
<codename1.targetPlatform>javascript</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending Android builds use:
mvn cn:build -P android
-->
<id>android</id>
<properties>
<codename1.targetType>android</codename1.targetType>
<codename1.targetPlatform>android</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending Windows UWP builds use:
mvn cn:build -P uwp
-->
<id>uwp</id>
<properties>
<codename1.targetType>windows</codename1.targetType>
<codename1.targetPlatform>win</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending Windows desktop builds use:
mvn cn:build -P windows
-->
<id>windows</id>
<properties>
<codename1.targetType>desktop_windows</codename1.targetType>
<codename1.targetPlatform>javase</codename1.targetPlatform>
</properties>
</profile>
<profile>
<!--
For sending Mac Desktop builds use:
mvn cn:build -P mac
-->
<id>mac</id>
<properties>
<codename1.targetType>desktop_macosx</codename1.targetType>
<codename1.targetPlatform>javase</codename1.targetPlatform>
</properties>
</profile>
</profiles>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>properties-maven-plugin</artifactId>
<version>1.0.0</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>read-project-properties</goal>
</goals>
<configuration>
<files>
<file>${basedir}/codenameone_settings.properties</file>
</files>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>com.codenameone</groupId>
<artifactId>codenameone-maven-plugin</artifactId>
<executions>
<execution>
<id>generate-gui-sources</id>
<phase>process-sources</phase>
<goals>
<goal>generate-gui-sources</goal>
</goals>
</execution>
<execution>
<id>cn1-process-classes</id>
<phase>process-classes</phase>
<goals>
<goal>compliance-check</goal>
<goal>css</goal>
<!--<goal>compile-javase-sources</goal>-->
</goals>
</execution>
<execution>
<id>attach-test-artifact</id>
<phase>test</phase>
<goals>
<goal>attach-test-artifact</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>

How to make REST api call from React app bundled into Spring boot using frontend-maven-plugin?

I create a spring boot project and added a react app (created using create react-app) into it. I want to bundle the REST Api and the frontend in single build (fat jar).
Created spring boot web project, at the root added the frontend folder containing the react code. Here is the plugins inside pom.xml
<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/>
<!-- lookup parent from repository -->
</parent>
<groupId>com.example</groupId>
<artifactId>ppa-test</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>ppa-test</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>11</java.version>
<frontend-src-dir>${project.basedir}/src/main/frontend</frontend-src-dir>
<node.version>v15.7.0</node.version>
<npm.version>7.14.0</npm.version>
<frontend-maven-plugin.version>1.7.6</frontend-maven-plugin.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>${frontend-maven-plugin.version}</version>
<configuration>
<nodeVersion>${node.version}</nodeVersion>
<yarnVersion>${npm.version}</yarnVersion>
<workingDirectory>frontend</workingDirectory>
<installDirectory>${project.build.directory}</installDirectory>
</configuration>
<executions>
<execution>
<id>install-frontend-tools</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm-install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<execution>
<id>build-frontend</id>
<goals>
<goal>npm</goal>
</goals>
<phase>compile</phase>
<configuration>
<arguments>run-script build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>process-classes</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static</outputDirectory>
<resources>
<resource>
<directory>frontend/build</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Here is the github repo link
The project is running on 8087 and http://localhost:80807 does render the App.js. But inside that I made an api call to http://localhost:8087/api/audits which is returning 404 error. I though the Rest controller can be used like this.
What am I doing wrong here?
#EnableWebMvc does expose the Rest endpoint but then the App.js content is not served by the build.
You were right, im sorry. I just cloned your repo and tried. It does just work. Response Code 200 with empty array.
Btw: you do not need the cors configuration. It is only needed if the frontend would be served by another webserver. But when deploying it alongside your spring in a fat-jar - its not necessary since it is not doing cors calls since its the same host.
I just clicked in to the repo and saw your front-end code. The path u
are querying within axios is just
axios.get("/audits")
but has to be
axios.get("/api/audits")
since the controller is annotated with a corresponding
RequestMapping.
#RequestMapping("/api")

statefun is giving org.apache.flink.client.program.ProgramInvocationException classloader.parent-first-patterns.additional;

I am running stateful-fun 2.0 basic hello job with the following command
./bin/flink run -c org.apache.flink.statefun.flink.core.StatefulFunctionsJob ./stateful-sun-hello-java-1.0-SNAPSHOT-jar-with-dependencies.jar
and my POM.xml is
<?xml version="1.0" encoding="UTF-8"?>
<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>org.example</groupId>
<artifactId>stateful-sun-hello-java</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>com.google.protobuf</groupId>
<artifactId>protobuf-java</artifactId>
<version>3.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>statefun-sdk</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>statefun-flink-distribution</artifactId>
<version>2.0.0</version>
</dependency>
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>statefun-kafka-io</artifactId>
<version>2.0.0</version>
</dependency>
</dependencies>
<build>
<defaultGoal>clean generate-sources compile install</defaultGoal>
<plugins>
<!-- compile proto file into java files. -->
<plugin>
<groupId>com.github.os72</groupId>
<artifactId>protoc-jar-maven-plugin</artifactId>
<version>3.6.0.1</version>
<executions>
<execution>
<phase>generate-sources</phase>
<goals>
<goal>run</goal>
</goals>
<configuration>
<includeMavenTypes>direct</includeMavenTypes>
<inputDirectories>
<include>src/main/protobuf</include>
</inputDirectories>
<outputTargets>
<outputTarget>
<type>java</type>
<outputDirectory>src/main/java</outputDirectory>
</outputTarget>
<outputTarget>
<type>grpc-java</type>
<pluginArtifact>io.grpc:protoc-gen-grpc-java:1.15.0</pluginArtifact>
<outputDirectory>src/main/java</outputDirectory>
</outputTarget>
</outputTargets>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<!-- get all project dependencies -->
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<!-- MainClass in mainfest make a executable jar -->
<archive>
<manifest>
<mainClass>org.apache.flink.statefun.flink.core.StatefulFunctionsJob</mainClass>
</manifest>
</archive>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<!-- bind to the packaging phase -->
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
It is giving the following exception
The program finished with the following exception:
org.apache.flink.client.program.ProgramInvocationException: The main method caused an error: Invalid configuration: classloader.parent-first-patterns.additional; Must contain all of org.apache.flink.statefun, org.apache.kafka, com.google.protobuf
at org.apache.flink.client.program.PackagedProgram.callMainMethod(PackagedProgram.java:335)
at org.apache.flink.client.program.PackagedProgram.invokeInteractiveModeForExecution(PackagedProgram.java:205)
at org.apache.flink.client.ClientUtils.executeProgram(ClientUtils.java:138)
at org.apache.flink.client.cli.CliFrontend.executeProgram(CliFrontend.java:662)
at org.apache.flink.client.cli.CliFrontend.run(CliFrontend.java:210)
at org.apache.flink.client.cli.CliFrontend.parseParameters(CliFrontend.java:893)
at org.apache.flink.client.cli.CliFrontend.lambda$main$10(CliFrontend.java:966)
at org.apache.flink.runtime.security.NoOpSecurityContext.runSecured(NoOpSecurityContext.java:30)
at org.apache.flink.client.cli.CliFrontend.main(CliFrontend.java:966
Please suggest how to fix this.
You have to add below configuration parameters to your flink-conf.yaml file.
classloader.parent-first-patterns.additional: org.apache.flink.statefun;org.apache.kafka;com.google.protobuf
jobmanager.scheduler: legacy
https://ci.apache.org/projects/flink/flink-statefun-docs-release-2.0/deployment-and-operations/packaging.html#flink-jar --> Official document says:
The following configurations are strictly required for running StateFun application.
classloader.parent-first-patterns.additional: org.apache.flink.statefun;org.apache.kafka;com.google.protobuf
We need to add this jar
<dependency>
<groupId>org.apache.flink</groupId>
<artifactId>statefun-flink-distribution</artifactId>
<version>2.1.0</version>
</dependency>
Package a statefun job to submit to an existing Flink cluster deployment style is no longer mentioned in statefun 3.1 documents. Is this deployment style still possible or supported? If so, where should the module.yaml file be packaged?

Resources