Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » MoDisco » Generate Java code from a Java model
Generate Java code from a Java model [message #776997] Mon, 09 January 2012 16:23 Go to next message
Marcus Fessele is currently offline Marcus FesseleFriend
Messages: 4
Registered: January 2012
Junior Member
Hey guys,

I want to generate java code from a .xmi model. I extracted the model from a project and now I want to generate code refers to ttp://wiki.eclipse.org/MoDisco/Components/Java/Documentation/0.9#Java_Generation

But when I write the sample code I get an error:

"The type org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator cannot be resolved. It is indirectly referenced from required .class files"

My code:

 	GenerateJavaExtended javaGenerator = new GenerateJavaExtended(URI.createFileURI("../Model.xmi"),
				    new File("../myOutputFolder"), new ArrayList<Object>());
			
	javaGenerator.doGenerate(null);


I added the org.eclipse.gmt.modisco.java.generation as a dependencie to my plugin.xml but it doesn't work.

So can someone help me?

Greetings
Marcus

[Updated on: Mon, 09 January 2012 16:26]

Report message to a moderator

Re: Generate Java code from a Java model [message #777306 is a reply to message #776997] Tue, 10 January 2012 09:03 Go to previous messageGo to next message
Gregoire Dupe is currently offline Gregoire DupeFriend
Messages: 75
Registered: September 2009
Location: France
Member
Hello,

I think you also have to add the plug-in 'org.eclipse.acceleo.engine' in your plug-in dependencies.

If its works, tell me, I'll update the documentation.

Regards,
Grégoire
Re: Generate Java code from a Java model [message #777678 is a reply to message #777306] Tue, 10 January 2012 22:06 Go to previous messageGo to next message
Marcus Fessele is currently offline Marcus FesseleFriend
Messages: 4
Registered: January 2012
Junior Member
Hey Gregoire,

thanks for your reply. It solves my problem, thank you. But now I have a further problem.

Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for 'jar:file:[..]/eclipse/plugins/org.eclipse.gmt.modisco.java.generation_0.9.1.v201109150824.jar!/org/eclipse/gmt/modisco/java/generation/files/GenerateJava.emtl'; a registered resource factory is needed
	at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:394)
	at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:348)
	at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.initialize(AbstractAcceleoGenerator.java:441)
	at org.eclipse.gmt.modisco.java.generation.files.GenerateJava.<init>(GenerateJava.java:85)
	at org.eclipse.gmt.modisco.java.generation.files.GenerateJavaExtended.<init>(GenerateJavaExtended.java:39)
	at MDSDMoDiscoProject.GenerateJavaCode.main(GenerateJavaCode.java:34)


I tried to solve this problem with the following code but it doesn't work:

		
XMIResourceFactoryImpl xmiResourceFactoryImpl = new XMIResourceFactoryImpl() {
			public Resource createResource(URI uri) {
				XMIResource xmiResource = new XMIResourceImpl(uri);
				return xmiResource;
			}
		};

Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
		"xmi", xmiResourceFactoryImpl);


Any further advises or tips?

