Sharif-Judge icon indicating copy to clipboard operation
Sharif-Judge copied to clipboard

Java files can't be compiled if they contain package statement ☕

Open alirezaopmc opened this issue 2 years ago • 0 comments

Consider this java code:

package something;

class SomeClass {
  public static void main(String[] args) {
    System.out.println("Hello world!");
  }
}

This must be compiled using javac according to the package name. In fact to compile this java code it must be moved to a directory called something. Then It can be compiled using javac something/SomeClass.java. But the tester.sh does not do this operation currently.

You can see the shell command executed for java files here:

if [ "$EXT" = "java" ]; then
	cp ../java.policy java.policy
	cp $PROBLEMPATH/$UN/$FILENAME.java $MAINFILENAME.java
	shj_log "Compiling as Java"
	javac $MAINFILENAME.java >/dev/null 2>cerr
        ...

This is annoying if the students structure their code in some directories with package statements.

A real example code: image

Output: image

alirezaopmc avatar Jul 14 '22 17:07 alirezaopmc