Explorer

    A way to run the Explorer 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">
    <dependencies>
        <dependency>
            <groupId>org.xworker</groupId>
            <artifactId>xworker_explorer</artifactId>
            <version>2.0.0-SNAPSHOT</version>
           <scope>test</scope>
</dependency>
    </dependencies>
    <repositories>
        <repository>
            <id>sonatype</id>
            <name>sonatype Repository</name>
            <url>https://oss.sonatype.org/content/groups/public/</url>
            <releases>
                <enabled>false</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
            <layout>default</layout>
        </repository>
    </repositories>
</project>

2. Run the model editor

    Write a Java program to run the Model Editor.

import org.xmeta.World;
import xworker.swt.SwtThingEditor;
import xworker.webserver.XWorkerWebServer;

import java.io.File;

public class ThingEditor {
    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
            world.init("./xworker/");

            //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
            XWorkerWebServer.run();
            SwtThingEditor.run();
        }catch(Exception e){
            e.printStackTrace();
        }
    }
}

    The first time it is executed or when the Jar that the project depends on is changed, 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.

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