When you create a custom GenTemplate, you may wish to share it with others — team members, customers, etc. This is easy to do with RepreZen API Studio. Currently, you can share GenTemplates by packaging them as jar files, or you can share your GenTemplate projects in external repositories like GitHub.
In the future we intend to make it possible to use GenTemplates published to Maven repositories.
One way to share a GenTemplate is to package it as a Java jar file and then share that jar file.
To create a jar file, right click on the GenTemplate project folder in the Project Explorer pane, and select Run As → Maven build…:
In the dialog that appears, type
package in the Goals field, and press Run.
|If you are familiar with using Eclipse for Java development, you may wish to switch to the Java perspective while working on GenTemplate projects. One benefit is that the standard Run tool will be present in the toolbar, making it easy to re-run this packaging step at any time.|
RepreZen API Studio will create a jar file in your project’s
If you are unable to open your
You can now copy the new jar file and paste a copy anywhere you’d like, either within the RepreZen API Studio Project Explorer or in your system’s file explorer. You can also use drag-and-drop to copy the jar file, and there are many applications that can serve as drop targets, including email applications, cloud storage solutions like Google Drive and Dropbox, and so on.
If you create or obtain a GenTemplate packaged as a Jar file and you want to use it to create GenTargets in your model projects, you have two simple options:
Copy the jar file into your model project’s
Copy the jar file into a
GenTemplates folder in a project named
shared in your RepreZen API Studio workspace.
The first option makes the GenTemplates in the jar file available for use with all the models in that model project, but not models in other projects. The second option makes those GenTemplates available in all your model projects.
Either way, you’ll need to create the indicated project and/or folder if they don’t already exist.
If you need to create a
With your jar file in either location, RepreZen API Studio will find any GenTemplates it contains, and you will find those GenTemplates available for use.
You can change the location of the shared folder in the RepreZen preferences. Select Window →
Preferences in the menu bar, and then navigate to RepreZen → Code Generation and enter your
desired path. If you start your path with
Many developers now use GitHub to maintain source code for their projects and, in some cases, to make that code available to others. If you publish a RepreZen API Studio GenTemplate project on GitHub, others have the option of importing your project into their own workspace, thereby making your GenTemplates available for use on all models in that workspace.
If you are the publisher of a GenTemplate project in this scenario, you are presumably familiar with the steps necessary to set up and publish to GitHub, so we will focus on the steps required to import such a project.
You can follow along with the steps below to import the GenTemplate that is developed in Introduction to Code Generation in RepreZen API Studio.
Before getting started, you’ll save yourself some difficulty if you use the Project menu to turn off automated builds temporarily. We’ll turn it back on later, and also explain why we did it.
Everything starts with File → Import… in the RepreZen API Studio menu bar. Select Git → Projects from Git in the dialog that appears, then click Next.
In the next panel, select Clone URI and click Next.
Next, in the URI field, enter the URI for the GitHub repository that
contains the project you want to use. In our case we’ll use the
repository that contains all the source material for this
documentation portal, including the an example GenTemplate
project. The clone URI for that project is
email@example.com:RepreZen/docs.git. After you enter the URI, click Next.
Note that in the above dialog, when you fill in the URI field, the other fields are filled in automatically.
The next panel allows you to select which branches of the repository you want to download. You will usually need only the "master" branch, but it is harmless to download other branches. Make your selection and click Next.
The next panel is where you can decide where you want to copy the repository on your local system. There will generally be an acceptable default location, and you probably don’t need to change anything else. Click Next.
Use the default option in the next panel, and click Next.
In the next panel, RepreZen API Studio shows you a list of the importable projects it was able to find in the
downloaded repository. If you’re following along with this example, you’ll see only one project -
LexiconGentemplates. Make your selections and press Finish (finally)!
Now we’ll explain why we suppressed automatic builds at the outset. If we had not done that, RepreZen API Studio would immediately start trying to build the porject. Unfortunately, it would end up failing with some bizarre looking errors. The reason is that this project is structured as a particular type of Maven project. Maven is a widely used system to manage complex Java projects, and it has its own ideas about project layout and how projects should be built.
So before we let RepreZen API Studio try to build this project, we’ll clue it in about the fact that Maven should be managing the build, by right-clicking on the project name and using the Maven > Update… option in the context menu:
Click OK in the dialog that appears, and then turn automatic updates back on in the Project menu where you disabled it earlier. After a few moments, while RepreZen API Studio automatically builds the project, the imported GenTemplates will be available for your use.