| Home » Modeling » M2T (model-to-text transformation) » running jet application
 Goto Forum:| 
| running jet application [message #20695] | Wed, 06 June 2007 02:49  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: alexjaquet.gmail.com 
 Hi,
 
 I would like to know to run jet from a gmf application.
 
 Thanks,
 
 Regards,
 Alexandre
 |  |  |  |  | 
| Re: running jet application [message #20771 is a reply to message #20695] | Wed, 06 June 2007 08:48   |  | 
| Eclipse User  |  |  |  |  | JET has an API: 
 JET2Platform.runTransformOnObject(transformID, documentRoot,
 progressMonitor)
 
 Get the EMF Resource object for your GMF model, and use that as the
 documentRoot value.
 
 If you JET transform uses the predefined variable
 org.eclipse.jet.resource.project.name, it will not be defined when using
 this API. You can define it yourself, however:
 
 Map variables = new HashMap();
 variables.put("org.eclipse.jet.resource.project.name",
 theNameOfTheProjectContainingTheEMFResource);
 JET2Platform.runTransformOnObject(transformID, documentRoot, variables,
 progressMonitor)
 
 Paul
 
 "Alexandre Jaquet" <alexjaquet@gmail.com> wrote in message
 news:f45ldt$r60$1@build.eclipse.org...
 > Hi,
 >
 > I would like to know to run jet from a gmf application.
 >
 > Thanks,
 >
 > Regards,
 > Alexandre
 >
 |  |  |  |  |  |  | 
| Re: running jet application [message #25247 is a reply to message #20771] | Sun, 08 July 2007 12:15   |  | 
| Eclipse User  |  |  |  |  | Originally posted by: woodri.us.ibm.com 
 Paul,
 
 Thanks, that worked. I was able to load and run a template.
 
 But there is a classloader problem. Another project that does work on a
 model (call it com.xyz.myproject) uses templates to do part of the work.
 A JET2 project manages the templates (call this project jet2test) - so
 com.xyz.myproject runs a jet2test template.
 
 When com.xyz.myproject passes one of its objects into the template's
 generate() method via JET2Context's setVariable(), the template's
 classloader can't find the object.  The classloader is a
 DefaultClassLoader, whose delegate is a BundleLoader.  I looked at the
 JET2 APIs, and didn't see access to classloader in JET2TemplateManager,
 JET2TemplateLoader, or JET2Context.
 
 Here's the setup:
 - the context object is part of com.xyz.myproject, which exports package
 com.xyz.myproject.stuff.
 - the template is in project jet2test, which sees com.xyz.myproject as a
 required project on the build path.
 
 I'm debugging com.xyz.myproject, which loads a template from jet2test:
 
 <%@ jet package="library.Writer.name" class="template1"
 imports="com.xyz.myproject.stuff.MyClass" %>
 <% MyClass instance = (MyClass) context.getVariable("MyClass"); %>
 <%= instance.getSomeValue() %>
 
 this compiles to:
 
 ...
 import com.xyz.myproject.stuff.MyClass;
 ...
 public void generate(final JET2Context context, final JET2Writer
 __out) {
 JET2Writer out = __out;
 MyClass instance = (MyClass) context.getVariable("MyClass");
 out.write( instance.getSomeValue() );
 out.write(NL);
 }
 
 When context.getVariable("MyClass") runs, the classloader throws this
 exception:
 
 java.lang.NoClassDefFoundError: com.xyz.myproject.stuff.MyClass
 at library.Writer.name.template1.generate(template1.java)
 at
 org.eclipse.jet.JET2TemplateManager$TemplateRunnerImpl.gener ate(JET2TemplateManager.java)
 at  com.xyz.myproject.template.Jet2Template$1.run(Jet2Template.j ava:52)
 at  org.eclipse.jet.JET2TemplateManager.run(JET2TemplateManager. java:147)
 at  com.xyz.myproject.template.Jet2Template.generate(Jet2Templat e.java:47)
 at ...
 
 
 Paul Elder wrote:
 > JET has an API:
 >
 > JET2Platform.runTransformOnObject(transformID, documentRoot,
 > progressMonitor)
 >
 > Get the EMF Resource object for your GMF model, and use that as the
 > documentRoot value.
 >
 > If you JET transform uses the predefined variable
 > org.eclipse.jet.resource.project.name, it will not be defined when using
 > this API. You can define it yourself, however:
 >
 > Map variables = new HashMap();
 > variables.put("org.eclipse.jet.resource.project.name",
 > theNameOfTheProjectContainingTheEMFResource);
 > JET2Platform.runTransformOnObject(transformID, documentRoot, variables,
 > progressMonitor)
 >
 > Paul
 >
 > "Alexandre Jaquet" <alexjaquet@gmail.com> wrote in message
 > news:f45ldt$r60$1@build.eclipse.org...
 >> Hi,
 >>
 >> I would like to know to run jet from a gmf application.
 >>
 >> Thanks,
 >>
 >> Regards,
 >> Alexandre
 >>
 >
 >
 |  |  |  |  | 
| Re: running jet application [message #25289 is a reply to message #25247] | Sun, 08 July 2007 12:16  |  | 
| Eclipse User  |  |  |  |  | Originally posted by: woodri.us.ibm.com 
 Whoa - sorry, replied to the wrong message. Should have been "invoke
 template from java with string return?"
 
 - Rick
 
 Rick Wood wrote:
 > Paul,
 >
 > Thanks, that worked. I was able to load and run a template.
 >
 > But there is a classloader problem. Another project that does work on a
 > model (call it com.xyz.myproject) uses templates to do part of the work.
 > A JET2 project manages the templates (call this project jet2test) - so
 > com.xyz.myproject runs a jet2test template.
 >
 > When com.xyz.myproject passes one of its objects into the template's
 > generate() method via JET2Context's setVariable(), the template's
 > classloader can't find the object.  The classloader is a
 > DefaultClassLoader, whose delegate is a BundleLoader.  I looked at the
 > JET2 APIs, and didn't see access to classloader in JET2TemplateManager,
 > JET2TemplateLoader, or JET2Context.
 >
 > Here's the setup:
 > - the context object is part of com.xyz.myproject, which exports package
 > com.xyz.myproject.stuff.
 > - the template is in project jet2test, which sees com.xyz.myproject as a
 > required project on the build path.
 >
 > I'm debugging com.xyz.myproject, which loads a template from jet2test:
 >
 > <%@ jet package="library.Writer.name" class="template1"
 > imports="com.xyz.myproject.stuff.MyClass" %>
 > <% MyClass instance = (MyClass) context.getVariable("MyClass"); %>
 > <%= instance.getSomeValue() %>
 >
 > this compiles to:
 >
 >     ...
 >     import com.xyz.myproject.stuff.MyClass;
 >     ...
 >     public void generate(final JET2Context context, final JET2Writer
 > __out) {
 >         JET2Writer out = __out;
 >  MyClass instance = (MyClass) context.getVariable("MyClass");
 >         out.write( instance.getSomeValue() );
 >         out.write(NL);
 >     }
 >
 > When context.getVariable("MyClass") runs, the classloader throws this
 > exception:
 >
 > java.lang.NoClassDefFoundError: com.xyz.myproject.stuff.MyClass
 >     at library.Writer.name.template1.generate(template1.java)
 >     at
 >  org.eclipse.jet.JET2TemplateManager$TemplateRunnerImpl.gener ate(JET2TemplateManager.java)
 >
 >     at  com.xyz.myproject.template.Jet2Template$1.run(Jet2Template.j ava:52)
 >     at
 >  org.eclipse.jet.JET2TemplateManager.run(JET2TemplateManager. java:147)
 >     at
 >  com.xyz.myproject.template.Jet2Template.generate(Jet2Templat e.java:47)
 >     at ...
 >
 >
 > Paul Elder wrote:
 >> JET has an API:
 >>
 >> JET2Platform.runTransformOnObject(transformID, documentRoot,
 >> progressMonitor)
 >>
 >> Get the EMF Resource object for your GMF model, and use that as the
 >> documentRoot value.
 >>
 >> If you JET transform uses the predefined variable
 >> org.eclipse.jet.resource.project.name, it will not be defined when
 >> using this API. You can define it yourself, however:
 >>
 >> Map variables = new HashMap();
 >> variables.put("org.eclipse.jet.resource.project.name",
 >> theNameOfTheProjectContainingTheEMFResource);
 >> JET2Platform.runTransformOnObject(transformID, documentRoot,
 >> variables, progressMonitor)
 >>
 >> Paul
 >>
 >> "Alexandre Jaquet" <alexjaquet@gmail.com> wrote in message
 >> news:f45ldt$r60$1@build.eclipse.org...
 >>> Hi,
 >>>
 >>> I would like to know to run jet from a gmf application.
 >>>
 >>> Thanks,
 >>>
 >>> Regards,
 >>> Alexandre
 >>>
 >>
 >>
 |  |  |  | 
 
 
 Current Time: Fri Oct 31 01:12:46 EDT 2025 
 Powered by FUDForum . Page generated in 0.04270 seconds |