Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » TMF (Xtext) » How to run automatically generated java file has a method main in Xtext generator ?
How to run automatically generated java file has a method main in Xtext generator ? [message #1755310] Thu, 02 March 2017 09:53 Go to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
I create a template in myDSLGenerator.Xtend in this template a method main, then when runtime eclipse and write myDSL in Xtext Editor. i want when save my dsl model the genrated java file run automatically when is generating.

is there a method to run my method main in Xtend.

[Updated on: Thu, 02 March 2017 09:56]

Report message to a moderator

Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755311 is a reply to message #1755310] Thu, 02 March 2017 09:55 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
Hi,

can you please give more context?

- if you are in eclipse
- if you are in a project that has xtext nature
- if this project not a java project or is a java project and the test.mydsl file is in a source folder
- if build automatically is on.

the generator will be called on save


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755312 is a reply to message #1755311] Thu, 02 March 2017 09:59 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
p.s.: it will not call the main, it will call doGenerate

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755313 is a reply to message #1755311] Thu, 02 March 2017 10:01 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
if I am in a project that has xtext nature then save the generated java file is contain a method main i want to build automatically .
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755315 is a reply to message #1755313] Thu, 02 March 2017 10:04 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
Is there a mthod doRun to run the genrated java file or other solution
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755320 is a reply to message #1755315] Thu, 02 March 2017 10:31 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
can you please elaborarate your usecase.
you can do inside doGenerate whatever you want. (even call another java main)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755322 is a reply to message #1755320] Thu, 02 March 2017 10:43 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
or do you want to run the file that was generated? this you have to do yourself.
there is no out of the box mechanism for that


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755327 is a reply to message #1755322] Thu, 02 March 2017 11:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
well there is actually a way if you abuse xtext.xbase.testing (you need to add a dependency to that testing bundle at runtime)


		val cl = MyDslGenerator.classLoader
		println(cl)
		val InMemoryJavaCompiler compiler = new InMemoryJavaCompiler(cl, JavaVersion.JAVA8)
		val result = compiler.compile(new JavaSource(
			"a/Hello.java",
			'''
				package a; 
				public class Hello {
					public static void main(String[] args) {
						System.out.println("Hello Dynamic");
					}
				}
			'''
		))
		val Class<?> mainClazz = result.classLoader.loadClass("a.Hello")
		val Method mainMethod = mainClazz.getMethod("main", typeof(String[]));
		val String[] args = #[]
		mainMethod.invoke(null,#[args])



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755341 is a reply to message #1755327] Thu, 02 March 2017 13:22 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
thanks for your quick answer , OK where i put this code it's not clear ? i put it in myDSLGenerator.xtend please help me .

And where i add the Dependency .

[Updated on: Thu, 02 March 2017 13:26]

Report message to a moderator

Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755346 is a reply to message #1755341] Thu, 02 March 2017 13:57 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
add it to the dependencys in manifest.mf

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755349 is a reply to message #1755346] Thu, 02 March 2017 14:23 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
About this code where i put it
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755353 is a reply to message #1755349] Thu, 02 March 2017 14:48 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
what about there where you have the generate java in hand.

i dont know if you wrote

- an igenerator
- a builder participant
- something else
- ......

=> first try then ask


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755371 is a reply to message #1755353] Thu, 02 March 2017 16:56 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
yes , i wrote an igenerator i add this dependency org.eclipse.xtext.xbase.testing;resolution:=optional in manifest and import xtext.xbase.testing but i have this problem :

- The method or field JavaVersion is undefined for the type MyDslGenerator
- InMemoryJavaCompiler cannot be resolved.
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755377 is a reply to message #1755371] Thu, 02 March 2017 17:08 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
argggggggggggggg

import java.lang.reflect.Method
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.eclipse.xtext.util.JavaVersion
import org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler
import org.eclipse.xtext.xbase.testing.JavaSource


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755379 is a reply to message #1755377] Thu, 02 March 2017 17:28 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
i have errors in this imports ;

import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.eclipse.xtext.util.JavaVersion

org.eclipse.xtext.generator.IFileSystemAccess2 cannot be resolved
to a type.

org.eclipse.xtext.generator.IFileSystemAccess2 cannot be resolved to a type.

org.eclipse.xtext.generator.IGeneratorContext cannot be resolved
to a type.
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755380 is a reply to message #1755379] Thu, 02 March 2017 17:32 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
which xtext version do you use?
how does your generator look like?

the generator that xtext creates out of the box looks like

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext

/**
 * Generates code from your model files on save.
 * 
 * See https://www.eclipse.org/Xtext/documentation/303_runtime_concepts.html#code-generation
 */
class MyDslGenerator extends AbstractGenerator {

	override void doGenerate(Resource resource, IFileSystemAccess2 fsa, IGeneratorContext context) {
//		fsa.generateFile('greetings.txt', 'People to greet: ' + 
//			resource.allContents
//				.filter(Greeting)
//				.map[name]
//				.join(', '))
	}
}



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755385 is a reply to message #1755380] Thu, 02 March 2017 17:43 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
i have Xtext version : 2.4.3

this mydslIGenerator :

import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.IGenerator
import org.eclipse.xtext.generator.IFileSystemAccess
import org.xtext.example.mydsl.myDsl.Entity
import java.lang.reflect.Method
import org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler
import org.eclipse.xtext.xbase.testing.JavaSource

import java.lang.reflect.Method
import org.eclipse.emf.ecore.resource.Resource
import org.eclipse.xtext.generator.AbstractGenerator
import org.eclipse.xtext.generator.IFileSystemAccess2
import org.eclipse.xtext.generator.IGeneratorContext
import org.eclipse.xtext.util.JavaVersion
import org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler
import org.eclipse.xtext.xbase.testing.JavaSource


/**
 * Generates code from your model files on save.
 * 
 * see http://www.eclipse.org/Xtext/documentation.html#TutorialCodeGeneration
 */
class MyDslGenerator implements IGenerator {
	
	override void doGenerate(Resource resource, IFileSystemAccess fsa) {
for(e: resource.allContents.toIterable.filter(typeof(Entity))){
		 	compile(e,fsa) }
				val cl = MyDslGenerator.classLoader
		println(cl)
		val InMemoryJavaCompiler compiler = 
		new InMemoryJavaCompiler(cl, JavaVersion.JAVA7)
		val result = compiler.compile(new JavaSource(
			"a/Hello.java",
			'''
				package a; 
				public class Hello {
					public static void main(String[] args) {
						System.out.println("Hello Dynamic");
					}
				}
			'''
		))
		val Class<?> mainClazz = result.classLoader.loadClass("a.Hello")
		val Method mainMethod = mainClazz.getMethod("main", typeof(String[]));
		val String[] args = #[]
		mainMethod.invoke(null,#[args])
		
	}



Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755386 is a reply to message #1755385] Thu, 02 March 2017 17:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
arrrg

in that stoneange version this is all different.

i dont know if it has the InMemoryJavaCompiler. i doubt that Sad
if yes it is in a different package and may have different api.

=> you have have to use a more recent xtext version.

what is the reason you keep using this real stone stone stone (dinosaur) age version of xtext?


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Thu, 02 March 2017 17:47]

Report message to a moderator

Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755387 is a reply to message #1755386] Thu, 02 March 2017 17:53 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
i ' m using PolarSys IDE Version: 0.8 integrating Xtext

witch eclipse and xtext version do you use for download it .
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755388 is a reply to message #1755387] Thu, 02 March 2017 18:12 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
i use xtext 2.11

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755389 is a reply to message #1755388] Thu, 02 March 2017 18:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
you may use this class in your old version https://github.com/eclipse/xtext/blob/v2.4.3/plugins/org.eclipse.xtext.xbase.junit/src/org/eclipse/xtext/xbase/compiler/OnTheFlyJavaCompiler.java

but i cannot tell you how to use it.
maybe google helps.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
icon5.gif  Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755394 is a reply to message #1755389] Thu, 02 March 2017 18:54 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
I search in googel for this but i didn't find it , can you help me please ?

Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755397 is a reply to message #1755394] Thu, 02 March 2017 19:18 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
how much experience do you have as a programmer in general?

if google does not find anything you have to have a look at the stoneage old xtext test code yourself

		val OnTheFlyJavaCompiler compiler = new OnTheFlyJavaCompiler()
		val mainClazz = compiler.compileToClass("a.Hello", '''
				package a; 
				public class Hello {
					public static void main(String[] args) {
						System.out.println("Hello Dynamic");
					}
				}
			''')
		
		val Method mainMethod = mainClazz.getMethod("main", typeof(String[]));
		val String[] args = #[]
		mainMethod.invoke(null,#[args])


or simpy have a look at the class and the methods and .....

git clone git@github.com:eclipse/xtext.git
cd xtext
git checkout tags/v2.4.3 -b v2.4.3
cd tests
grep -ril "new OnTheFlyJavaCompiler" .


results ./org.eclipse.xtext.xbase.tests/src/org/eclipse/xtext/xbase/tests/compiler/OnTheFlyJavaCompilerTest.java
open it in editor and have a look



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755427 is a reply to message #1755397] Fri, 03 March 2017 09:25 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
Hii Christian DietrichFriend , I updated my Xtext to last version and the error of pervious imports is resloved , But when runtime new eclipse for writing my Dsl then press CTRL+S i have this error :

Errors occurred during the build.
Errors running builder 'Xtext Project Builder' on project 'Test'.
org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler

and this code error in Console , Did you test it in your machine ?


!ENTRY org.eclipse.osgi 2 0 2017-03-03 10:03:55.175
!MESSAGE While loading class "org.eclipse.egit.ui.internal.ConfigurationChecker$1$1", thread "Thread[Worker-1,5,main]" timed out waiting (5021ms) for thread "Thread[main,6,main]" to finish starting bundle "org.eclipse.egit.ui_4.4.1.201607150455-r [146]". To avoid deadlock, thread "Thread[Worker-1,5,main]" is proceeding but "org.eclipse.egit.ui.internal.ConfigurationChecker$1$1" may not be fully initialized.
!STACK 0
org.osgi.framework.BundleException: Unable to acquire the state change lock for the module: osgi.identity; type="osgi.bundle"; version:Version="4.4.1.201607150455-r"; osgi.identity="org.eclipse.egit.ui"; singleton:="true" [id=146] STARTED [STARTED]
	at org.eclipse.osgi.container.Module.lockStateChange(Module.java:337)
	at org.eclipse.osgi.container.Module.start(Module.java:401)
	at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:470)
	at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
	at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:529)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
	at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at org.eclipse.egit.ui.internal.ConfigurationChecker$1.run(ConfigurationChecker.java:45)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.util.concurrent.TimeoutException: Timeout after waiting 5 seconds to acquire the lock.
	at org.eclipse.osgi.container.Module.lockStateChange(Module.java:334)
	... 13 more
Root exception:
java.util.concurrent.TimeoutException: Timeout after waiting 5 seconds to acquire the lock.
	at org.eclipse.osgi.container.Module.lockStateChange(Module.java:334)
	at org.eclipse.osgi.container.Module.start(Module.java:401)
	at org.eclipse.osgi.framework.util.SecureAction.start(SecureAction.java:470)
	at org.eclipse.osgi.internal.hooks.EclipseLazyStarter.postFindLocalClass(EclipseLazyStarter.java:107)
	at org.eclipse.osgi.internal.loader.classpath.ClasspathManager.findLocalClass(ClasspathManager.java:529)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.findLocalClass(ModuleClassLoader.java:325)
	at org.eclipse.osgi.internal.loader.BundleLoader.findLocalClass(BundleLoader.java:345)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:423)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	at org.eclipse.egit.ui.internal.ConfigurationChecker$1.run(ConfigurationChecker.java:45)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)

