Forums

Search results: 44

Hello,

I'm using CodeRunner inside a Moodle test. I'd like my students to write a Java method that makes use of javax/json and org/glassfish libraries. I've attached the corresponding jar files in the "support files" section, and personalized the __tester__ class so it imports these packages. But it fails:

    __tester__.java:6: error: package javax.json does not exist
    import javax.json.JsonReader;

How can I fix that?

I've tried uncompressing the jar files in the "support files" section but sub-directories are deleted when I save the question.

Have a good day,

Virginie

Question Authors' Forum -> nodejs with ESM rather than CJS

by Peter Sander -

Hello All,

Anyone tried using the newer ES Modules syntax for nodejs code (using export / import) as opposed to Common JavaScript (using module.exports / require)?

For what it's worth, a simple test results in

***Error***
(node:4531) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
__tester__.nodejs:2
import done from './cli.mjs');
^^^^^^ SyntaxError: Cannot use import statement outside a module
at wrapSafe (internal/modules/cjs/loader.js:931:16)
at Module._compile (internal/modules/cjs/loader.js:979:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1035:10)
at Module.load (internal/modules/cjs/loader.js:879:32)
at Function.Module._load (internal/modules/cjs/loader.js:724:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:60:12)
at internal/main/run_main_module.js:17:47
Perhaps it would work with a new prototype question, nodejs_esm say, with main_module.js named main_module.mjs instead?

Just trying to keep up...

Question Authors' Forum -> Java packages -> Re: Java packages

by Richard Lobb -

Happy Christmas to you too :-) My sympathies for your heavy lockdown over Christmas. We're fortunate in New Zealand that we're a small island nation at the bottom of the world with a good government that has managed to eliminate covid, although there could be an outbreak at any time.

Without your prototype I can't check exactly what you're doing but I'm almost certain that the problem is that the "Is combinator" checkbox is checked in your prototype. Since the template is a per-test template not a combinator template, this will result in the TEST variable being undefined. You should uncheck it.

I attach an exported version of your question that uses your template within a customised question rather than as a question prototype. In its present form it's not usable because your support module generates random data so the output is non-deterministic, but it does at least run and generate plausible output. I suggest you steer clear of using randomisation until you have more familiarity with CodeRunner and its randomisation capabilities.

Question Authors' Forum -> Java packages -> Re: Java packages

by sc kaindorf -

Thanks for your answer and "Frohes Fest" (Happy Christmas)! I have build a new Question for my students and modified the template. Its still the same, but added some print commands for a better debugging.

May I found probably my error. I use the python script found in the forum:


import sys, os, shutil, subprocess __student_answer__ = """{{ STUDENT_ANSWER | e('py') }}""" # Make package directory, put support files into it os.mkdir("{{ QUESTION.parameters.package }}") [shutil.move(f, "{{ QUESTION.parameters.package }}") for f in os.listdir() if f.endswith(".java")] # Put student answer class into package directory with open("{{ QUESTION.parameters.package }}/{{ QUESTION.parameters.class}}.java", "w") as f: print(__student_answer__, file=f) # Build test class in package directory too print('Testcode : {{ TEST.testcode }}') tester = """package {{ QUESTION.parameters.package }}; public class __Tester__ { public static void main(String[] args) { //Hello //Test: {{ TEST.testcode }} } } """ with open("{{ QUESTION.parameters.package }}/__Tester__.java", "w") as f: print(tester, file=f) # Compile and run if (subprocess.call(["javac", "{{ QUESTION.parameters.package }}/__Tester__.java"]) != 0 or subprocess.call(["java", "{{ QUESTION.parameters.package }}/__Tester__"]) != 0): print("** Further testing aborted **", file=sys.stderr)

and in my python environment everything works fine. The problem seams to be the {{ TEST.testcode }} for the generated __Tester__ class. {{ TEST.testcode }} is empty and I have no idea to fix this circumstance. The debug message from my student account is:

import sys, os, shutil, subprocess
__student_answer__ = """"""
# Make package directory, put support files into it
os.mkdir("Bsp211")
[shutil.move(f, "Bsp211") for f in os.listdir() if f.endswith(".java")]
# Put student answer class into package directory
with open("Bsp211/Bsp211.java", "w") as f:
    print(__student_answer__, file=f)

# Build test class in package directory too
print('Testcode : ')
tester = """package Bsp211;
public class __Tester__ {
    public static void main(String[] args) {
        //Hello
        //Test: 
    }
}
"""
with open("Bsp211/__Tester__.java", "w") as f:
    print(tester, file=f)
# Compile and run
if (subprocess.call(["javac", "Bsp211/__Tester__.java"]) != 0 or
   subprocess.call(["java", "Bsp211/__Tester__"]) != 0):
    print("** Further testing aborted **", file=sys.stderr)

