Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF "Technology" (Ecore Tools, EMFatic, etc)  » NPE When Serializing with Texo
NPE When Serializing with Texo [message #990926] Fri, 14 December 2012 17:45 Go to next message
Ole Ersoy is currently offline Ole Ersoy
Messages: 201
Registered: July 2009
Senior Member
Hi,

I'm trying to serialize a model as described here:
http://wiki.eclipse.org/Texo/XML_and_XMI_Serialization

I did make sure to "Touch" or initialize the model package. I'll first list the exception, then my test code, then my maven dependencies, then the model.

EXCEPTION:
java.lang.ExceptionInInitializerError
at com.example.texo.SerializationTest.serialize(SerializationTest.java:17)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:616)
at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: java.lang.NullPointerException
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.getEncoding(XMLLoadImpl.java:314)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:122)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:240)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1505)
at org.eclipse.emf.texo.utils.ModelUtils.readEPackagesFromFile(ModelUtils.java:343)
at com.example.texo.TexoModelPackage.initialize(TexoModelPackage.java:88)
at com.example.texo.TexoModelPackage.<clinit>(TexoModelPackage.java:66)
... 24 more

TEST CODE:package com.example.texo;

import static org.junit.Assert.*;

import java.io.StringWriter;
import java.util.ArrayList;
import java.util.List;

import org.eclipse.emf.texo.xml.ModelXMLSaver;
import org.junit.Test;

public class SerializationTest {

@Test
public void serialize()
{
TexoModelPackage.initialize();
List<Object> modelObjects = new ArrayList<Object>();
modelObjects.add(new Configuration());

final ModelXMLSaver xmlSaver = new ModelXMLSaver();
xmlSaver.setSaveAsXMI(true);
xmlSaver.setObjects(modelObjects);
final StringWriter sw = new StringWriter();
xmlSaver.setWriter(sw);
xmlSaver.write();
String content = sw.toString();
assertNotNull(content);
}

}

MAVEN DEPENDENCIES:
<dependencies>
<!-- Logging -->
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.0.7</version>
</dependency>

<!-- Modeling -->
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.common</artifactId>
<version>2.8.0-v20120911-0500</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore.xmi</artifactId>
<version>2.8.0-v20120911-0500</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore</artifactId>
<version>2.8.0-v20120911-0500</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.texo.xml</artifactId>
<version>0.1.0-v201210251502</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.texo</artifactId>
<version>0.1.0-v201210251502</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.texo.server</artifactId>
<version>0.1.0-v201210251502</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.texo.json</artifactId>
<version>0.1.0-v201210251502</version>
</dependency>
<!-- Testing -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-all</artifactId>
<version>1.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.9</version>
<scope>test</scope>
<exclusions>
<exclusion>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest-core</artifactId>
</exclusion>
</exclusions>
</dependency>
</dependencies>

MODEL
<?xml version="1.0" encoding="UTF-8"?>
<ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="texo" nsURI="http://texo.example.com" nsPrefix="texo">
<eClassifiers xsi:type="ecore:EClass" name="Configuration">
<eStructuralFeatures xsi:type="ecore:EAttribute" name="fileName" eType="ecore:EDataType http://www.eclipse.org/emf/2002/Ecore#//EString"
defaultValueLiteral="nameofthefile" unsettable="true"/>
</eClassifiers>
</ecore:EPackage>


Thoughts?

