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 11:23 Go to next message
Marcus Fessele is currently offline Marcus Fessele
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 11: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 04:03 Go to previous messageGo to next message
Gregoire Dupe is currently offline Gregoire Dupe
Messages: 74
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 17:06 Go to previous messageGo to next message
Marcus Fessele is currently offline Marcus Fessele
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 03:09 Go to previous messageGo to next message
Gregoire Dupe is currently offline Gregoire Dupe
Messages: 74
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 03: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 17:18 Go to previous messageGo to next message
Marcus Fessele is currently offline Marcus Fessele
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 09:38 Go to previous messageGo to next message
Davide Piccione is currently offline Davide Piccione
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 10:23 Go to previous messageGo to next message
Davide Piccione is currently offline Davide Piccione
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 12:13 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
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
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: Generate Java code from a Java model [message #939078 is a reply to message #804477] Wed, 10 October 2012 08:06 Go to previous messageGo to next message
Benjamin Klatt is currently offline Benjamin Klatt
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 11:01 Go to previous messageGo to next message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
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
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Re: Generate Java code from a Java model [message #945970 is a reply to message #945709] Mon, 15 October 2012 16:36 Go to previous messageGo to next message
Rafael Durelli is currently offline Rafael Durelli
Messages: 51
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 05:31 Go to previous message
Fabien Giquel is currently offline Fabien Giquel
Messages: 138
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
4, rue du Château de l'Eraudiere
44324 NANTES CEDEX 03
----------------------------------------------------
Previous Topic:How to specifiy query parameters in the Query Executions view?
Next Topic:Help with KDM transformation
Goto Forum:
  


Current Time: Wed Jul 23 04:02:00 EDT 2014

Powered by FUDForum. Page generated in 0.01998 seconds