The JFWMP (Java Flutter Web Multi Project) Maven Plugin is a custom plugin designed to simplify the development of client-server solutions within a single project. It automates the process of compiling Flutter projects, copying the compiled projects to resources, and generating server classes for access to the application. It is specifically designed for projects that use Java and Maven. This plugin is particularly useful for developers who are working on multi-project solutions where they need to manage multiple Flutter web applications in a single Java project.
Before you can use the JFWMP Maven Plugin, you need to ensure that you have the following prerequisites installed and set up on your computer:
-
Flutter (which includes the Dart SDK): You can download Flutter from the official Flutter website. Follow the instructions provided on the website to install Flutter on your operating system.
-
Environment Variables: After installing Flutter and Dart, you need to set up your environment variables. Add the path to your Flutter
bin
directory to yourPATH
environment variable. The process for setting environment variables depends on your operating system:-
On Windows, you can follow the instructions provided in this Microsoft documentation.
-
On Linux and macOS, you can add the following line to your
.bashrc
,.bash_profile
, or.zshrc
file (depending on your shell):export PATH="$PATH:`<path_to_flutter_directory>`/flutter/bin"
Replace
<path_to_flutter_directory>
with the actual path to the directory where you installed Flutter.
-
After setting up the prerequisites, you can proceed to use the JFWMP Maven Plugin as described in the rest of this README.
The plugin accepts the following parameters:
apiPath
: The API path for the server. Default is/api/v1/miniapp
.port
: The port number for the server. Default is8080
. See SimpleServer library documentation for more information on theport
parameterthreads
: The number of threads for the server. Default is0
(use available processors - 1). See SimpleServer library documentation for more information on thethreads
parametercreateStartServerMethod
: A boolean value indicating whether to create a start server method. Default istrue
.createUnpackMethod
: A boolean value indicating whether to create an unpack method. Default istrue
.https
: A boolean value indicating whether to use HTTPS. Default isfalse
.
The plugin generates the following files:
Server.java
: This file contains the server class with endpoints for each file in the Flutter project. It is located in theflutters
package.Unpacker.java
: This file contains the unpacker class with unpack methods for each Flutter project. It is also located in theflutters
package.
These files are automatically generated and should not be manually modified, as they are overwritten each time the plugin is run.
To use the plugin, add it to your pom.xml
file:
<build>
<plugins>
<plugin>
<groupId>ru.zoommax</groupId>
<artifactId>jfwmp-maven-plugin</artifactId>
<version>1.0.0</version>
<configuration>
<!-- Add your configuration here -->
</configuration>
</plugin>
</plugins>
</build>
You can customize the plugin's behavior by adding configuration parameters:
<configuration>
<apiPath>/custom/api/path</apiPath>
<port>8081</port>
<threads>4</threads>
<createStartServerMethod>false</createStartServerMethod>
<createUnpackMethod>false</createUnpackMethod>
<https>true</https>
</configuration>
The plugin expects the following directory structure:
- The Flutter projects should be located in a directory named
flutter
in the project's base directory. - The
src/main/resources
directory is used to store the compiled Flutter projects. - The
src/main/java/your_package/flutters
directory is used to store the generatedServer.java
andUnpacker.java
files.
The plugin checks for the presence of the SimpleServer
dependency in the pom.xml
file. If it is not found, an exception is thrown.
The plugin modifies the index.html
file of the Flutter project to insert the base path. Therefore, it is important not to manually modify this file after the plugin has been run.