csj / code-a-la-mode

15 stars 26 forks source link

Please make a runnable jar file #56

Closed wizzup closed 5 years ago

wizzup commented 5 years ago

First of all, I am not a Java developer and I don't know much about Java ecosystem. Just want to write bot locally.

I try to make a runnable jar file via mvn but can't get it work, here is the story

  1. Add main class

The readme mention com.codingame.game.Main.java but I can only found Main at test, so I pick com/codingame/game/sample/Main

$ grep -r Main src/
src/test/java/com/codingame/game/sample/Main.java:public class Main {
src/test/starterkit/starterAI.cs:        HasPlate = Content.Contains(MainClass.Dish);
src/test/starterkit/starterAI.cs:public class MainClass
src/test/starterkit/starterAI.cs:    static void Main()

and add following to pom.xml

$ git diff
diff --git a/pom.xml b/pom.xml
index 142f2f1..555fa54 100644
--- a/pom.xml
+++ b/pom.xml
@@ -46,6 +46,17 @@

     <build>
         <plugins>
+            <plugin>
+              <groupId>org.apache.maven.plugins</groupId>
+              <artifactId>maven-jar-plugin</artifactId>
+              <configuration>
+                <archive>
+                  <manifest>
+                    <mainClass>com.codingame.game.sample.Main</mainClass>
+                  </manifest>
+                </archive>
+              </configuration>
+            </plugin>
             <plugin>
                 <groupId>org.jetbrains.kotlin</groupId>
                 <artifactId>kotlin-maven-plugin</artifactId>
  1. run mvn package to create jar
$ mvn package

$ find target/ -name *.jar
target/code-a-la-mode-1.0-SNAPSHOT.jar

But when I try to run the jar file, I got an error

$ java -jar target/code-a-la-mode-1.0-SNAPSHOT.jar
Error: Could not find or load main class com.codingame.game.sample.Main
Caused by: java.lang.ClassNotFoundException: com.codingame.game.sample.Main

Please help me solve the problem.


With current system, is it possible to use a bot in starterkit for testing? How the communication (stdin/stdout) should be, if I want to write a bot that is not java?

It would be nice have some tool (CLI) like

runner <bot1> <bot2> <bot3> <bot4>

where the runner spawn botN as executable and manage stdin/stdout automatically.

Upon further investigation, I have found sdk documentation on game-runner but unfortunately I don't have enough Java skill to make it.

Counterbalance commented 5 years ago

I've added a CLI in my fork, and a release for convenience: https://github.com/Counterbalance/code-a-la-mode/releases

wizzup commented 5 years ago

@Counterbalance Thanks, useful tool like this should be push back to the codingame SDK.

I still have problem running your fork, but we should discuss at your repo. Can you enable issue feature?


run.sh script

java -jar target/code-a-la-mode-1.0-SNAPSHOT-shaded.jar \
  -p1 "python src/test/starterkit/starterAI.py" \
  -p2 "python src/test/starterkit/starterAI.py" \
  -p3 "python src/test/starterkit/starterAI.py" \
  -l "runlog.txt" \
  -s

I have try

$ git rev-parse HEAD
626a0d4d76aa9b6438d7d16f88749386ffe4b578

$ mvn package

$ ./run.sh
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.

but nothing happen and there is no runlog.txt anywhere.

wizzup commented 5 years ago

@Counterbalance Sorry to bother you again, problem is no longer exists (no idea why).

$ ./run.sh
WARNING: sun.reflect.Reflection.getCallerClass is not supported. This will impact performance.
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.google.inject.internal.cglib.core.$ReflectUtils$2 (file:/data/build/code-a-la-mode/target/code-a-la-mode-1.0-SNAPSHOT-shaded.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int,java.security.ProtectionDomain)
WARNING: Please consider reporting this to the maintainers of com.google.inject.internal.cglib.core.$ReflectUtils$2
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
http://localhost:8888/test.html
Exposed web server dir: /tmp/codingame
0
0
0
seed=-7786196049531864105

Thank you again.

Counterbalance commented 5 years ago

I've seen this before when using Java 11 - some issue with the google libs (maybe it's not triggered if you omit the -l option?). If it happens again, try downgrading to Java 8.