Embed Groovy in an Android Java App - java

Basically, I need to run Groovy Scripts to manipulate Java objects, and GroovyShell / GroovyScriptEngine seems to be the best way to do so. Is it possible to embed Groovy inside a Java App? I tried placing the groovy-all-1.8.2.jar into my Android Java App's libs folder, referenced it then hit compile but I got a bunch of errors.
How do I do this?

I don't believe this will work. Groovy converts scripts to bytecode, and as the Dalvik bytecode is different to the Java bytecode that Groovy expects, I believe it will have problems...
The Discobot from a few years ago has been resurrected though, and great progress is being made so there is hope on the horizon.
But that doesn't help you today...

In near future it will be possible: http://skillsmatter.com/podcast/home/groovy-android/

I have found it recelty.
You can find the solution from http://melix.github.io/blog/2014/06/grooid.html.
Check it http://glaforge.appspot.com/article/groovy-2-3-3-and-groovy-2-4-beta-1-with-android-support too!

Since 09/2011, Discobot seems to be stuck. The last results seem to be : most of it works, but this is very slow.
Groovy 2.0 is out now, and Guillaume Laforge (insider) says it could helps - especially because of the #CompileStatic new feature of Groovy 2.0. Since then, Groovy 2.0.1...2.0.4, it looks that static compilation got a lot of bugfixes.
But for now, on the official website of Groovy, Android is not discussed, nobody seems to really be in charge (see wiki and wiki).

Here is an example of what you are trying to accomplish. https://github.com/melix/grooidshell-example
It is pretty slow since it has to first compile to class files on the android device and then convert them to dex, but it will accomplish what you are looking for.

A better choice for running scripts on Android is SnapScript. It does not rely on Bytecode and is fully supported on Android.

Related

Java API for Vowpal Wabbit?

I am trying to use Vowpal Wabbit through Java. I have downloaded and successfully compiled the code from GitHub. The command line tool works fine.
After having a quick look at the repository (especially here), I can only assume that using it through Java is supposed to be already possible, and I don't really want to reinvent the wheel.
A wrapper around Vowpal Wabbit that allows use through Java. This wrapper is designed to be self contained. Because
of the use of JNI, a number of platforms are supported in this JAR.
I have added the maven dependency (found here) to my project, but without any kind of document, I don't really know where to start.
I have seen in another question that it seems to be possible to use VW with Java, but the guy only uses Runtime.getRuntime.exec() to call his bash command, and I can't find any documentation about any other way of doing (and there are only 2 questions mixing VW and Java on SO, which doesn't help).
I am new to JNI, so most likely there is something easy that I don't see.
To be perfectly clear, my questions are :
Should I just make a valid vw command and use it through Runtime.getRuntime.exec()? This doesn't seem to be the spirit of JNI, for there is no need for any wrapper/library for this. Plus, this doesn't make it very portable.
Where (the hell) is the (Java API) documentation ?
Any kind of help or guidance would be welcome.
I was one of the two primary authors of the VW JNI wrapper. Since the posting of this question the interface has significantly changed. We now encourage users to compile the native side on their own and provide it on the java.library.path. We have updated the README significantly to show how to use the library from Java.
I totally agree with your criticism that we have not published the Java API. I will work on that the next time I modify this code. In the meantime please feel free to clone the library and run mvn install and you can generate the Java API docs yourself. They should be quite detailed as we spent a lot of effort writing detailed docs.
You may checkout vowpal wabbit JNI wrapper we've built in Indeed: https://github.com/indeedeng/vowpal-wabbit-java.
We wrote integration test that can work as usage examples and we wrote API documentation as well. Check "using the library" section of README.
Hope this will help.
I don't think this adds a lot, but none of the previous answers really provided a clear answer. Like #Macchiatow mentioned, to use the Java wrapper which comes with Vowpal Wabbit, you would:
(on the project root dir) make all java or make java
cd into java and verify the installation with mvn test
you'd then mvn install to have the Java API jarred up and placed in your local maven repository. Supposedly this builds the JNI parts on your machine, so as to fit the C/C++ libraries of your platform if you have the necessary native C/C++ libraries installed and available to the make command.
you'd supposedly be able to include the vowpal package/s from those jars in the build tool used in your own project (ant/maven/boot/leiningen/sbt/etc. as in here).
For more background maybe see the Vowpal Wabbit Java readme. I think what it tries to say there, is that if you want a ready made jar from maven central, you should make sure it's the same vowpal version you're using, but without knowing more I'd guess if you built it like above, you are by definition using the same version.
I've had the above process work off a fresh clone, with Ubuntu 16.04 and Java 8.
This link may be of some help with regards to setting up a JNI wrapper.
I wasn't able to find Java API documentation anywhere, but Java code seems well documented - did you maybe try generating Javadoc yourself from the code?
There is indeed Java JNI wrapper to have a basic access to VW. By basic I mean to teach your model and to predict probability later on. They also provide Python library that can do far more than wrapper for Java. Recently I was forced to expose few more VW methods to Java by extending code provided.
Back to the questions:
Rather use the vw-jni artifact available in central maven repo and clone their code and run make all java. I some cases compiling code yourself will be the only solution, as for example provided artifact won't run on OpenSuse (my case)
Code available pretty straight forward. VWLearners::create is a factory to get an instance of VW from Java.

