Ruby compass compiler using java - java

I am using compass compiler inside my java application. Basically, I am executing Process to launch compass.
The question is... Is it possible to use some tool/framework like JRuby to execute compass compiler task without installing any dependencies(Ruby) on my environment?

You can execute a command in ruby (and therefore JRuby) using backticks, for example:
puts `compass version`

Related

CPython 2.7 + Java

My major program is written in Python 2.7 (on Mac) and need to leverage some function which is written in a Java 1.8, I think CPython cannot import Java library directly (different than Jython)?
If there is no solution to call Java from CPython, could I integrate in this way -- wrap the Java function into a Java command line application, Python 2.7 call this Java application (e.g. using os.system) by passing command line parameter as inputs, and retrieve its console output?
regards,
Lin
If you have lot of dependcieis on Java/JVM, you can consider using Jython.
If you would like to develop a scalable/maintainable application, consider using microservices and keep Java and Python components separate.
If your call to Java is simple and it is easy to capture the output and failure, you can go ahead with this running the system command to invoke Java parts.
A number of open source projects have been written to enable calling Java from CPython, depending on your needs.
Pyjnius
Py4J
JPype forked (original JPype hasn't been updated in years)
jpy

How to create java interface for existing ruby project

my project has a significant and isolated part that was written in ruby(jruby compatible). It is a commandline application that we run it in the terminal and provide it with various option flags.
My client wants to use this tool but only willing to use it if it is wrapped in a java class. I went through a lot of trouble to convert the ruby code to java by using jrubyc --javac A.rb. Inspecting the converted .java file, it is calling a Ruby Runtime to execute the ruby script. Like this:
org.jruby.Ruby.getGlobalRuntime().executeScript(stringBuiltFromARubyFile, 'path')
My question is performance wise, is this better than just wrap the create a runnable jar, wrap it with a java class that takes certain parameters, and execute the jar via Runtime.getRuntime().exec("java -jar A.jar args") ?
The application A.rb uses multi-threading. I bring in ruby dependencies (gems) using jruby-gradle plugin.
What are some other options I can explore?
Thanks in advance.
The approach you are using likely won't work. You are launching a JVM within a ruby context; and what you've been asked for is launching some of your ruby code within a JVM context.
I would look at C to Ruby bindings, and then use a Java to C (JNI) interface to launch the required Ruby code from the C layer. If such a thing is not practical, as your Ruby is more of a standing service than a CLI process, I would then consider making a set of Java libraries to call the process through a network call.

do you need jython for calling a python script from java?

I have seen in answered here that if you want to call a python script from java, you can use jython as a option.
But have seen other answers as well saying, you can use Process or ProcessBuilder and call their exec or start methods to run the python script.
As I understand jython allows you to program python in you java code, but it allows you to call python scripts as well via, PythonInterpreter.execfile.
So I'm wondering what are my options if I want to call a python script (e.g. text processing script which uses nltk) from my java code and along with some arguments and return the results back to my java programme? which option should I use?
Jython is an implementation of the Python language for the Java platform
(source)
You can simply use ProcessBuilder if there is a regular python script on a machine that has regular python installed. This saves you from having to include a whole python runtime in your java application. You can pass parameters quite easily, the returned text is a little trickier: See http://examples.javacodegeeks.com/core-java/lang/processbuilder/java-lang-processbuilder-example/ or other examples. Basically anything that the python program prints can be captured that way.
However if you don't like external dependencies and prefer shipping everything in a single application you can try jython. It has some limitations though since it doesn't come with all those modules and it seems it may have difficulties with C modules. Getting Python's nltk.wordnet module working for Jython looks like an explanation on how to get nltk to run with it. Arguments and return values should be simpler with jython since the integration is better. And if you want more than just printed text, Jython can even call into java code directly from python. That would give you interesting options for hybrid code.

Run TypeScript compiler from Java

I am trying to run the TypeScript compiler from my Java application. To start, I am trying to figure out, whether I can run the compiler from command-line without Node.js:
$ jsc tsc.js
But this way I don't get any errors, nor help.
$ jsc tsc.js myscript.ts
Will get me nowhere.
It is easy to run js code directly from java (and I am hoping to run the compiler in this way), but is it possible to run TypeScript compiler without node.js?
EDIT:
I confirm the same behaviour with rhino.
I have a project, Typescript4j that does precisely this.
It runs the Typescript compiler wrapped within Rhino.
I'm using it successfully within Bakehouse, and a non-trivial Typescript application.
Looking at the source code, the tsc command invokes a JS script tsc.js, which has 2 backends: Node.js and Windows Scripting Host. If any other JavaScript server supports reading and writing to a file system (like Rhino with RingoJS), it should be able to run the TypeScript compiler tsc.js.
Moreover, there is a fork of TypeScript compiler which claims to directly run on Rhino. So you could invoke Rhino directly from Java, without installing node.js.
what you want to do is jsc node_modules/typescript/lib/tsc.js file1.ts, but unfortunately that won't work with engines different than node.js.
What will work (or at least works in the browser), is using TypeScript Compiler API, instead of trying to use the CLI (you will have to program). In the browser, you do this by loading the file node_modules/typescript/typescript.js and then you have access to the compiler API (https://github.com/Microsoft/TypeScript/wiki/Using-the-Compiler-API) via the global ts. Here you have an example of how to transpile a ts string to js using the compiler API: https://typescript-api-playground.glitch.me/#example=Transpiling-a-single-file
Good luck
The TypeScript compiler is implemented in TypeScript, and can be used in any JavaScript host.
You may need to specify the full path to tsc.js

Launch Clojure REPL from java swing

How to Launch REPL using java Swing application. As shown in Image. This REPL should be able to run all functions provided by Clojure Build-in libraray and other developed libraries by user. (provied as jar in classpath).
Point is, how to run Java clojure.jar clojure.main from swing so that it will show user defined Namespace. like myRepl=>
I'm not sure I understand your question exactly. Do you want to write such REPL or to just use it?
In any case, googling for "clojure swing repl" seems to show interesting results, one of which is: https://github.com/alandipert/clj-swingrepl
N.B. I haven't tested this.

Categories