and the added test should be:

NotenUi ui = new NotenUi();
ui.start();

Do you have another hint for me? Attached my export. Meanwhile: Here in Austria we have a lot of snow and a hard lockdown :-) - Hope you are fine and on this way: Happy New Year ... Thanks - schtl

Question Authors' Forum -> Java packages -> Re: Java packages

by Richard Lobb -

Your exported question needs your Java_Package prototype, which I don't have so I can't test exactly. However, I changed the question type to python3, customised it, set the template to the code you gave above, and set the memlimit to 0 and numprocs to 100. When I run it get the output "Well Done?" from your template:

Can you confirm please that you have tried setting memlimit to 0 and that numprocs has been set to a higher number (both under Advanced Customisation) ?

Result table image

I attach my working version (with the "Expected" set to "Well Done?"). Note that I also checked Hoist Template Parameters so I could dispense with all the QUESTION.parameters prefixes in your template code.

[Edit: it belatedly occurs to me that because I exported the question from my development system, which has extra database fields, the attached .xml file might not be importable onto your system. I can redo the exercise on a production system if necessary, but please try it first, after confirming the memlimit and numprocs values.]

By the way: I think it would be easier you you to debug template code in a single customised question first, and only set up a prototype once that sample question is working.


Question Authors' Forum -> Java packages -> Re: Java packages

by Richard Lobb -

It is strange to get no output at all.

Have you set memlimit to 0 so that the sandbox doesn't limit memory at all? This is pretty safe with Java because the JVM manages memory anyway.

Have you turned on template debugging, copied the program that's generated out to your own machine and run it with the support file in the same directory as the Python expanded template? Does it work?

If you're still stumped, please post back attaching the exported xml question together with the Java file(s) that you're testing with and I'll have a look at it.

Richard

Question Authors' Forum -> Java packages

by sc kaindorf -

Oh dear - I'm so frustrated - I cant find the error. My wife asked me the whole time, what I do all the time for our school ... Hhhmmm :-)

What I have done is:

* new Prototype for java packages

import sys, os, shutil, subprocess
__student_answer__ = """{{ STUDENT_ANSWER | e('py') }}"""
# Make package directory, put support files into it
os.mkdir("{{ QUESTION.parameters.package }}")
[shutil.move(f, "{{ QUESTION.parameters.package }}") for f in os.listdir() if f.endswith(".java")]
# Put student answer class into package directory
with open("{{ QUESTION.parameters.package }}/{{ QUESTION.parameters.class}}.java", "w") as f:
    print(__student_answer__, file=f)
    
# Build test class in package directory too
tester = """package {{ QUESTION.parameters.package }};
public class __Tester__ {
    public static void main(String[] args) {
        {{TEST.testcode}}
    }
}
"""
with open("{{ QUESTION.parameters.package }}/__Tester__.java", "w") as f:
    print(tester, file=f)
# Compile and run
if (subprocess.call(["javac", "{{ QUESTION.parameters.package }}/__Tester__.java"]) != 0 or
   subprocess.call(["java", "{{ QUESTION.parameters.package }}/__Tester__"]) != 0):
    print("Error")
    print("** Further testing aborted **", file=sys.stderr)
print("Well Done?")

* I have two java files: one for the answer and an additional

* Parameter set to {"package": "Bsp206", "class": "IqTester"}

* My testcase is simple:

System.out.println("DEBUG0");
IqTester iqt = new IqTester();
iqt.start();


But: Nothing happens! No output - nothing! Could anyone please help!

Thanks, thanks, thanks

PS (On my ubuntu laptop javac and java works fine ...)


Hi Richard!


I put everything to work like I inted with a tip form anseki/readline-sync: instead of using readline-sync I used syncprompt package. I'm testing and at the moment it is working.

var prompt = require('syncprompt');

 var answer = prompt('');

console.log('\nHi ' + answer+'!');


Thank you very much for your help.


Yes, I did and it worked. 

The problem is that I wanted a sync readline input because my course is a introductory to programming for multimedia students that are integrated in anothers couse in the following order: first they will learn html+css, then learn coding with javascript and finally PHP+SQL databases.

In others courses I used C# with coderunner to introduce coding and it was great.  So I'd like to replicate that course to Javascript. But the readline method uses an asynchronously way that is to complex to explain to newbies.

So I tried the readline-sync package but that throw the error I mentioned above.

The problem now is that the jobe server tell that stty is not set:


stty: when specifying an output style, modes may not be set

But when I run a script in the "runs" folder exactly the same, it works!


There is some chance to set the stty mode in jobe server?