Closed aaaaaa2493 closed 3 years ago
In Stepik we use the following bash script to get the main class name in Java (and somewhat similar in Scala and Kotlin):
#!/bin/bash
# Grep *.class files in the given directory to find one with psvm method defined
# Usage: java_lookup_main.sh DIRECTORY_PATH
PSVM_REGEX="public static( final)? void main\(java\.lang\.String(\[\]|\.\.\.)\)"
shopt -s nullglob
for f in "$1"/*.class; do
if javap -p "$f" 2> /dev/null | grep -Pq "$PSVM_REGEX"; then
filename=$(basename "$f")
echo -n "${filename%.*}"
exit 0
fi
done
exit 1
Full code to work with this script: https://github.com/bioinf/edy/blob/e7fda90797557eecf841b86ef78e6ebc71a5572b/plugins/stepic_plugins/quizzes/code/runners.py#L192..L242
Also should be checked if there are more than one Main method and show feedback to the user that there should be just one main method
Fixed in 55e1caf4f37783a49ab8d378b0b7a8820fbbfb2a
The script will be useful for implementing #91
Relates to #46