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...
Related
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
By using the JRE or some other runtime environment, is it possible to compile Java code on a web server such as Apache or Nginx?
Specifically, I would like to have a web application that would accept user input (Java code), and when the user hits run, it would compile the Java into Java Byte code and display the result, like Eclipse does.
Does this sort of technology even exist?
Does this defy the logic of compiled languages?
Thank you for your time in advance.
Amicably,
James
The server running Apache would also need a JDK. You could easily write the input to a file, compile it, run it, and display the results to the user. This could be done with a CGI script, or a Java EE app or similar, running in Tomcat. A JDK will be required, a JRE will not suffice.
Consider the potential security risk with this, though. Depending on what the program actually does, it could result in problems on your machine or others.
Of course this is possible. But you need a JDK, and some server side scripts (PHP, Ruby, Python, Java ...) which takes the source code as input and calls the Java compiler to compile the code.
What you have to consider are the security implications. Every user could then upload code, which would be executed on the server. So you have to make sure, that the code runs in a sandbox.
There are several websites that do this. One that I've used is at http://www.ideone.com.
You can reproduce this with the JDK and various scripts or you can write your own compiler from scratch. Either way, you need a compiler of some kind to actually compile the code.
For reasons I don't quite (yet) understand, there's some Java libraries/packages that just won't work correctly (or even run) when deployed to an Android device. Libraries like Guice or Apache Camel.
Not being an iOS, .NET or JavaScript developer, I don't know if iPhones, Windows Phones or Blackberries suffer the from same/similar problems.
Irregardless, we have at least 1 scenario (Java/Android) where PhoneGap is generating code for a target platform that may not be runnable on that platform. So I ask: does PhoneGap know each target platform well enough to not generate native code that won't run on it?
In other words, Apache Camel (for example) will not run on Android devices. What happens when I use GWT to compile a Camel route (with endpoints) down into JavaScript, and then use PhoneGap to wrap it and package an APK? Will PhoneGap say "hey, this is Camel stuff; you can't run on Android devices" and fail it or is there the possibility of leaking "un-runnable" code into PhoneGap apps?
As you pointed out yourself, GWT compiles your Java code to Javascript.
So phonegap only sees Javascript code, it will not be able to tell that this is compiled from Java (it does not contain any java source anymore). It will treat it as a normal web apps and it will just execute the generated javascript source.
In XCode, I saw the template for Java but I could not get the output of my program written in one of the Java templates (Java Application). Does Xcode supports Java compilation? If it supports it, should I add any thing to my program to run? It is just a "Hello World" program.
XCode does support Java development.
I'm not sure if you're asking for this specific to the iPhone - it's listed in the tags but not mentioned anywhere in your question. The iPhone only supports program development in Objective-C - to get a Java program to run on the iPhone you'd have to run it through a cross-compiler to turn your Java program into an Objective-C program. XMLVM is usually the cross-compiler mentioned in regards to this.
So, if you're developing a regular Java app that's going to run as a desktop or web app hosted on a Linux/Windows/Mac computer - XCode will do that. If you're trying to develop a Java app for the iPhone, you'll have to develop the app in Java (using XCode of otherwise), run it through a cross-compiler to produce an Objective-C program (not something that XCode does), and then deploy that to the iPhone.
Xcode goes not include gcj, but some people have managed to add it. No guarantees that this can be used to create iPhone apps 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.