The groovy eclipse tutorial launches off in the direction of making a class.
If I just want to make a script, what do I do? Just make a file in some folder that is named 'something.groovy' and expect eclipse to be willing to run it?
In the new Groovy Class Wizard, there is a checkbox to create a script instead of a class:
Alternatively, you can create a regular class and delete all the contents except for the package statement. That is a script.
A couple of points, though. The script should be in a source folder with a proper package statement if not in the default package. If not, you will not have any editing support for your script.
I'm not familiar with the groovy plugin for eclipse but there should be no problem creating a simple groovy script and running it from Command line or from Eclipse.
Save the following as hello.groovy somewhere:
System.out.println("Hello Groovy");
Create a Java run configuration it with the groovy jar in the classpath and main method is in groovy.lang.GroovyShell. Pass the script name as an argument (You can use ${resource_loc}) to make it a generic run configuration and it will work fine.
Edit: You can also find instructions on running groovy scripts on the Groovy website
Related
I have a selenium project in eclipse that i want to distribute to manual testers with no Eclipse or Java knowledge. Hence i am looking to distribute it to them as executable files so that they dont need to use eclipse to run them. Can any one suggest the best way to do this without having to install any 3rd party extensions?
P.S : My organisation doesnt allow me to install 3rd party extensions on Eclipse. It will require a lot of approvals. Hence i am wondering if there is any method available inside Eclipse itself?
I've done it some years ago, in my eclipse version:
file -> export -> java -> Runnable jar file
If you want an exe file you can use: Launch4J
Export your project as jar file and create a .bat file which will include all the necessary libraries in your classpath with your project and then make a call to the underlying script (in case if you are using testng then testng has option to make command line calls)
else use Maven
EDIT:
Something on below lines:
1. Create run.bat file
2. Content of the bat file:
JAVA_HOME={Path to your JDK}
CLASSPATH=%PATH%;{All the dependent jar files of your project as well as you project}
{Call to your Junit Script from command line} Something like this Run JUnit from command line
3. Run your batch file (run.bat)
I may not have provided the exact code but thats where you should be heading if you wish to run your JUnit tests from command line.
NOTE / FYI : Maven does not require any installation or approval..You just download the zip and unzip it and set environment variable and thats it.
This question is not limited to lex and yacc, but how can I add a custom script compiler as part of a project? For example, I have the following files in the project:
grammar.y
grammar.l
test.script
The binary 'script_compiler' will be generated using grammar.y and grammar.l compiled by lex, yacc and g++. And then I want to use that generated script_compiler to compile test.script to generate CompiledScript.java. This file should be compiled along with the rest of the java files in the project. This setting is possible with XCode or make, but is it also possible with Eclipse alone? If not, how about together with Maven plugin?
(I might setup the script compiler as a separate project, but it would be nice if they can be put in the same project so that changes to the grammar files can be applied immediately)
Thanks in advance for your help!
You can add a custom "Builder" from the project properties dialog. This can be an ant script (with an optional target) or any other script or executable.
There are also maven plugins for ant and other scripting languages
If you just want to run an external program in Maven this is what you want: http://mojo.codehaus.org/exec-maven-plugin/ -- you can then run Maven targets from your IDE or command line and it should do the right thing either way.
To integrate with the normal compilation bind the plugin to the "generate-sources" phase and add the location where the Java files are generated to the "sourceRoot" option of the exec plugin. That way the compiler will pick them up.
Ideally you generate the code into a folder "target/generated-sources/MY_SCRIPT_NAME". That is the standard location for generated sources in the Maven world and e.g. IntelliJ IDEA will pick up source files inside of that location. Note that this doesn't work if the files are directly in "target/generated-sources".
The other option is to write your own Maven plugin, which is actually quite easy as well. See e.g. https://github.com/peterbecker/maven-code-generator
I'm playing around with ActiveJDBC and it has a post-compile step for 'instrumentation' (i.e. crudely speaking it post-process byte-code to add the parent's static members to the class as per the ActiveRecord pattern).
You constantly have to run the following command:
java -cp=$CLASSPATH -DoutputDirectory=build activejdbc.instrumentation.Main
for the post processing to take place. Is there some way to integrate this with Eclipse (Helios) so that the whenever it builds the project it triggers the above? Anyway to automate it?
I do not use Maven/Ant and do not wish to learn it just for the sake of ActiveJDBC (Maven is its only dependency, which I find is a bit annoying).
The above could be done by encapsulating it in a java file and running that file - so if there is a way to run a java file after build that'll be fine too :)
Any ideas?
If you do not want to use Ant, then you can configure a second builder in Eclipse:
Project -> Properties -> Builders -> New
Then you can configure to execute a shell script or a batch file with that command. Once you have that builder configured (took 5 minutes for me), you can build entire project pressing Ctrl+B, which will execute the standard builder as well as your script.
However, I'd suggest that you copy this Ant script: http://code.google.com/p/activejdbc/wiki/Instrumentation#Bare_bones_Ant_script
And simply configure it for your environment. E-Riz correctly stated info about the builders, but you do not need to take an hour to write an Ant script if you are going to go this route. Configuring a new builder with Ant script instead of a shell is even simpler.
I wrote about adding custom builders a few years ago: http://bewarethepenguin.blogspot.com/2008/08/customizing-builds-for-your-eclipse.html
One of the options when creating a new builder is to run any arbitrary program. I don't see why you couldn't run the ActiveJDBC java command above.
Even if that doesn't work for some reason, you could probably write an Ant script to invoke that Java class in less than an hour, including learning and testing, using Ant's "java" task: http://ant.apache.org/manual/Tasks/java.html
I have a project in eclipse I would like to run a perl script before every build on eclipse
but I want to pass the perl script parameters, in detail I want to pass it the names/paths of all the files in the project
(this script add things to make makefile)
Thank you
As a general direction: You would use building systems like Ant or Maven to realise this in Eclipse.
For Ant: http://ant.apache.org/faq.html#shell-redirect-2
I have a project in eclipse right now that is compiled using ant. I am wondering what eclipse is doing behind the curtains whenever I double click on the jar target of one of this build files.
Is it possible to get the commands that eclipse is executing with ant, as I'd like to setup a shell script that compiles the project. How can I find what commands it is actually executing and what parameters it is passing.
I imagine there are also some variables like classpath, and buildpath that are set, where do I find them as to be easily copied over.
Eclipse comes with its own installation of ant. Is it possible to use that bundled installation of ant to build via command line.
Any help appreciated,
Ted.
One possible way is to look at the process executed by Eclipse when building.
For that, use Process Explorer (if you are on Windows) in order to display the full command line and all its parameter when running that build.