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
Related
I'm trying to use zeep library to provide soap call in python code and its okay it works when I try to run with python. Then, I'm trying to use jython to run this code (i need jython because next step will be on the server that uses jython to compile) and when I try to install lxml for jython it gives me this error:
error:Compiling extensions is not supported on Jython
When I search for this situation, I found that jython doesn't support c based libraries.
So, there is a solution with jython-jni bridge but I couldn't understand how to be.
Is there another solution? Or can you give me an obvious example?
I couldn't achieve to implement jni but i created a new layer between jython and server.I mean, i made a REST call from jython compiler and this call listens my server for soap call and it worked.
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.
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.
Can I compile Dart to Javascript from a Java Virtual Machine based application?
I'm developing a web application that runs in the JVM. I'm thinking about allowing people to save and compile Dart via my web application, and then that compiled Dart code would be included on certain pages, as Javascript.
I suppose in theory the answer is yes, because it should be possible to somehow bundle the Dart editor or the dart2js program in my JVM application, and make an external process call to Dart. But I'm wondering: Is there any "easy" way to compile Dart, from Java? Like including some JAR and then it'll work? Or calling out to some scripting language via the JVM's script engine?
https://code.google.com/p/jdart/
Is this what you want? It compiles dart into a jar file. I haven't actually used it yet though...
Can a scala program be running on a browser with disabled java plugin (as scala is compiled to a jvm bytecode)? In other words: is the jvm disabled provided the java browser plugin is disabled?
Or does Scala run server-side and I am confused?
If I estimate it correctly, you can have both: Server-side and Client-side.
In case you want to use it on the server, it's called a Servlet and compiled to a JSP-application.
In case you want to use it on the client, it's an Applet and runs in the JVM. And that's what the user disables in his browser-settings.
As far as I know it, java and scala compiles to the same type of bytecode which is executed by the JVM.
Therefore, you cannot use neither Scala nor Java if the user has the plugin disabled. The browser cannot distinguish between these two.
The only java program which "runs in a browser" is an applet; any class extending java.applet.Applet will serve this purpose. As a scala class can extend a java one, it is therefore perfectly possible to write an applet in scala.
However, this cannot run if java is disabled in the browser as scala runs on the Java Virtual Machine. (In fact, there's no difference between a compiled scala program and a compiled Java program - they are both bytecode, which is run on a JVM)
Applets are not particularly common however, and most scala code will be server-side in practice. When you see people talking about scala and the web, they are most probably talking about Lift, which is a (server-side) web-framework for Scala.
Scala is almost always run on the server or as a normal desktop "java" application.
I suppose it would work perfectly well as an applet, if it doesn't add any confusion to the security model, but if applets are disabled I presume you can't run any JVM code at all.
Regarding Lift, the server side runs Scala, but the client side runs automatically generated Javascript, which does not need the jvm.