!ENTRY org.eclipse.oomph.setup.ui 2 0 2017-03-03 10:06:55.172
!MESSAGE java.lang.NullPointerException
!STACK 0
java.lang.NullPointerException
	at org.eclipse.oomph.setup.ui.SetupUIPlugin.performStartup(SetupUIPlugin.java:443)
	at org.eclipse.oomph.setup.ui.SetupUIPlugin.access$5(SetupUIPlugin.java:414)
	at org.eclipse.oomph.setup.ui.SetupUIPlugin$1$1.run(SetupUIPlugin.java:253)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
org.eclipse.osgi.internal.loader.EquinoxClassLoader@24f9a670[org.xtext.example.mydsl:1.0.0.qualifier(id=964)]

!ENTRY org.eclipse.core.resources 4 2 2017-03-03 10:09:45.042
!MESSAGE Problems occurred when invoking code from plug-in: "org.eclipse.core.resources".
!STACK 0
java.lang.NoClassDefFoundError: org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler
	at org.xtext.example.mydsl.generator.MyDslGenerator.doGenerate(MyDslGenerator.java:30)
	at org.eclipse.xtext.generator.GeneratorDelegate.doGenerate(GeneratorDelegate.java:43)
	at org.eclipse.xtext.generator.GeneratorDelegate.generate(GeneratorDelegate.java:34)
	at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:564)
	at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:549)
	at org.eclipse.xtext.builder.BuilderParticipant.doGenerate(BuilderParticipant.java:534)
	at org.eclipse.xtext.builder.BuilderParticipant.doBuild(BuilderParticipant.java:280)
	at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:238)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant$DeferredBuilderParticipant.build(RegistryBuilderParticipant.java:161)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:69)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:291)
	at org.eclipse.xtext.builder.impl.XtextBuilder.fullBuild(XtextBuilder.java:319)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:155)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.ClassNotFoundException: org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler cannot be found by org.xtext.example.mydsl_1.0.0.qualifier
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 25 more

