How can I execute a script inside an Eclipse Plugin? - eclipse

I have one lib/ folder inside my Eclipse Plugin Project and on this folder I have a little script... But when I run the 'Eclipse Plugin Project' I cannot execute that script because I cannot access to that folder...
How can I fix this?
--
Thanks in advance

If you can execute the script by passing an InputStream or a String to the interpreter, put in the src/ folder, so it ends up on the classpath and use getClass().getClassLoader().getResourceAsStream("script-name") to get an InputStream
If the interpreter is external (like bash or something that doesn't implement the Java Scripting API), do the same. When you need to execute the script, create a stream and copy the script to a temporary file.
Keeping the script in lib/ is also a bad idea since the plugin will be assembled into a single JAR file unless you turn that off, so you will end up with a script file inside of a JAR - again something which most interpreters can't use.
By using the classpath, you can let Eclipse figure out where the data is.

Related

Best method to export the Eclipse project as exe file

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.

Where to put files I want to load with my program in SBT?

In SBT where do I put files I want to load into my program? I know I can use the /test/ directory, but the problem is I have no idea in what context sbt is executing my scala program. From where does it execute so I know how to write a directory string to grab it?
Place them under src/main/resources or src/test/resources as described in Directory structure

groovy eclipse and scripts that aren't classes

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

Add raw .groovy file to output dir in Eclipse with Groovy Plugin

I'm using Eclipse and I have the Groovy Plugin installed.
From within a standard Java project I want to include a file with a .groovy extension on the runtime classpath. I have a source folder (src/main/resources) which includes all files and has no exclusion filters. Inside that directory I have 2 files: foo.groovy and foo.txt. When I clean and rebuild the project from eclipse and look in the output directory I see foo.txt, but foo.groovy is nowhere to be found.
Does anyone know if it's possible to have Eclipse treat a file with a .groovy extension like any other resource file while still having the Groovy plugin installed and having other Groovy projects in the same workspace?
In case you are wondering, I'm trying to get logback configured using a groovy script. If there's some other way to accomplish this please let me know.
There is a new feature in Groovy-Eclipse 2.1.0 that allows you to specify script folders. These folders contain groovy files that are not compiled and are optionally copied to the output folder. src/main/resources is a script folder by default.
To enable this, install 2.1.0 (or later) and go to preferences -> Groovy -> compiler.
I ran into the same thing a few years ago. The Groovy plugin treats .groovy files as source files. The same way a .java files do not get put into the output directory, neither do .groovy files. At the time I could not find a way around this. I don't know if there is a way around it but I did come up with a workaround.
I used the extension .g for groovy files that I wanted to keep as scripts and have them interpreted at runtime. These would be skipped by the groovy compiler and would end up in the output directory. Also doing things this way allows you to mix compiled groovy (.groovy) and runtime interpreted groovy files (.g).
** EDIT **
See comment from #Andrew Eisenberg. This answer was correct when this question was originally asked. His answer is correct going forward since there is a new version of the eclipse plugin.

In a Netbeans java project: How can I copy misc. data files into build directory

After a build of a java applet I would like to copy a file, or files from $PROJECT_DIR\data into the build directory. Can I do this easily somehow by marking the files in some way, or must I write an ant copy statement?
Ant build.xml is the way to go, IMO.