Reputation: 115
I had been creating an online judge platform like codeforces.com on Django recently. Now, I'm struck across a problem that the user may possibly upload a Java file for testing with the filename different from the public class defined inside it. Yet, I should compile it automatically. So, what could be a possible solution to this?
If it's impossible to compile the file without renaming it properly, I need guidance how this 'renaming' can be done using a script/code?
Upvotes: 0
Views: 51
Reputation: 43651
The easiert would be probably to parse the uploaded Java file using something like JavaParser, then extract the package name and top-level class name and rename the uploaded file accordingly.
By the way, make sure you run the uploaded code in a pretty sandboxed environment.
Upvotes: 0
Reputation: 425
It will be a compilation error. file name should be same as public class name. hence not possible at all
Upvotes: 2