Java project

1. Use dynamic models in Java projects

    The dynamic model engine used by XWorker is implemented in Java and is a Lightweight engine, which can be used in Java projectsDynamic Model Programming.

2.The role of XWorker

  • Model Editor
    XWorker is a dynamic model development tool that can be used to edit and run models.
      
  • Auxiliary tools
    XWorker contains various auxiliary tools, and you can also develop your own tools.
      
  • Model Library
    XWorker provides some model libraries that can be introduced into Java projects as needed.

    For more information, please refer to Development and Example.

3. Import XWorker

    Importing XWorker into a Java project mainly involves importing XWorker-related class libraries. If it is only used to edit and run models, the scope of the class library can be set to test.

3.1. Official version

<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_swt_thingeditor</artifactId>
            <version>2.0.3</version>
           <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.xworker</groupId>
             <artifactId>xworker_webserver</artifactId>
             <version>2.0.3</version>
            <scope>test</scope>
         </dependency>
     </dependencies>
</project>

     If you only use XWorker as the model editor, the scope of the related package can be set to test.

2.2.SNAPSHOT version

     The SNAPSHOT version can access the latest XWorker model library, and the sonatype warehouse is for using 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_swt_thingeditor</artifactId>
             <version>2.0.4-SNAPSHOT</version>
            <scope>test</scope>
         </dependency>
         <dependency>
             <groupId>org.xworker</groupId>
             <artifactId>xworker_webserver</artifactId>
             <version>2.0.4-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>

    If you only use XWorker as the model editor, the scope of the relevant package can be set to test.

3.3. Select model library

    The dependencies in the above pom are necessary to run the model editor. You can choose other XWorker model libraries according to your needs. You can refer to Model library tool.

4. Run the model editor

    Write a Java program to run the model editor. If it is a Maven project, it can be placed under src/test/java.

import org.xmeta.World;
import xworker.lang.util.XWorkerUtils;
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 the model manager, which is the directory where the model is stored, required for editing the model. Test is the name of the model manager and cannot be repeated with other model managers.
             world.addFileThingManager("myproject", new File("./src/main/resources"), false, true);
             //The model can be placed in the Java source code directory. The model can be compiled and packaged together with Java, but the model in the jar is generally read-only.

             //Check whether initialization is required, such as re-indexing if the dependent model library is updated
             XWorkerUtils.setup(false);

             //Run the web server and model editor
             XWorkerWebServer.run();
             SwtThingEditor.run();
         }catch(Exception e){
             e.printStackTrace();
         }
  System.exit(0);
     }
}

   Note that the startup time will be longer after the first startup or after the class library is changed. In this case, resources will be decompressed and indexed during startup. After successful operation, the model manager will open, as shown below.

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