No, it is not that easy. Your Groovy class is probably in a text file - the JVM on the other hand requires a class file in the classpath. Part of what the Groovy runtime does is automatically convert Groovy source files into Java class files and add them into the classpath. So what you have to do is convince the Groovy runtime to do that for you within you Java app so that you can call the Groovy class.
You could try running your Java app with the groovy.bat or groovy.sh script. Or look into those scripts to see what options they are passing to the java command line and add those same options to your java command line.
I just tried to run my java program (which calls my groovy script) inside the groovy console and it did not like it.
I even tried to rename my java program to myprogram.groovy and I got the same problem.
all I am trying to do is use the very nice groovy XML MarkupBuilder to produce a XML file based on the data that I get from running MyProgram.java
So myprogram.java is parsing a txt file and placing the data I need into an ArrayList<JavaBeans>. I then want to take that data out of the arraylist and
create a XML file using groovys MarkupBuilder.
"So myprogram.java is parsing a txt file and placing the data I need into an ArrayList<JavaBeans>. I then want to take that data out of the arraylist and
create a XML file using groovys MarkupBuilder."
Why not do the file parsing in Groovy? It's very well suited for that.
A good workman is known by his tools.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 32767
posted
0
Groovy supports both of the major Java scripting engines - the javax.script package (available in Java 6) and Apache BSF. Either of those can provide smooth Java/Groovy integration.
I just tried to run my java program (which calls my groovy script) inside the groovy console and it did not like it.
I even tried to rename my java program to myprogram.groovy and I got the same problem.
What error message are you seeing? What is the class name? myprogram or MyProgram or some other spelling? (See http://faq.javaranch.com/java/ShowSomeEffort, especially the section on casing.) Does the class have a package? If so, did you use the full class name, including the package name, in the Groovy console?