!ENTRY org.eclipse.core.resources 4 75 2017-03-03 10:09:45.297
!MESSAGE Errors occurred during the build.
!SUBENTRY 1 org.eclipse.xtext.ui.shared 4 75 2017-03-03 10:09:45.298
!MESSAGE Errors running builder 'Xtext Project Builder' on project 'Test'.
!STACK 0
java.lang.NoClassDefFoundError: org/eclipse/xtext/xbase/testing/InMemoryJavaCompiler
	at org.xtext.example.mydsl.generator.MyDslGenerator.doGenerate(MyDslGenerator.java:30)
	at org.eclipse.xtext.generator.GeneratorDelegate.doGenerate(GeneratorDelegate.java:43)
	at org.eclipse.xtext.generator.GeneratorDelegate.generate(GeneratorDelegate.java:34)
	at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:564)
	at org.eclipse.xtext.builder.BuilderParticipant.handleChangedContents(BuilderParticipant.java:549)
	at org.eclipse.xtext.builder.BuilderParticipant.doGenerate(BuilderParticipant.java:534)
	at org.eclipse.xtext.builder.BuilderParticipant.doBuild(BuilderParticipant.java:280)
	at org.eclipse.xtext.builder.BuilderParticipant.build(BuilderParticipant.java:238)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant$DeferredBuilderParticipant.build(RegistryBuilderParticipant.java:161)
	at org.eclipse.xtext.builder.impl.RegistryBuilderParticipant.build(RegistryBuilderParticipant.java:69)
	at org.eclipse.xtext.builder.impl.XtextBuilder.doBuild(XtextBuilder.java:291)
	at org.eclipse.xtext.builder.impl.XtextBuilder.fullBuild(XtextBuilder.java:319)
	at org.eclipse.xtext.builder.impl.XtextBuilder.build(XtextBuilder.java:155)
	at org.eclipse.core.internal.events.BuildManager$2.run(BuildManager.java:735)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:206)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:246)
	at org.eclipse.core.internal.events.BuildManager$1.run(BuildManager.java:301)
	at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
	at org.eclipse.core.internal.events.BuildManager.basicBuild(BuildManager.java:304)
	at org.eclipse.core.internal.events.BuildManager.basicBuildLoop(BuildManager.java:360)
	at org.eclipse.core.internal.events.BuildManager.build(BuildManager.java:383)
	at org.eclipse.core.internal.events.AutoBuildJob.doBuild(AutoBuildJob.java:144)
	at org.eclipse.core.internal.events.AutoBuildJob.run(AutoBuildJob.java:235)
	at org.eclipse.core.internal.jobs.Worker.run(Worker.java:55)
