2.3. T02 Create a Class
In this tutorial we will create a simple class with MetaFactory.
Add the highlighted line to your codeinstruction.xml to use a new pattern.
1<?xml version="1.0" encoding="UTF-8"?>
2<code_instruction
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xmlns="https://metafactory.io/xsd/v1/codeinstruction"
5 xsi:schemaLocation="https://metafactory.io/xsd/v1/codeinstruction https://metafactory.io/xsd/v1/codeinstruction.xsd
6 https://metafactory.io/xsd/v1/java-codeinstruction https://metafactory.io/xsd/v1/java-codeinstruction.xsd"
7 xmlns:typescript="https://metafactory.io/xsd/v1/typescript-codeinstruction"
8 xmlns:java="https://metafactory.io/xsd/v1/java-codeinstruction"
9>
10 <properties>
11 <base>com.metafactory.workshop</base>
12 <java.main.directory>src/main/java</java.main.directory>
13 <java.generated.directory>src/main/generated</java.generated.directory>
14 <conf.main.directory>src/main/resources</conf.main.directory>
15 <java.test.directory>src/test/java</java.test.directory>
16 <conf.test.directory>src/test/resources</conf.test.directory>
17 <!-- Frontend properties -->
18 <jhipster.style>4</jhipster.style>
19 <jhipster6104_angular1000_frontend.output.path>./metafactory-workshop-frontend</jhipster6104_angular1000_frontend.output.path>
20 <app.class.name>MetaFactoryWorkshopApplication</app.class.name>
21 <angular.use.angular8.viewchild>true</angular.use.angular8.viewchild>
22 <angular.app.name>Workshop</angular.app.name>
23 <angular.app.title>MetaFactory Workshop</angular.app.title>
24 <webapp.app.directory>/app</webapp.app.directory>
25 <webapp.main.directory>${project.property.webapp.main.directory}</webapp.main.directory>
26 <angular.library.output.path>./metafactory-workshop-frontend</angular.library.output.path>
27 <angular.webapp.main.directory>src/main/webapp</angular.webapp.main.directory>
28 <angular.webapp.root>src/main/webapp/app</angular.webapp.root>
29 <webapp.components.selector>shc</webapp.components.selector>
30 <app.showNotifications>true</app.showNotifications>
31 <!-- Backend properties -->
32 <jhipster6104_angular1000_backend.output.path>./metafactory-workshop-backend</jhipster6104_angular1000_backend.output.path>
33
34 </properties>
35
36 <!-- Load Freemarker template files -->
37 <freemarker>
38 <freemarker_library namespace="naming">/library/naming.ftl</freemarker_library>
39 <freemarker_library namespace="util">/jhipster/util/util.ftl</freemarker_library>
40 <freemarker_library namespace="state_util">/jhipster/util/state-utils.ftl</freemarker_library>
41 <freemarker_library namespace="model_util">/library/model_utils.ftl</freemarker_library>
42 <freemarker_library namespace="tl">/library/layout/tableLayout.ftl</freemarker_library>
43 <freemarker_library namespace="metadata">/library/metadata.ftl</freemarker_library>
44 </freemarker>
45
46 <external_libraries>
47 <external_library name="libMF">
48 <path>./</path>
49 <patterns_folder>src/patterns</patterns_folder>
50 <snippets_folder>src/snippets</snippets_folder>
51 <function_library>src/patterns/package/pattern-functions.xml</function_library>
52 </external_library>
53 </external_libraries>
54
55 <features>
56
57 </features>
58
59 <!--#############################################################################################################-->
60 <!--############################################### Java patterns ###############################################-->
61 <!--#############################################################################################################-->
62
63 <!-- The new MetaFactory Runtime Model => A pojo representation of your model.xml which can be used from your snippets-->
64 <java:external_java_package id="libMF/package/model/runtime/model-root.xml" />
65 <java:external_java_package id="libMF/package/model/runtime/model-pojo.xml" />
66
67 <!-- your codeinstructions here -->
68 <java:external_java_package id="libMF/package/feature1/java_package1.xml" />
69
70</code_instruction>
Create a new file called pattern1.xml in a new directory metafactory-workshop-metafactory\src\patterns\package\feature1 and place the following content in it:
1<java_package
2 xmlns="https://metafactory.io/xsd/v1/java-codeinstruction"
3 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4 xsi:schemaLocation="https://metafactory.io/xsd/v1/java-codeinstruction
5 https://metafactory.io/xsd/v1/java-codeinstruction.xsd"
6 name="com.company.workshop"
7 path="src/main/java">
8 <class name="MyClass">
9 </class>
10</java_package>
Now:
Click on metafactory-workshop-metafactory in the MetaFactory Project window.
Click on the Play button to run the Code Composer.
Once finished the Code Composer will have generated the Java class MyClass.
Open metafactory-workshop-backend\src\main\java\com\company\workshop\MyClass.java to see the result.