0

I have a Acceleo project (a bunch of *.mtl files, and a Java class which can generate output using these templates). The project works fine as long as I run it from inside Eclipse, but when I compile the *.emtl files using Maven I get a NullPointerException inside AcceleoService#doGenerate():

Thread [ModalContext] (Suspended (exception NullPointerException))  
    AcceleoService.doGenerate(Module, String, EObject, List<Object>, File, Monitor) line: 565   
    Plugin(AbstractAcceleoGenerator).generate(Monitor) line: 194    
    Plugin(AbstractAcceleoGenerator).doGenerate(Monitor) line: 159  
    Plugin.doGenerate(Monitor) line: 211    
    Plugin.main(String[]) line: 168 
    NewRPCServiceDefinitionWizard.generatePluginXml(IProgressMonitor) line: 450 
    NewRPCServiceDefinitionWizard.generateCode(IProgressMonitor) line: 269  
    NewRPCServiceDefinitionWizard.access$2(NewRPCServiceDefinitionWizard, IProgressMonitor) line: 231   
    NewRPCServiceDefinitionWizard$3$1.runInWorkspace(IProgressMonitor) line: 315    
    NewRPCServiceDefinitionWizard$3.run(IProgressMonitor) line: 321 
    ModalContext$ModalContextThread.run() line: 121 

The code in question looks like this:

    for (Template template : mainTemplates) {
        // Calls the template with each potential arguments
        final EClassifier argumentType = template.getParameter().get(0).getType();
        // !!! argumentType is null here !!!
        if (argumentType.eIsProxy()) {
            throw new AcceleoEvaluationException(AcceleoEngineMessages.getString(
                    "AcceleoService.TypeIsProxy", templateName)); //$NON-NLS-1$
        }

So getType() returns null. Since this works inside Eclipse, but not when building with Maven, I diffed the generated *.emtl files and found that the *.emtl file which works has at the top

<input>
    <takesTypesFrom href="http://mycompany.com/xyz#/"/>
</input>

while the one which does not work has

<input/>

Since the NPE was triggered by getType() returning null, this looked like a possible cause, but this is as far as I've managed to come.

Any ideas as to what may be wrong here?

JesperE
  • 63,317
  • 21
  • 138
  • 197

1 Answers1

0

When you run Acceleo standalone you must give it all libraries/jars and classes that the plugin runs for you. In addition, if you want to export it to a jar, you must supply Eclipse's libraries too.

I recommend you to compile and generate the jar with maven/ant (I've used maven), because you will have to package several libraries and it makes it easier.

The list of jars (you can take almost all of them from your plugins folder in your Eclipse):

enter image description here

Maybe you might have to include some of them as dependencies in your pom, in order that maven would be able to include them in your final jar.

Finally, you have to configure your plugin for acceleo like this:

            <configuration>
                <useBinaryResources>false</useBinaryResources>
                <usePlatformResourcePath>true</usePlatformResourcePath>
                <acceleoProject>
                    <root>${project.basedir}</root>
                    <entries>
                        <entry>
                            <input>your/source/package (ordinary: src/main)</input>
                            <output>your/target/package</output>
                        </entry>
                    </entries>
                </acceleoProject>
            </configuration>

As you can see, I have imported things related to MoDisco, but they will be surely useless for you.

I hope I could help you!

Juan Aguilar Guisado
  • 1,687
  • 1
  • 12
  • 21