Search Results

Search found 595 results on 24 pages for 'groovy'.

Page 2/24 | < Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >

  • how to return value from groovy to java

    - by Sid
    Hi I am very new to groovy and having trouble with some parts. I have a jsp page tied to a servlet that runs groovy scripts. I am able to get to the groovy script from the servlet. But after the script runs how do I return the response from the groovy script back to the servlet to be displayed in the jsp page? My java servlet code is as follows: File file = new File("TestScript.groovy"); ClassLoader parent = getClass().getClassLoader(); GroovyClassLoader loader = new GroovyClassLoader(parent); Class groovyClass = loader.parseClass(file); Object[] args = {}; GroovyObject groovyObject = (GroovyObject) groovyClass.newInstance(); groovyObject.invokeMethod("runTest", args);

    Read the article

  • reading excel using scriptom for groovy, producing xml

    - by john
    Dear friends, I got a program from http://kousenit.wordpress.com/2007/03/27/groovyness-with-excel-and-xml but I got some very strange results: 1) I can still print xml but two records are not readable. 2) I got exception suggesting some thing missing could some experts enlighten me about what might go wrong? I copied the program and result below. thanks! import org.codehaus.groovy.scriptom.ActiveXObject def addresses = new File('addresses1.xls').canonicalPath def xls = new ActiveXObject('Excel.Application') def workbooks = xls.Workbooks def workbook = workbooks.Open(addresses) // select the active sheet def sheet = workbook.ActiveSheet sheet.Visible = true // get the XML builder ready def builder = new groovy.xml.MarkupBuilder() builder.people { for (row in 2..1000) { def ID = sheet.Range("A${row}").Value.value if (!ID) break // use the builder to write out each person person (id: ID) { name { firstName sheet.Range("B${row}").Value.value lastName sheet.Range("C${row}").Value.value } address { street sheet.Range("D${row}").Value.value city sheet.Range("E${row}").Value.value state sheet.Range("F${row}").Value.value zip sheet.Range("G${row}").Value.value } } } } // close the workbook without asking for saving the file workbook.Close(false, null, false) // quits excel xls.Quit() xls.release() however, i got the following results: <people> <person id='1234.0'> <name> <firstName>[C@128a25</firstName> <lastName>[C@5e45</lastName> </name> <address> <street>[C@179ef7c</street> <city>[C@12f95de</city> <state>[C@138b554</state> <zip>12345.0</zip> </address> </person> </person> Exception thrown May 12, 2010 4:07:15 AM org.codehaus.groovy.runtime.StackTraceUtils sanitize WARNING: Sanitizing stacktrace: java.lang.NullPointerException at org.codehaus.groovy.runtime.callsite.GetEffectivePojoFieldSite.acceptGetProperty(GetEffectivePojoFieldSite.java:43) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callGetProperty(AbstractCallSite.java:237) at sriptom4_excel$_run_closure1.doCall(sriptom4_excel.groovy:18) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [1]: http://kousenit.wordpress.com/2007/03/27/groovyness-with-excel-and-xml/

    Read the article

  • Are there compelling reasons not to use Groovy?

    - by Leonard H Martin
    I'm developing a LoB application in Java after a long absence from the platform (having spent the last 8 years or so entrenched in Fortran, C, a smidgin of C++ and latterly .Net). Java, the language, is not much changed from how I remember it. I like it's strengths and I can work around its weaknesses - the platform has grown and deciding upon the myriad of different frameworks which appear to do much the same thing as one another is a different story; but that can wait for another day - all-in-all I'm comfortable with Java. However, over the last couple of weeks I've become enamoured with Groovy, and purely from a selfish point of view: but not just because it makes development against the JVM a more succinct and entertaining (and, well, "groovy") proposition than Java (the language). What strikes me most about Groovy is its inherent maintainability. We all (I hope!) strive to write well documented, easy to understand code. However, sometimes the languages we use themselves defeat us. An example: in 2001 I wrote a library in C to translate EDIFACT EDI messages into ANSI X12 messages. This is not a particularly complicated process, if slightly involved, and I thought at the time I had documented the code properly - and I probably had - but some six years later when I revisited the project (and after becoming acclimatised to C#) I found myself lost in so much C boilerplate (mallocs, pointers, etc. etc.) that it took three days of thoughtful analysis before I finally understood what I'd been doing six years previously. This evening I've written about 2000 lines of Java (it is the day of rest, after all!). I've documented as best as I know how, but, but, of those 2000 lines of Java a significant proportion is Java boiler plate. This is where I see Groovy and other dynamic languages winning through - maintainability and later comprehension. Groovy lets you concentrate on your intent without getting bogged down on the platform specific implementation; it's almost, but not quite, self documenting. I see this as being a huge boon to me when I revisit my current project (which I'll port to Groovy asap) in several years time and to my successors who will inherit it and carry on the good work. So, are there any reasons not to use Groovy?

    Read the article

  • Advantages of Scala vs. Groovy with JAVA EE 6 Applications.

    - by JAVA EE Wannabe
    Please let me first emphasize that I am not looking for flare wars. I just want advices from people who have real experiences. I started learning JAVA EE 6 as real newbie and am having had time choosing what tools to use. First problem is what is the advantage of using Scala vs. Groovy with Java EE 6 apps over Java? I've seen on some blogs people mentioning you gonna write less code but as a newbie I don't know what other advantages and disadvantages are there. Second problem is Netbeans 6.9 or Helios 3.6.1? I realized that with eclipse I can easily mix EE 6 applications with Groovy or Scala without any problems (I only did this by displaying a String message from Scala and Groovy classes.). With Netbeans the only I can think of is having separate Java project libraries and using the jars in my web app. But also realize to the extent of my little knowledge Netbeans has better support for Java EE 6. Please need your expert advice. Thanks.

    Read the article

  • How to render or include files/data in bootstrap.groovy?

    - by skurt
    I want to use some parts of code in different area of bootstrap.groovy. How do I "include" these parts and reuse it? def init = { environments { production { include("bla.groovy) include("blaFoo.groovy) } test { include("blaFoo.groovy) } development { include("bla.groovy) include("bla1.groovy) include("blaFoo.groovy) } } }

    Read the article

  • Groovy Grapes in NetBeans IDE

    - by Geertjan
    The start of Groovy Grapes support in NetBeans IDE. Below you see a pure Groovy project, with the Groovy JAR and the Ivy JAR automatically on its classpath. There's also a Groovy script that makes use of a @Grab annotation. In the bottom left, in the Services window, you also see a Grape Repository browser, i.e., showing you the JARs that are currently in ".groovy/grapes". Click the images below to get a better look at them. Next, you see what happens when the project is run. The @Grab annotation automatically starts downloading the JARs that are needed and puts them into the ".groovy/grapes" folder. However, the "no suitable classloader found for grab" error message (which Google shows is a problem for lots of developers) prevents the application from running successfully: The final screenshot shows that I've put the JARs that I need onto the classpath of the project. I did that manually, hoping to learn from the NetBeans Maven project or the NetBeans Gradle project how to do that automatically. Also note that the @Grab annotation has been commented out. Now the error message about the classloader is avoided and the project runs. What needs to happen for Groovy Grapes support to be complete in NetBeans IDE: Figure out how to add the downloaded JARs to the project classpath automatically. Fix the refresh problem in the Grape Repository browser, i.e., right now the refresh doesn't happen automatically yet. Hopefully find a way to get around the grab classloader problem, i.e., it's not ideal that one needs to comment out the annotation. Let the user specify a different Grape repository, i.e., right now ".groovy/grapes" is assumed, but the user should be able to point the repository browser to something different. Maybe there should be support for multiple Grape repositories? Comments/feedback/help is welcome.

    Read the article

  • how to run existing ant script from groovy

    - by Omnipresent
    my build is a 3 step process. run ant to build. transfer war to server. touch reload file. I have transfered last two steps in groovy, using antbuilder. However, I am not able to run my existing ant script using groovy. Usually I run it using the following command in dos prompt: ant -Dsystem=mysystem -DsomeotherOption=true from groovy when I try to do "ant -Dsystem=mysystem -DsomeotherOption=true".execute() it gives an error saying ant is not a recognized command. How can I utilize my existing ant script in groovy?

    Read the article

  • Using Groovy as a scripting language...

    - by Zombies
    I prefer to use scripting languages for short tasks, anything such as a really simple http bot, bulk importing/exporting data to/from somewhere, etc etc... Basic throw-away scripts and simple stuff. The point being, that a scripting language is just an efficient tool to write quick programs with. As for my understanding of Groovy at this point... If you were to program in Groovy, and you wan't to write a quick script, wouldn't you be forced to going back to regular java syntax (and we know how that can be convoluted compared to a scripting language) in order to do anything more complicated? For example, if I want to do some http scripting, wouldn't I just be right back at using java syntax to invoke Commons HttpClient? To me, the point of a scripting language is for quickly typed and less forced constructs. And here is another thing, it doesn't seem that there is any incentive for groovy based libraries to be developed when there are already so many good java one's out there, thus making groovy appear to be a Java dependent language with minor scripting features. So right now I am wondering if I could switch to Groovy as a scripting language or continue to use a more common scripting language such as Perl, Python or Ruby.

    Read the article

  • Run groovy script from within gradle

    - by macattack
    What's the best way to create a gradle task, which runs a groovy script? I realize that gradle build files are groovy, so I would think it would be possible to do something like this: task run << { Script app = new GroovyShell().parse(new File("examples/foo.groovy")) // or replace .parse() w/ a .evalulate()? app.run() } I get all kinds of whacky errors when I try this if bar.groovy is using @Grab annotations or even doing simple imports. I want to create a gradle task to handle this, so that I can hopefully reuse the classpath definition. Would it be better to move the examples directory into the src directory somewhere? What's a best practice?

    Read the article

  • Grails: Services VS Groovy classes

    - by Olexandr
    Documentation says: The Grails team discourages the embedding of core application logic inside controllers, as it does not promote re-use and a clean separation of concerns. I have one API controller and a few Groovy classes in src/groovy folder. Those classes just implements my application logic so actions in API controller works in this way: //index page def index = { render new IndexApi().index(params) as JSON } I'm curious - is there any reason to move my application logic from plain groovy classes into services ?

    Read the article

  • groovy regexpression

    - by srinath
    Hi, How to get file name from these lines using groovy . File file = new File(SOURCE_FILE_NAME).eachLine{line- println line } getting line like this : /usr/local/testing.groovy /usr/local/picture.jpg expecting output: testing.groovy picture.jpg Can any one help me using any if regex needed . thanks

    Read the article

  • groovy: how to replaceAll ')' with ' '

    - by user311884
    i tried this: def str1="good stuff 1)" def str2 = str1.replaceAll('\)',' ') but i got this: Exception org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed, Script11.groovy: 3: unexpected char: '\' @ line 3, column 29. 1 error at org.codehaus.groovy.control.ErrorCollector(failIfErrors:296) question: how to do this: str1.replaceAll(')',' ')

    Read the article

  • Clean Stack Traces in Groovy using Eclipse?

    - by yar
    I am using Groovy in a Java Swing application as part of my plan to force-feed myself dynamic languages until I like them (which is happening, partly). My stack traces are filled with Groovy stuff like org.codehaus.groovy.runtime.callsite.ConstructorSite$ConstructorSiteNoUnwrapNoCoerce.callConstructor is there a way to get Eclipse to remove all of that codehaus stuff (filter stack traces, basically)? Edit: I can do this from the command-line with grep (well, not yet) so it's not so bad, but inside of Eclipse would be great too.

    Read the article

  • Running a groovy script created in STS(Spring Tool Suite) using the command line

    - by user1811107
    I have used the STS(Spring Tool Suite) to create a compiled groovy script which exists as a file on windows called Test.class. I am able to right click on the file in STS and execute it which works well. However - I want to be able to execute the script on the windows command line, so far I have tried various ways but have not been successful. I have tried the following... java -cp C:\Users\MyName\springsource\sts- 3.1.0.RELEASE\plugins\org.codehaus.grails.bundle_2.1.1\content\lib\ org.codehaus.groovy\groovy-all\jars\groovy-all-1.8.8.jar Test.class But that does not work it gives me an error -- Error: Could not find or load main class Test.class Any Pointers?

    Read the article

  • When to write an explicit return statement in Groovy?

    - by Roland Schneider
    At the moment I am working on a Groovy/Grails project (which I'm quite new in) and I wonder whether it is good practice to omit the return keyword in Groovy methods. As far as I know you have to explicitly insert the keyword i.e. for guard clauses, so should one use it also everywhere else? In my opinion the additional return keyword increases readability. Or is it something you just have to get used to? What is your experience with that topic? Some examples: def foo(boolean bar) { // Not consistent if (bar) { return positiveBar() } negativeBar() } def foo2() { // Special Grails example def entitiy = new Entity(foo: 'Foo', bar: 'Bar') entity.save flush: true // Looks strange to me this way entity }

    Read the article

  • Groovy Debugging

    - by Vijay Allen Raj
    Groovy Debugging - An Overview:ADF BC developers may express snippets of business logic (like the following) as embedded groovy expressions: default / calculated attribute valuesvalidation rules / conditionserror message tokensLOV input values (VO) This approach has the advantages that: Groovy has a compact, EL-like syntax for expressing simple logicADF has extended this syntax to provide useful built-insembedded Groovy expressions are customizableGroovy debugging support helps improve maintainability of business logic expressed in Groovy.Following is an example how groovy debugging works.Example:This example shows how a script expression validator can be created and the groovy script debugged. It shows Step over, breakpoint functionalities as well as syntax coloring.Let us create a ADFBC application based on Emp and Dept tables, and add a script expression validator based on the script:  if (Sal >= 5000){ //If EmpSal is greater than a property value set on the custom //properties on the root AM //raise a custom exception else raise a custom warning if (Sal >= source.DBTransaction.rootApplicationModule.propertiesMap.salHigh) { adf.error.raise("ExcGreaterThanApplicationLimit"); } else { adf.error.warn("WarnGreaterThan5000"); } } else if (EmpSal <= 1000) { adf.error.raise("ExcTooLow"); }return true;In the Emp.xml Flat editor, place breakpoints at various locations as shown below:Right click the appmodule and click Debug. Enter a value greater than 5000 and click next. You can see the debugging work as shown below:  The code can be also be stepped over and debugged.

    Read the article

  • Groovy Prototype Object

    - by Holden
    I have a method with an incoming variable, which represents a script. e.g. hello.groovy Foo.init(this) Foo.groovy class Foo { static init(app) { } } What is the best way to add a ton of new functionality to the app variable in the init method? Basically, I would like to add all the functionality of another object to the app object. For instance, if I had another class: class Bar { def a() { } def b() { } } I would like the app object to basically be a new Bar(). In JavaScript, this is easy by using the prototype object, but I cannot seem to get it working in groovy. What is the best way to accomplish this? Or should I be doing something differently?

    Read the article

  • Groovy MarkupBuilder causing java.lang.NoClassDefFoundError on closure in soapUI

    - by Eric
    I am not able to get the Groovy MarkupBuilder to work with soapUI. I am very new to Groovy and I am just following one of the user guides on creating XML. Testing a very simple method: public String Example(){ def writer = new StringWriter() def root = new MarkupBuilder(writer) root.mkp.xmlDeclaration(version:"1.0", encoding:"UTF-8") root.Root{ Example("A") } return writer.toString() } I get the following error in soapUI: ava.lang.NoClassDefFoundError: MockXML$_Example_closure2 I have no error when I run from Groovy Console. In the same class I have: public String Hello(){ return "Hello" } Which works fine in soapUI. Is there something I would need setup/imported/configured in soapUI that I am not thinking about to handle MarkupBuilder/closures? Thanks

    Read the article

  • Simple ranking algorithm in Groovy

    - by Richard Paul
    I have a short groovy algorithm for assigning rankings to food based on their rating. This can be run in the groovy console. The code works perfectly, but I'm wondering if there is a more Groovy or functional way of writing the code. Thinking it would be nice to get rid of the previousItem and rank local variables if possible. def food = [ [name:'Chocolate Brownie',rating:5.5, rank:null], [name:'Pizza',rating:3.4, rank:null], [name:'Icecream', rating:2.1, rank:null], [name:'Fudge', rating:2.1, rank:null], [name:'Cabbage', rating:1.4, rank:null]] food.sort { -it.rating } def previousItem = food[0] def rank = 1 previousItem.rank = rank food.each { item -> if (item.rating == previousItem.rating) { item.rank = previousItem.rank } else { item.rank = rank } previousItem = item rank++ } assert food[0].rank == 1 assert food[1].rank == 2 assert food[2].rank == 3 assert food[3].rank == 3 // Note same rating = same rank assert food[4].rank == 5 // Note, 4 skipped as we have two at rank 3 Suggestions?

    Read the article

  • Bind a java class as a closure into a groovy-script

    - by chrsk
    Is it possible to bind a closure written in java into a groovy-script. Is there an interface or something to implement so i can provide a closure? Something like this? public class Example implements Closure { public void closure(Object... args) { System.out.println(args[0]); } } Bind this into the groovyscript. Binding binding = new Binding(); binding.put("example", new Example()); groovyScriptEngine.run("foo.groovy", binding) and use it in the foo.groovy like this: example("Hello World")

    Read the article

  • Netbeans 6.8 groovy files in src/main/java

    - by Jeff Storey
    I have a new netbeans maven/groovy project, and I actually prefer to mix my java and groovy files in src/main/java and src/test/java (I find it easier to navigate this way and my pom reflects this configuration). However, when I have my project setup this way in Netbeans 6.8, it always shows the generated-sources folder in error. The stubs generated from groovy files in src/test/java can't be opened by netbeans and given an error that they can't be parsed. However, in windows explorer the files are in tact. Netbeans can run the project but it continues to prompt me that some files are in error (even though I know they're not). It's like netbeans isn't refreshing itself. Any thoughts on how to fix this? thanks, Jeff

    Read the article

  • Groovy: stub typed reference

    - by Don
    Hi, I have a Groovy class similar to class MyClass { Foo foo } Under certain circumstances I don't want to initialize foo and want to stub out all the calls to it. Any methods that return a value should do nothing. I could do it like this: Foo.metaClass.method1 = {param -> } Foo.metaClass.method2 = { -> } Foo.metaClass.method3 = {param1, param2 -> } While this will work, it has a couple of problems Tedious and long-winded, particularly if Foo has a lot of methods This will stub out calls to any instance of Foo (not just foo) Although Groovy provides a StubFor class, if I do this: this.foo = new groovy.mock.interceptor.StubFor(Foo) I get a ClassCastException at runtime. Although this would work if I could redefine foo as: def foo But for reasons I won't go into here, I can't do that. Thanks, Don

    Read the article

  • how to use execute() in groovy to run any command

    - by drake
    I usually build my project using these two commands from command line (dos) G:\> cd c: C:\> cd c:\my\directory\where\ant\exists C:\my\directory\where\ant\exists> ant -Mysystem ... ..... build successful What If I want to do the above from groovy instead? groovy has execute() method but following does not work for me: def cd_command = "cd c:" def proc = cd_command.execute() proc.waitFor() it gives error: Caught: java.io.IOException: Cannot run program "cd": CreateProcess error=2, The system cannot find the file specified at ant_groovy.run(ant_groovy.groovy:2)

    Read the article

  • Scoping in embedded groovy scripts

    - by Aaron Digulla
    In my app, I use Groovy as a scripting language. To make things easier for my customers, I have a global scope where I define helper classes and constants. Currently, I need to run the script (which builds the global scope) every time a user script is executed: context = setupGroovy(); runScript( context, "global.groovy" ); // Can I avoid doing this step every time? runScript( context, "user.groovy" ); Is there a way to setup this global scope once and just tell the embedded script interpreter: "Look here if you can't find a variable"? That way, I could run the global script once. Note: Security is not an issue here but if you know a way to make sure the user can't modify the global scope, that's an additional plus.

    Read the article

  • Call javascript function from Java (Groovy) class

    - by ashkanr
    Hi, I have a javascript function (very big one!) that I need its functionality in a Java (Groovy) class. It is a simple calendar converter. I can rewrite it in groovy but just want to know if it is possible to call javascript function from a java (groovy) method? I guess functional testing libraries like selenium and Canoo should have something like this, am I right? PS: I don't want to wake up a real-world browser in order to use its JS runtime env. Thanks,

    Read the article

< Previous Page | 1 2 3 4 5 6 7 8 9 10 11 12  | Next Page >