Caused by: java.lang.ClassNotFoundException: org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler cannot be found by org.xtext.example.mydsl_1.0.0.qualifier
	at org.eclipse.osgi.internal.loader.BundleLoader.findClassInternal(BundleLoader.java:461)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:372)
	at org.eclipse.osgi.internal.loader.BundleLoader.findClass(BundleLoader.java:364)
	at org.eclipse.osgi.internal.loader.ModuleClassLoader.loadClass(ModuleClassLoader.java:161)
	at java.lang.ClassLoader.loadClass(Unknown Source)
	... 25 more

!ENTRY org.eclipse.jface 2 0 2017-03-03 10:09:49.860
!MESSAGE Keybinding conflicts occurred.  They may interfere with normal accelerator operation.
!SUBENTRY 1 org.eclipse.jface 2 0 2017-03-03 10:09:49.861
!MESSAGE A conflict occurred for ALT+CTRL+H:
Binding(ALT+CTRL+H,
	ParameterizedCommand(Command(org.eclipse.jdt.ui.edit.text.java.open.call.hierarchy,Open Call Hierarchy,
		Open a call hierarchy on the selected element,
		Category(org.eclipse.ui.category.navigate,Navigate,null,true),
		org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@4a0e955,
		,,true),null),
	org.eclipse.ui.defaultAcceleratorConfiguration,
	org.eclipse.ui.contexts.window,,,system)