Regards
Marcus
Re: Generate Java code from a Java model [message #777963 is a reply to message #777678] Wed, 11 January 2012 08:09 Go to previous messageGo to next message
Gregoire Dupe is currently offline Gregoire DupeFriend
Messages: 75
Registered: September 2009
Location: France
Member
Hello,

I think you haven't installed or enable the plug-in 'org.eclipse.acceleo.model' in your target platform. This plug-in is not required for the compilation but it is required for the execution.

I've opened a bug asking to reexport the required dependencies (Bug 368318).

Regards,
Grégoire

[Updated on: Wed, 11 January 2012 08:10]

Report message to a moderator

Re: Generate Java code from a Java model [message #778244 is a reply to message #777963] Wed, 11 January 2012 22:18 Go to previous messageGo to next message
Marcus Fessele is currently offline Marcus FesseleFriend
Messages: 4
Registered: January 2012
Junior Member
Hey,

that works for me. Thank you.

I've also added the following dependencies:

com.google.inject;bundle-version="2.0.0",
com.google.collect;bundle-version="1.0.0",
org.eclipse.jdt.core;bundle-version="3.7.1"


I guess the last one was for the code formatter.

Regards,
Marcus

Re: Generate Java code from a Java model [message #790600 is a reply to message #778244] Sat, 04 February 2012 14:38 Go to previous messageGo to next message
Davide Piccione is currently offline Davide PiccioneFriend
Messages: 2
Registered: February 2012
Junior Member
Hello,
unfortunately i don't yet solve the same problem.
I used both method illustrated in online guide but both don't run correctly. I use eclipse Indigo.

The errors are:
- Couldn't load class org.eclipse.gmt.modisco.java.generation.files.GenerateJavaExtended. Check that its containing package is exported. -> if I use the second mode with Acceleo as runner.

- Exception in thread "main" java.lang.RuntimeException: Cannot create a resource for './prova.xmi'; a registered resource factory is needed -> if i use the first mode and also if i use the second mode with Java Application as runner.

I imported all library indicated in this topic but it doesn't run good.

Somebody can explain better how it does?

Thank you.

p.s.: sorry for my english Wink
Re: Generate Java code from a Java model [message #790618 is a reply to message #790600] Sat, 04 February 2012 15:23 Go to previous messageGo to next message
Davide Piccione is currently offline Davide PiccioneFriend
Messages: 2
Registered: February 2012
Junior Member
Hello,
finally i solved the problem!!!

These are the steps (with Eclipse Indigo):
1. import in workspace the plugin org.eclipse.gmt.modisco.java.generation by File/Import/Plugin and fragments;

2. in src folder create a java Classe that like this:

public class Generation {

	public static void main(String[] args) throws IOException {
		XMIResourceFactoryImpl xmiResourceFactoryImpl = new XMIResourceFactoryImpl() {
			public Resource createResource(URI uri) {
				XMIResource xmiResource = new XMIResourceImpl(uri);
				return xmiResource;
			}
		};

		Resource.Factory.Registry.INSTANCE.getExtensionToFactoryMap().put(
				"xmi", xmiResourceFactoryImpl);

		GenerateJavaExtended javaGenerator = new GenerateJavaExtended(
				URI.createFileURI("src/generation/prova.xmi"),
				new File("src/"), new ArrayList<Object>());

		javaGenerator.doGenerate(null);
	}

}

3. Run this as java application.

Thanks Marcus for the Code! Smile
Re: Generate Java code from a Java model [message #804477 is a reply to message #790618] Wed, 22 February 2012 17:13 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien GiquelFriend
Messages: 147
Registered: July 2009
Senior Member
Hi David,

glad that you have succeeded in launching generation from some main() method, calling some xmi resource factory registration.

There are several ways of reusing the generation acceleo module, with several technical difficulties. We recommend this one : invoking GenerateJavaExtended class in one java plugin project, with dependencies to org.eclipse.gmt.modisco.java.generation installed plugin. Then the code must be executed within an eclipse context ("Eclipse Application" Run Config)

Modisco Documentation has been updated (Bug 372090) for focusing on this recommendation.

Regards,
Fabien.


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
rue Nina Simone
44000 NANTES
----------------------------------------------------
Re: Generate Java code from a Java model [message #939078 is a reply to message #804477] Wed, 10 October 2012 12:06 Go to previous messageGo to next message
Benjamin Klatt is currently offline Benjamin KlattFriend
Messages: 36
Registered: September 2010
Member
Dear Fabien,

I checked the java generation with the latest modisco release and noticed that:

1. Acceleo misses the emtl file when I import the plugin as a project (java.io.IOException: 'GenerateJava.emtl' not found)

2. When checking out the source from the svn trunk:
a) The svn repository location is outdated:
http://wiki.eclipse.org/MoDisco/JavaGeneration#Install
must be changed to
https://dev.eclipse.org/svnroot/modeling/org.eclipse.mdt.modisco/main/trunk/org.eclipse.gmt.modisco.java.generation/

b) Acceleo requires the generator plugin to have access to some google classes
http://wiki.eclipse.org/Acceleo/FAQ#Exception_in_thread_.22main.22_java.lang.NoClassDefFoundError:_com.2Fgoogle.2Fcommon.2Fbase.2FPredicate
which are meanwhile hosted within the google guava project. The guava plugin might already be installed, but the modisco java generator plugin requires a dependency to com.google.guava

Could you please update the documentation and the java generation project or can you tell me how I could contribute this update to your resources?

Thanks in advance
Benjamin
Re: Generate Java code from a Java model [message #945709 is a reply to message #939078] Mon, 15 October 2012 15:01 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien GiquelFriend
Messages: 147
Registered: July 2009
Senior Member
Hi Benjamin,

thank you for these observations.
2a) i have updated the wiki documentation
2b) i was not aware of these google plugins dependency. I will have a look at it for understanding.

Fabien


----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
rue Nina Simone
44000 NANTES
----------------------------------------------------
Re: Generate Java code from a Java model [message #945970 is a reply to message #945709] Mon, 15 October 2012 20:36 Go to previous messageGo to next message
Rafael Durelli is currently offline Rafael DurelliFriend
Messages: 72
Registered: September 2012
Member
Thanks guys. I'm using Java model to generate files .java. Thanks to this forum I have done it. Best Regards
Re: Generate Java code from a Java model [message #994081 is a reply to message #776997] Wed, 26 December 2012 10:31 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien GiquelFriend
Messages: 147
Registered: July 2009
Senior Member
From what i understand, com.google.guava dependency should have been transparantly fixed with Bug 364265.

----------------------------------------------------
Fabien GIQUEL
R&D Engineer
Mia-Software
rue Nina Simone
44000 NANTES
----------------------------------------------------
Re: Generate Java code from a Java model [message #1804023 is a reply to message #994081] Fri, 15 March 2019 22:51 Go to previous message
Ali Sardarian is currently offline Ali SardarianFriend
Messages: 12
Registered: March 2019
Junior Member
Hi
I Tried the discussed steps in Eclipse 2018-12

But I get this error when I ran the generation class :
Exception in thread "main" java.lang.IndexOutOfBoundsException: Index: 67, Size: 1
at java.util.ArrayList.rangeCheck(Unknown Source)
at java.util.ArrayList.get(Unknown Source)
at org.eclipse.emf.ecore.impl.EPackageImpl.eObjectForURIFragmentNameSegment(EPackageImpl.java:1970)
at org.eclipse.emf.ecore.impl.EModelElementImpl.eObjectForURIFragmentSegment(EModelElementImpl.java:473)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:811)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.getEObject(ResourceImpl.java:787)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setValueFromId(XMLHandler.java:2868)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.setAttribValue(XMLHandler.java:2773)
at org.eclipse.emf.ecore.xmi.impl.SAXXMIHandler.handleObjectAttribs(SAXXMIHandler.java:79)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromFactory(XMLHandler.java:2247)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObjectFromTypeName(XMLHandler.java:2150)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.createObject(XMLHandler.java:2085)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.createObject(XMIHandler.java:151)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.handleFeature(XMLHandler.java:1868)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.processElement(XMLHandler.java:1048)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.processElement(XMIHandler.java:82)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:1026)
at org.eclipse.emf.ecore.xmi.impl.XMLHandler.startElement(XMLHandler.java:720)
at org.eclipse.emf.ecore.xmi.impl.XMIHandler.startElement(XMIHandler.java:190)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanStartElement(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(Unknown Source)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(Unknown Source)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(Unknown Source)
at org.eclipse.emf.ecore.xmi.impl.XMLLoadImpl.load(XMLLoadImpl.java:175)
at org.eclipse.emf.ecore.xmi.impl.XMLResourceImpl.doLoad(XMLResourceImpl.java:261)
at org.eclipse.acceleo.model.mtl.resource.EMtlResourceImpl.doLoad(EMtlResourceImpl.java:93)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1563)
at org.eclipse.emf.ecore.resource.impl.ResourceImpl.load(ResourceImpl.java:1342)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoad(ResourceSetImpl.java:259)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.demandLoadHelper(ResourceSetImpl.java:274)
at org.eclipse.emf.ecore.resource.impl.ResourceSetImpl.getResource(ResourceSetImpl.java:406)
at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:391)
at org.eclipse.acceleo.common.utils.ModelUtils.load(ModelUtils.java:356)
at org.eclipse.acceleo.engine.service.AbstractAcceleoGenerator.initialize(AbstractAcceleoGenerator.java:485)
at org.eclipse.gmt.modisco.java.generation.files.GenerateJava.<init>(GenerateJava.java:92)
at org.eclipse.gmt.modisco.java.generation.files.GenerateJavaExtended.<init>(GenerateJavaExtended.java:39)
at Generation.main(Generation.java:13)


what's the problem? How can I fix this issue?

Thanks
Previous Topic: Is it possible to generate Java code from a resource only loaded in memory?
Next Topic:Problem with Java model to source code transformation
Goto Forum:
  


Current Time: Thu Mar 28 21:30:17 GMT 2024

Powered by FUDForum. Page generated in 0.03240 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top