How to run the WEB version of the model editor under a Java project.

1. Import class library

    Please refer to the pom.xml below to introduce the relevant class library into your own Java project, where the sonatype repository is for the use of the SNAPSHOT version of the class library.

<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">
            <name>sonatype Repository</name>

2. Run the model editor

    Write a Java program to run the Model Editor.

import org.xmeta.World;
import xworker.web.thingeditor.XWorkerWebThingEditor;

import java.io.File;

public class StartWebThingEditor {

    public static void main(String args[]) {
        try {
            //Get an instance of the dynamic model engine
            World world = World.getInstance();
            //Initialize the working directory of the engine, some temporary files may be generated, the directory must be writable

            //Add a model manager, that is, the directory where the model is stored, which is needed to edit the model. Test is the name of the model manager and cannot be duplicated with other model managers.
            world.addFileThingManager("myproject", new File("./src/main/resources"), false, true);
            //The model can be placed in the Java source directory, and the model can be compiled and packaged with Java, but the model in the jar is generally read-only

            // run the web server and model editor
        } catch (Exception e) {

    The first time it is executed or when the Jar that the project depends on changes, the initialization operation will be performed. After the initialization is performed, the application will exit and need to be reopened. The function of initialization is to decompress the class libraries and resources that cannot be imported through Maven to the ./xworker/ directory. After execution, please import the relevant jars in the Java project according to the prompts, and pay attention to import <xworker>/lib_rap/ Under the class library, Be careful not to import swt.jar.

3. Open the model editor

    When the WEB version of the model editor runs, it will print a URL address, enter the address in the browser to open the model editor, the default username and password are admin/admin.

    An example URL address is as follows: http://localhost:9001/rap?app=xworker.webserver.Login


    Since the server-side model can be modified, there is a security risk, and login authentication needs to be set.

    The priority of the following authentication methods is LoginListener > WebLogin Action > Default.


    The default username is admin and the password is randomly created. Username and password are set under the _local.xworker.config.XWorkerConfig model.

4.2.WebLogin action model

    If the _local.xworker.config.WebLogin model exists, then perform validation on this model as an action.

    The parameters of the action are loginName and password, the type is String, and the return value is boolean. If the verification passes, it returns true, otherwise it returns false.

4.3. Validation in Java code

    The interface xworker.web.thingeditor.LoginListener can be implemented and set.

import xworker.web.thingeditor.Login;
import xworker.web.thingeditor.LoginListener

LoginListener listener = new LoginListener(){
     public boolean login(String name, String password){
        // perform verification

Login.loginListener = listener;

Copyright ©  2007-2019 XWorker.org  版权所有  沪ICP备08000575号