java服务器代码,在服务器上执行java代码

I'm developping a Web app, a sort of an online IDE to write and compile code. The programming language is developped internally at the university and also the compiler.

My question is : is it possible to execute a compiler on a server ( the compiler is written in java ), so that it compiles the code and returns a compiled file to be downloaded ?

In a simpler fashion, the user uses the online code editor, then clicks on the compile button, the server takes the written code, executes the compiler which is on ther server ( the compiler is written in java ) and then returns the compiled file.

So how could i execute the compiler ( written in java ) on the server ?

Thank you in advance !

解决方案

You didn't say what type of server, or what language you are using to develop the web app (PHP, node.js, python, perl, etc.), but normally Java distributions have a commandline binary that will run Java code.

If the compiler file is in a jar file, your command that the webapp executes could be a simple as something like:

java -jar compiler.jar inputcodefile outputexecutablefile

Of course you would substitute filenames and add the proper options needed for the compiler (if any).

EDIT: I see you tagged your question with node.js, so I'm assuming that is the language you are using on the server side.

node.js has "child process" that allows you to execute external commands.

So with the example command I gave above, you would do something like:

var exec = require('child_process').exec;

var compileit = 'java -jar compiler.jar inputcodefile outputexecutablefile';

exec(compileit, function(error, stdout, stderr) {

});

With PHP it's even easier:

exec('java -jar compiler.jar inputcodefile outputexecutablefile');

See http://php.net/manual/en/function.exec.php for more info on the exec() function in PHP.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值