Binding(ALT+CTRL+H,
	ParameterizedCommand(Command(org.eclipse.xtext.xbase.ui.hierarchy.OpenCallHierarchy,Open Call Hierarchy,
		Open a call hierarchy on the selected element,
		Category(org.eclipse.core.commands.categories.autogenerated,Uncategorized,Commands that were either auto-generated or have no category,true),
		org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@117ea0cf,
		,,true),null),
	org.eclipse.ui.defaultAcceleratorConfiguration,
	org.eclipse.xtext.ui.XtextEditorScope,,,system)
Binding(ALT+CTRL+H,
	ParameterizedCommand(Command(org.eclipse.xtext.ui.editor.OpenCallHierarchy,Open Call Hierarchy,
		Open call hierarchy for the selected element,
		Category(org.eclipse.ui.category.navigate,Navigate,null,true),
		org.eclipse.ui.internal.WorkbenchHandlerServiceHandler@57dbd55d,
		,,true),null),
	org.eclipse.ui.defaultAcceleratorConfiguration,
	org.eclipse.xtext.ui.XtextEditorScope,,,system)

Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755436 is a reply to message #1755427] Fri, 03 March 2017 10:54 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
yes i did but with xtext 2.11 ?!? did you switch?
did you add the plugin to your runtime/feature/.... (i dont know how you start your runtime eclipse make sure the plugin is picked up)


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755457 is a reply to message #1755436] Fri, 03 March 2017 14:05 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
i use xtext 2.10 , and witch plugin did you mean ?

[Updated on: Fri, 03 March 2017 14:12]

Report message to a moderator

Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755459 is a reply to message #1755457] Fri, 03 March 2017 14:16 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
in xtext 2.10 !?! there is no testing. it is xbase.junit and the import is different

org.eclipse.xtext.xbase.compiler.InMemoryJavaCompiler


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755460 is a reply to message #1755459] Fri, 03 March 2017 14:25 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
I should update xtext to 2.11.0 for importing org.eclipse.xtext.xbase.testing . so the pervious error for xtext version , and what about this version is there other class for run method main ?
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755461 is a reply to message #1755460] Fri, 03 March 2017 14:28 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
as i said: there is a feature like organzie imports that should help you discover

- xtext 2.4.3 : OnTheFlyJavaCompiler
- xtext 2.10.0: org.eclipse.xtext.xbase.compiler.InMemoryJavaCompiler
- xtext 2.11.0: org.eclipse.xtext.xbase.testing.InMemoryJavaCompiler


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755466 is a reply to message #1755461] Fri, 03 March 2017 14:46 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
I don't have org.eclipse.xtext.xbase.compiler.InMemoryJavaCompiler in xtext 2.10.0 where i found it
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755467 is a reply to message #1755466] Fri, 03 March 2017 14:47 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
did you add org.eclipse.xtext.xbase.junit to the dependencies?

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755538 is a reply to message #1755467] Sun, 05 March 2017 10:36 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
Hi Christian Dietrich Thanks for your answer , it's work in Xtext 2.10.0 but where i find the package a and the class Hello.java it's not in the package src-gen .
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755541 is a reply to message #1755538] Sun, 05 March 2017 11:21 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
i dont understand that ?!?!?!?!?!?!?!?!?

you are the guy that generates file and you are the guy that generates it to a directory.

fsa.generateFile(name, content)

in my example i simpy take the class name and the content and compile it.
i dont generate any file. i thought that was OBVIOUS !?!?!?!?!.

i dont care about the generated files. i simply execute them.

=> Your jub is to implement the generator and do the calling. it is not mine.


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Sun, 05 March 2017 11:28]