TIA,
- Ole
Re: NPE When Serializing with Texo [message #990929 is a reply to message #990926] Fri, 14 December 2012 18:11 Go to previous messageGo to next message
Martin Taal is currently offline Martin Taal
Messages: 5326
Registered: July 2009
Senior Member
Hi Ole,
Another user has also reported this issue. I changed the error message so it is more descriptive (for now).

In the generated code there should also be an ecore file in that same java package. Can you check if this ecore file is
there and is also present in the output directory (bin/build)? And that it is present in any other location where you
use your runtime code (for example when packaging it in a jar)?

gr. Marton

On 12/14/2012 11:45 PM, Ole Ersoy wrote:
> Hi,
>
> I'm trying to serialize a model as described here:
> http://wiki.eclipse.org/Texo/XML_and_XMI_Serialization
>
> I did make sure to "Touch" or initialize the model package. I'll first list the exception, then my test code, then my
> maven dependencies, then the model.
>
> EXCEPTION:
> java.lang.ExceptionInInitializerError
> at com.example.texo.SerializationTest.serialize(SerializationTest.java:17)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:616)
> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
> Caused by: java.lang.NullPointerException
> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.getEncoding(XMLLoadImpl.java:314)
> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:122)
> at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:240)
> at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1505)
> at org.eclipse.emf.texo.utils.ModelUtils.readEPackagesFromFile(ModelUtils.java:343)
> at com.example.texo.TexoModelPackage.initialize(TexoModelPackage.java:88)
> at com.example.texo.TexoModelPackage.<clinit>(TexoModelPackage.java:66)
> ... 24 more
>
> TEST CODE:package com.example.texo;
>
> import static org.junit.Assert.*;
>
> import java.io.StringWriter;
> import java.util.ArrayList;
> import java.util.List;
>
> import org.eclipse.emf.texo.xml.ModelXMLSaver;
> import org.junit.Test;
>
> public class SerializationTest {
>
> @Test
> public void serialize()
> {
> TexoModelPackage.initialize();
> List<Object> modelObjects = new ArrayList<Object>();
> modelObjects.add(new Configuration());
>
> final ModelXMLSaver xmlSaver = new ModelXMLSaver();
> xmlSaver.setSaveAsXMI(true);
> xmlSaver.setObjects(modelObjects);
> final StringWriter sw = new StringWriter();
> xmlSaver.setWriter(sw);
> xmlSaver.write();
> String content = sw.toString();
> assertNotNull(content);
> }
>
> }
>
> MAVEN DEPENDENCIES:
> <dependencies>
> <!-- Logging -->
> <dependency>
> <groupId>ch.qos.logback</groupId>
> <artifactId>logback-classic</artifactId>
> <version>1.0.7</version>
> </dependency>
>
> <!-- Modeling -->
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.common</artifactId>
> <version>2.8.0-v20120911-0500</version>
> </dependency>
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.ecore.xmi</artifactId>
> <version>2.8.0-v20120911-0500</version>
> </dependency>
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.ecore</artifactId>
> <version>2.8.0-v20120911-0500</version>
> </dependency>
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.texo.xml</artifactId>
> <version>0.1.0-v201210251502</version>
> </dependency>
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.texo</artifactId>
> <version>0.1.0-v201210251502</version>
> </dependency>
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.texo.server</artifactId>
> <version>0.1.0-v201210251502</version>
> </dependency>
> <dependency>
> <groupId>org.eclipse.emf</groupId>
> <artifactId>org.eclipse.emf.texo.json</artifactId>
> <version>0.1.0-v201210251502</version>
> </dependency>
> <!-- Testing -->
> <dependency>
> <groupId>org.hamcrest</groupId>
> <artifactId>hamcrest-all</artifactId>
> <version>1.3</version>
> <scope>test</scope>
> </dependency>
> <dependency>
> <groupId>junit</groupId>
> <artifactId>junit</artifactId>
> <version>4.9</version>
> <scope>test</scope>
> <exclusions>
> <exclusion>
> <groupId>org.hamcrest</groupId>
> <artifactId>hamcrest-core</artifactId>
> </exclusion>
> </exclusions>
> </dependency>
> </dependencies>
>
> MODEL
> <?xml version="1.0" encoding="UTF-8"?>
> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="texo" nsURI="http://texo.example.com" nsPrefix="texo">
> <eClassifiers xsi:type="ecore:EClass" name="Configuration">
> <eStructuralFeatures xsi:type="ecore:EAttribute" name="fileName" eType="ecore:EDataType
> http://www.eclipse.org/emf/2002/Ecore#//EString"
> defaultValueLiteral="nameofthefile" unsettable="true"/>
> </eClassifiers>
> </ecore:EPackage>
>
>
> Thoughts?
>
> TIA,
> - Ole
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Re: NPE When Serializing with Texo [message #990936 is a reply to message #990929] Fri, 14 December 2012 23:14 Go to previous messageGo to next message
Ole Ersoy is currently offline Ole Ersoy
Messages: 201
Registered: July 2009
Senior Member
Hi Martin,

Got it - Thanks! For others reading the thread and using Maven - the file was generating into the "src/main/java", but neither "mvn eclipse:eclipse", nor "mvn test" was "seeing" it, since Maven's default behavior is to archive only .java files from src/main/java. It expects other resources to be in "src/main/resources". I fixed it by adding this:

<resources>
<resource>
<directory>src/main/java</directory>
<includes>
<include>com/example/texo/texo.ecore</include>
</includes>
</resource>
</resources>

For details see:
http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html
http://stackoverflow.com/questions/4509309/in-maven-how-can-i-include-non-java-src-files-in-the-same-place-in-the-output-ja

Thanks again for making Texo. It's brilliant,
- Ole









On 12/14/2012 05:11 PM, Martin Taal wrote:
> Hi Ole,
> Another user has also reported this issue. I changed the error message so it is more descriptive (for now).
>
> In the generated code there should also be an ecore file in that same java package. Can you check if this ecore file is there and is also present in the output directory (bin/build)? And that it is present in any other location where you use your runtime code (for example when packaging it in a jar)?
>
> gr. Marton
>
> On 12/14/2012 11:45 PM, Ole Ersoy wrote:
>> Hi,
>>
>> I'm trying to serialize a model as described here:
>> http://wiki.eclipse.org/Texo/XML_and_XMI_Serialization
>>
>> I did make sure to "Touch" or initialize the model package. I'll first list the exception, then my test code, then my
>> maven dependencies, then the model.
>>
>> EXCEPTION:
>> java.lang.ExceptionInInitializerError
>> at com.example.texo.SerializationTest.serialize(SerializationTest.java:17)
>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>> at java.lang.reflect.Method.invoke(Method.java:616)
>> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
>> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
>> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
>> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
>> at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
>> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>> Caused by: java.lang.NullPointerException
>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.getEncoding(XMLLoadImpl.java:314)
>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:122)
>> at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:240)
>> at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1505)
>> at org.eclipse.emf.texo.utils.ModelUtils.readEPackagesFromFile(ModelUtils.java:343)
>> at com.example.texo.TexoModelPackage.initialize(TexoModelPackage.java:88)
>> at com.example.texo.TexoModelPackage.<clinit>(TexoModelPackage.java:66)
>> ... 24 more
>>
>> TEST CODE:package com.example.texo;
>>
>> import static org.junit.Assert.*;
>>
>> import java.io.StringWriter;
>> import java.util.ArrayList;
>> import java.util.List;
>>
>> import org.eclipse.emf.texo.xml.ModelXMLSaver;
>> import org.junit.Test;
>>
>> public class SerializationTest {
>>
>> @Test
>> public void serialize()
>> {
>> TexoModelPackage.initialize();
>> List<Object> modelObjects = new ArrayList<Object>();
>> modelObjects.add(new Configuration());
>>
>> final ModelXMLSaver xmlSaver = new ModelXMLSaver();
>> xmlSaver.setSaveAsXMI(true);
>> xmlSaver.setObjects(modelObjects);
>> final StringWriter sw = new StringWriter();
>> xmlSaver.setWriter(sw);
>> xmlSaver.write();
>> String content = sw.toString();
>> assertNotNull(content);
>> }
>>
>> }
>>
>> MAVEN DEPENDENCIES:
>> <dependencies>
>> <!-- Logging -->
>> <dependency>
>> <groupId>ch.qos.logback</groupId>
>> <artifactId>logback-classic</artifactId>
>> <version>1.0.7</version>
>> </dependency>
>>
>> <!-- Modeling -->
>> <dependency>
>> <groupId>org.eclipse.emf</groupId>
>> <artifactId>org.eclipse.emf.common</artifactId>
>> <version>2.8.0-v20120911-0500</version>
>> </dependency>
>> <dependency>
>> <groupId>org.eclipse.emf</groupId>
>> <artifactId>org.eclipse.emf.ecore.xmi</artifactId>
>> <version>2.8.0-v20120911-0500</version>
>> </dependency>
>> <dependency>
>> <groupId>org.eclipse.emf</groupId>
>> <artifactId>org.eclipse.emf.ecore</artifactId>
>> <version>2.8.0-v20120911-0500</version>
>> </dependency>
>> <dependency>
>> <groupId>org.eclipse.emf</groupId>
>> <artifactId>org.eclipse.emf.texo.xml</artifactId>
>> <version>0.1.0-v201210251502</version>
>> </dependency>
>> <dependency>
>> <groupId>org.eclipse.emf</groupId>
>> <artifactId>org.eclipse.emf.texo</artifactId>
>> <version>0.1.0-v201210251502</version>
>> </dependency>
>> <dependency>
>> <groupId>org.eclipse.emf</groupId>
>> <artifactId>org.eclipse.emf.texo.server</artifactId>
>> <version>0.1.0-v201210251502</version>
>> </dependency>
>> <dependency>
>> <groupId>org.eclipse.emf</groupId>
>> <artifactId>org.eclipse.emf.texo.json</artifactId>
>> <version>0.1.0-v201210251502</version>
>> </dependency>
>> <!-- Testing -->
>> <dependency>
>> <groupId>org.hamcrest</groupId>
>> <artifactId>hamcrest-all</artifactId>
>> <version>1.3</version>
>> <scope>test</scope>
>> </dependency>
>> <dependency>
>> <groupId>junit</groupId>
>> <artifactId>junit</artifactId>
>> <version>4.9</version>
>> <scope>test</scope>
>> <exclusions>
>> <exclusion>
>> <groupId>org.hamcrest</groupId>
>> <artifactId>hamcrest-core</artifactId>
>> </exclusion>
>> </exclusions>
>> </dependency>
>> </dependencies>
>>
>> MODEL
>> <?xml version="1.0" encoding="UTF-8"?>
>> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="texo" nsURI="http://texo.example.com" nsPrefix="texo">
>> <eClassifiers xsi:type="ecore:EClass" name="Configuration">
>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="fileName" eType="ecore:EDataType
>> http://www.eclipse.org/emf/2002/Ecore#//EString"
>> defaultValueLiteral="nameofthefile" unsettable="true"/>
>> </eClassifiers>
>> </ecore:EPackage>
>>
>>
>> Thoughts?
>>
>> TIA,
>> - Ole
>>
>
>
Re: NPE When Serializing with Texo [message #990970 is a reply to message #990936] Sat, 15 December 2012 13:43 Go to previous message
Martin Taal is currently offline Martin Taal
Messages: 5326
Registered: July 2009
Senior Member
Thanks Ole for the answer, will add to the wiki!

gr. Martin

On 12/15/2012 05:14 AM, Ole Ersoy wrote:
> Hi Martin,
>
> Got it - Thanks! For others reading the thread and using Maven - the file was generating into the "src/main/java", but
> neither "mvn eclipse:eclipse", nor "mvn test" was "seeing" it, since Maven's default behavior is to archive only .java
> files from src/main/java. It expects other resources to be in "src/main/resources". I fixed it by adding this:
>
> <resources>
> <resource>
> <directory>src/main/java</directory>
> <includes>
> <include>com/example/texo/texo.ecore</include>
> </includes>
> </resource>
> </resources>
>
> For details see:
> http://maven.apache.org/plugins/maven-resources-plugin/examples/include-exclude.html
> http://stackoverflow.com/questions/4509309/in-maven-how-can-i-include-non-java-src-files-in-the-same-place-in-the-output-ja
>
> Thanks again for making Texo. It's brilliant,
> - Ole
>
>
>
>
>
>
>
>
>
> On 12/14/2012 05:11 PM, Martin Taal wrote:
>> Hi Ole,
>> Another user has also reported this issue. I changed the error message so it is more descriptive (for now).
>>
>> In the generated code there should also be an ecore file in that same java package. Can you check if this ecore file
>> is there and is also present in the output directory (bin/build)? And that it is present in any other location where
>> you use your runtime code (for example when packaging it in a jar)?
>>
>> gr. Marton
>>
>> On 12/14/2012 11:45 PM, Ole Ersoy wrote:
>>> Hi,
>>>
>>> I'm trying to serialize a model as described here:
>>> http://wiki.eclipse.org/Texo/XML_and_XMI_Serialization
>>>
>>> I did make sure to "Touch" or initialize the model package. I'll first list the exception, then my test code, then my
>>> maven dependencies, then the model.
>>>
>>> EXCEPTION:
>>> java.lang.ExceptionInInitializerError
>>> at com.example.texo.SerializationTest.serialize(SerializationTest.java:17)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
>>> at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
>>> at java.lang.reflect.Method.invoke(Method.java:616)
>>> at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:44)
>>> at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
>>> at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:41)
>>> at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
>>> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:263)
>>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:69)
>>> at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:48)
>>> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
>>> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
>>> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
>>> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
>>> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
>>> at org.junit.runners.ParentRunner.run(ParentRunner.java:292)
>>> at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
>>> at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
>>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
>>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
>>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
>>> at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
>>> Caused by: java.lang.NullPointerException
>>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.getEncoding(XMLLoadImpl.java:314)
>>> at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:122)
>>> at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:240)
>>> at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1505)
>>> at org.eclipse.emf.texo.utils.ModelUtils.readEPackagesFromFile(ModelUtils.java:343)
>>> at com.example.texo.TexoModelPackage.initialize(TexoModelPackage.java:88)
>>> at com.example.texo.TexoModelPackage.<clinit>(TexoModelPackage.java:66)
>>> ... 24 more
>>>
>>> TEST CODE:package com.example.texo;
>>>
>>> import static org.junit.Assert.*;
>>>
>>> import java.io.StringWriter;
>>> import java.util.ArrayList;
>>> import java.util.List;
>>>
>>> import org.eclipse.emf.texo.xml.ModelXMLSaver;
>>> import org.junit.Test;
>>>
>>> public class SerializationTest {
>>>
>>> @Test
>>> public void serialize()
>>> {
>>> TexoModelPackage.initialize();
>>> List<Object> modelObjects = new ArrayList<Object>();
>>> modelObjects.add(new Configuration());
>>>
>>> final ModelXMLSaver xmlSaver = new ModelXMLSaver();
>>> xmlSaver.setSaveAsXMI(true);
>>> xmlSaver.setObjects(modelObjects);
>>> final StringWriter sw = new StringWriter();
>>> xmlSaver.setWriter(sw);
>>> xmlSaver.write();
>>> String content = sw.toString();
>>> assertNotNull(content);
>>> }
>>>
>>> }
>>>
>>> MAVEN DEPENDENCIES:
>>> <dependencies>
>>> <!-- Logging -->
>>> <dependency>
>>> <groupId>ch.qos.logback</groupId>
>>> <artifactId>logback-classic</artifactId>
>>> <version>1.0.7</version>
>>> </dependency>
>>>
>>> <!-- Modeling -->
>>> <dependency>
>>> <groupId>org.eclipse.emf</groupId>
>>> <artifactId>org.eclipse.emf.common</artifactId>
>>> <version>2.8.0-v20120911-0500</version>
>>> </dependency>
>>> <dependency>
>>> <groupId>org.eclipse.emf</groupId>
>>> <artifactId>org.eclipse.emf.ecore.xmi</artifactId>
>>> <version>2.8.0-v20120911-0500</version>
>>> </dependency>
>>> <dependency>
>>> <groupId>org.eclipse.emf</groupId>
>>> <artifactId>org.eclipse.emf.ecore</artifactId>
>>> <version>2.8.0-v20120911-0500</version>
>>> </dependency>
>>> <dependency>
>>> <groupId>org.eclipse.emf</groupId>
>>> <artifactId>org.eclipse.emf.texo.xml</artifactId>
>>> <version>0.1.0-v201210251502</version>
>>> </dependency>
>>> <dependency>
>>> <groupId>org.eclipse.emf</groupId>
>>> <artifactId>org.eclipse.emf.texo</artifactId>
>>> <version>0.1.0-v201210251502</version>
>>> </dependency>
>>> <dependency>
>>> <groupId>org.eclipse.emf</groupId>
>>> <artifactId>org.eclipse.emf.texo.server</artifactId>
>>> <version>0.1.0-v201210251502</version>
>>> </dependency>
>>> <dependency>
>>> <groupId>org.eclipse.emf</groupId>
>>> <artifactId>org.eclipse.emf.texo.json</artifactId>
>>> <version>0.1.0-v201210251502</version>
>>> </dependency>
>>> <!-- Testing -->
>>> <dependency>
>>> <groupId>org.hamcrest</groupId>
>>> <artifactId>hamcrest-all</artifactId>
>>> <version>1.3</version>
>>> <scope>test</scope>
>>> </dependency>
>>> <dependency>
>>> <groupId>junit</groupId>
>>> <artifactId>junit</artifactId>
>>> <version>4.9</version>
>>> <scope>test</scope>
>>> <exclusions>
>>> <exclusion>
>>> <groupId>org.hamcrest</groupId>
>>> <artifactId>hamcrest-core</artifactId>
>>> </exclusion>
>>> </exclusions>
>>> </dependency>
>>> </dependencies>
>>>
>>> MODEL
>>> <?xml version="1.0" encoding="UTF-8"?>
>>> <ecore:EPackage xmi:version="2.0" xmlns:xmi="http://www.omg.org/XMI"
>>> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
>>> xmlns:ecore="http://www.eclipse.org/emf/2002/Ecore" name="texo" nsURI="http://texo.example.com" nsPrefix="texo">
>>> <eClassifiers xsi:type="ecore:EClass" name="Configuration">
>>> <eStructuralFeatures xsi:type="ecore:EAttribute" name="fileName" eType="ecore:EDataType
>>> http://www.eclipse.org/emf/2002/Ecore#//EString"
>>> defaultValueLiteral="nameofthefile" unsettable="true"/>
>>> </eClassifiers>
>>> </ecore:EPackage>
>>>
>>>
>>> Thoughts?
>>>
>>> TIA,
>>> - Ole
>>>
>>
>>
>


--

With Regards, Martin Taal

Springsite/Elver.org
Office: Hardwareweg 4, 3821 BV Amersfoort
Postal: Nassaulaan 7, 3941 EC Doorn
The Netherlands
Cell: +31 (0)6 288 48 943
Tel: +31 (0)84 420 2397
Fax: +31 (0)84 225 9307
Mail: mtaal@xxxxxxxx - mtaal@xxxxxxxx
Web: www.springsite.com - www.elver.org
Previous Topic:Access to the XTend2 Template Files.
Next Topic:Multi Java Annotations in the model
Goto Forum:
  


Current Time: Sat Aug 02 02:43:23 EDT 2014

Powered by FUDForum. Page generated in 0.01824 seconds