0

I have a Java Environment on C9. The Ace editor supports it nicely, but there's no run systems configured for it. I created my own which looks like this, the filename is JavaRunner.run:

// Create a custom Cloud9 runner - similar to the Sublime build system
// For more information see http://docs.c9.io:8080/#!/api/run-method-run
{
    "cmd" : ["javac", "$file", "$args"],
    "info" : "Started to compile java file at $project_path to ${file_base_name}.class",
    "env" : {},
    "selector" : "source.java"
}

On a second go, I tried this:

{
  "cmd": ["javac $file_name && java $file_base_name"],
  "info" : "In the directory of $file_path we will javac $file_name && java $file_base_name",
  "working_dir": "$file_path",
  "env" : {},
  "selector" : "source.java",
  "shell": true
 }

The first example will do the compiling, but then it won't run the code. The second one works if it is run from the command line, but it won't work within the runner file.

Michael Ryan Soileau
  • 1,763
  • 17
  • 28

2 Answers2

1

To run multiple commands you'll need to wrap them in a bash shell. Here's an example of how the Node.js runner does it:

// This file overrides the built-in Node.js (default) runner
// For more information see http://docs.c9.io:8080/#!/api/run-method-run
{
  "cmd": [
    "bash",
    "--login",
    "-c",
    "nvm use default > /dev/null; node ${debug?--nocrankshaft --nolazy --nodead_code_elimination --debug-brk=15454} '$file' $args"
  ],
  "selector": "source.js",
  "info": "Your code is running at \\033[01;34m$url\\033[00m.\n\\033[01;31mImportant:\\033[00m use \\033[01;32mprocess.env.PORT\\033[00m as the port and \\033[01;32mprocess.env.IP\\033[00m as the host in your scripts!\n"
}

This should work for your use case as well.

Ruben Daniels
  • 856
  • 4
  • 3
0

Created a Java Package Builder and Runner, Tested on Centos 7.1 and Ubuntu 14.04.3 LTS

Uses 'sed' to parse '~/src/' from path of file being compiled. Builder also creates '~/bin' directory and project structure for Runnner.

To Do : Allow for user input at run time. - removed xargs to allow for stdin.

C9 Doc: https://docs.c9.io/docs/custom-runners

Git Gist: https://gist.github.com/fogartyp/581e2ebc35a0c77b2cb1

MUST BE IN PROJECT LAYOUT

.
└── Packages
    └── src
        └── com
            └── example
                └── java
                    └── Main.java

Builder:

// Create a custom Cloud9 build system - similar to the Sublime build system
// For more information see https://docs.c9.io/custom_runners.html
{
  "cmd": [
    "bash",
    "-c",
    "mkdir -p $(echo $file | sed -r \"s_/src/.*_/_g\")bin; find $(echo $file | sed -r \"s_/src/.*_/_g\")src -name '*.java' -print | xargs javac -sourcepath $(echo $file | sed -r \"s_/src/.*_/_g\")src -d \"$(echo $file | sed -r \"s_/src/.*_/_g\")bin\""
  ],
  "info": "\\033[01;34mBuilding\\033[00m \\033[01;31m$project_name\\033[00m",
  "selector": "source.java",
  "working_dir": "$file_path"
}

Runner:

// Create a custom Cloud9 runner - similar to the Sublime build system
// For more information see https://docs.c9.io/custom_runners.html
{
  "cmd": [
    "bash",
    "-c",
    "java -cp $(echo $file | sed -r \"s_/src/.*_/bin_g\") $(echo $file | sed -r \"s_.*/src/__g\" | sed -r \"s_\\.java__g\"  | sed -r \"s_/_._g\")"
  ],
  "info": "\\033[01;34mRunning\\033[00m \\033[01;31m$file_name\\033[00m\n",
  "selector": "source.java",
  "working_dir": "$file_path"
}
Hammerhand
  • 11
  • 2