Report message to a moderator

Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755551 is a reply to message #1755541] Sun, 05 March 2017 16:36 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
I want to put the class java in my directory how to put it in pervious code .
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755552 is a reply to message #1755551] Sun, 05 March 2017 16:53 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
Don't understand please explain

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755554 is a reply to message #1755552] Sun, 05 March 2017 17:08 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
In this Code i want to put the class java in my pc like this

val cl = DDslGenerator.classLoader
		println(cl)
		val InMemoryJavaCompiler compiler = 
		new InMemoryJavaCompiler(cl, JavaVersion.JAVA7)
		val result = compiler.compile(new JavaSource(
			[b]"D:/New folder/a/Hello.java",[/b]
			'''
				package a; 
				public class Hello {
					public static void main(String[] args) {
						System.out.println("Hello Dynamic");
					}
				}
			'''
		))
		val Class<?> mainClazz = result.classLoader.loadClass("a.Hello")
		val Method mainMethod = mainClazz.getMethod("main", typeof(String[]));
		val String[] args = #[]
		mainMethod.invoke(null,#[args])
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755555 is a reply to message #1755554] Sun, 05 March 2017 17:11 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
once again:

GENARATION and EXECUTION have ZERO!!!!!!! in common.

you abuse the igenrator to find a place to execute
and you abuse the compiler class from test to execute

you should not use absolute file nams there.
the i generator is ment to generate to the project.
why is this a problem now?
if you want to generate somewhere else please use normal java file io means


if you want to generate files which has nothing todo with executing !!!!!
!!!!
!!!
!!!!
then use filesystemaccess



Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com

[Updated on: Sun, 05 March 2017 17:14]

Report message to a moderator

Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755556 is a reply to message #1755555] Sun, 05 March 2017 17:22 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
i mean the class Home.java that has method main is not in my PC ,i want to create java class method main .
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755557 is a reply to message #1755556] Sun, 05 March 2017 17:26 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
Yes but you said you had implemented the generator before
Didn't you


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755558 is a reply to message #1755557] Sun, 05 March 2017 17:35 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
yes i want to generate files which has nothing todo with executing to generate files which has nothing todo with executing , i want just to excute method main to call other classs java in IGenerator
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755559 is a reply to message #1755558] Sun, 05 March 2017 17:36 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
I don't understand. Simply call it. .....

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755560 is a reply to message #1755559] Sun, 05 March 2017 17:37 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
Where does the class come from.

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755561 is a reply to message #1755560] Sun, 05 March 2017 17:45 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
I have a class java in specific folder has a method main , then in myDSLIgenerator i want run the pervious class java has method main that's it .
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755562 is a reply to message #1755561] Sun, 05 March 2017 17:51 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
Do you have a .java or a .class file

If it is a .classfile then it would be easiest to put in the classpath of the mydsl project
Package it in a jar file. Copy the jar file to the mydsl project (e.g. Create a lib folder)
Adapt build.properties to include lib folder. Adapt manifest to add Lib/xxx.jar
To the classpath
http://stackoverflow.com/questions/8387359/external-jars-in-eclipse-plug-in


Or you use urlclassloader to load the class file

If it is a Java source file only you already have to tools
Simply use Java to read the file and then call the execute we discussed before




Or you use it as


Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755564 is a reply to message #1755562] Sun, 05 March 2017 18:38 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
it's .java file , I try to read a file to the pervious class Hello.java but i found errors
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755565 is a reply to message #1755564] Sun, 05 March 2017 18:45 Go to previous messageGo to next message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
???

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755622 is a reply to message #1755565] Mon, 06 March 2017 11:27 Go to previous messageGo to next message
abdf mncr is currently offline abdf mncrFriend
Messages: 75
Registered: February 2017
Member
I don't find any solution , for calling my other class in diffrent directory in the pervious code has method main, if you have the solution about it please help me.
Re: How to run automatically generated java file has a method main in Xtext generator ? [message #1755625 is a reply to message #1755622] Mon, 06 March 2017 11:33 Go to previous message
Christian Dietrich is currently offline Christian DietrichFriend
Messages: 14730
Registered: July 2009
Senior Member
i still dont understand what your problem is. please how your code

Twitter : @chrdietrich
Blog : https://www.dietrich-it.de
Day Job: https://www.everest-systems.com
Previous Topic:After Update to 2.11: Encoding Problem
Next Topic:A slot with name 'uml-gen' has not been configured exception
Goto Forum:
  


Current Time: Tue Nov 12 06:06:28 GMT 2024

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

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

Back to the top