Python for Android Apps

I've learnt python recently and I want to make an app for android. But everywhere on the net, it seems Java and Eclipse are the only ones that can be used.
So, my question is:
1) Can I use python to make an android app?
2) What kind of platform should I use to make an app with python?
Thanks guys!
If you're just looking to run Python scripts, try QPython.
If you're looking to make your Python code run like a native app, or just something more robust than the above, try SL4A.
If you're looking to effectively use Python as a library, and compile an .apk with the Python library included, try Kivy: github.com/kivy/python-for-android.
That said, you'd likely get a lot of benefit from learning Java, and not just for programming natively in Android (which would give you access to a much wider feature set and make your app run more efficiently).
Check out the Scripting Layer For Android, aka SL4A.
Here is a blog for getting started. The blog promises more entries in the series but there don't seem to be any. Still, it is a great starting point. There's quite a few parts to pull together so be patient and check the bottom of that blog entry for dozens of useful links.
If you want to contain everything to the Android device, including the IDE (pretty slick), check this out.
Here's a book from APress that could help with more advanced concepts: Pro Android Python with SL4A

JPen alternative for Java program

I want to develop a small Java program using some input like the pen of a Wacom graphictablet and found only the very active JPen project but are there some more possible alternatives without JNI or JNA (without any additional needed dll files), a pure Java implementation?
You can take a look at JTablet. From another SO thread.
It seems JPen moved to GitHub and this might be the best solution at the moment.
The other alternative solutions are not developed and maintained anymore.
https://github.com/nicarran/jpen

Building Ruby Documentation for Java Classes/Source

As I've recently started using JRuby, more specifically building Java applications using Ruby code, I've started using Java Libraries such as LWJGL and Slick.
I know JRuby changes Java method names to a more ruby-esque structure, my question is, is there any current way to generate Ruby documentation, either from source or by conversion of current documentation or even based on what JRuby exposes the methods themselves as?
At some point when JRuby 1.6.7 is out I plan on cleaning this really rough project for just such a thing:
https://github.com/enebo/noridoc
The intention is it will weave both Java and Ruby syntax together and give reasonable documentation for a Rubyist wanting to know all Ruby methods. In it's current form you should be able to generate a reasonable set of HTML docs of Java code showing you all ruby aliased methods. You will need to screw around with the javadoc comment.
Oh and we plan on making this tool available out of the box in JRuby once it is good enough to merge.

Is there something like ZenTest/Autotest for Java and JUnit

I've used ZenTest and autotest to work on Ruby projects before, and I used to using them for test-driven development a la this configuration. I have a project that I'm currently working on in Java, and I was wondering if there is something similar in the Java world to achieve the same effect.
Might I also suggest Infinitest, it is under active development and works with other languages besides Java. I believe it works fine with Scala, but I haven't had much luck using it with Groovy.
It is free for personal use and is being developed by Improving.
I use junit max which is a eclipse plugin written by kent beck
Although not a lot of people use autotest like tools in java, there is one (although not so mature).
A blog about it.
Autotest for java.
I used the tool and looks pretty cool for first release.. I would request him to come up with next version soon...
I was looking for something like this a couple of weeks ago when I had to start doing some java. I couldn't find anything anywhere (being new to java) and I don't use eclipse so I hacked this together and will hopefully make it more useful in the future when I find some time:
http://github.com/feydr/crappe

Categories