Skip to content

dist/bin/dotr can't run with a custom -classpath #3477

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nicolasstucki opened this issue Nov 15, 2017 · 3 comments
Closed

dist/bin/dotr can't run with a custom -classpath #3477

nicolasstucki opened this issue Nov 15, 2017 · 3 comments

Comments

@nicolasstucki
Copy link
Contributor

sbt dist-bootstrapped/pack
echo "object Main { def main(a: Array[String]): Unit = println(\"OK\") }" > Main.scala
./dist-bootstrapped/target/pack/bin/dotc -d out Main.scala
./dist-bootstrapped/target/pack/bin/dotr -classpath out Main

The last line will default to the repl instead running the application.

Note that dist-bootstrapped/target/pack/bin/dotr is generated from dist/bin/dotr when packing.

@rsoeldner
Copy link
Contributor

I changed the dist/bin/dotr to

if [ -z "$1" ]; then
    echo "Starting dotty REPL..."
    eval "$PROG_HOME/bin/dotc -repl"
elif [[ ${first_arg} == "-classpath" ]]; then
    eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$CLASS_PATH\"" $@
else
    eval "$PROG_HOME/bin/dotc -repl $@"
fi

But If i run your example I receive:

./dist-bootstrapped/target/pack/bin/dotr -classpath out Main
Exception in thread "main" java.lang.NoClassDefFoundError: scala/Predef$
	at Main$.main(Main.scala:1)
	at Main.main(Main.scala)
Caused by: java.lang.ClassNotFoundException: scala.Predef$
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:335)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 2 more

CLASS_PATH contains : :/home/rsoeldner/work/dotty/dist-bootstrapped/target/pack/lib/dotty-library_0.5-0.5.0-bin-SNAPSHOT.jar:/home/rsoeldner/work/dotty/dist-bootstrapped/target/pack/lib/scala-library-2.12.4.jar is this correct / what did i miss ?

@nicolasstucki
Copy link
Contributor Author

nicolasstucki commented Nov 16, 2017

@rsoeldner, that implies the JVM did not have the scala-library on the path.

If you change it to eval exec "\"$JAVACMD\"" "$DEBUG" "-classpath \"$CLASS_PATH\"" $@ you will see that you are going to execute

exec "/usr/bin/java"  -classpath ".:./dist-bootstrapped/target/pack/lib//dotty-library_0.5-0.5.0-bin-SNAPSHOT.jar:./dist-bootstrapped/target/pack/lib//scala-library-2.12.4.jar" -classpath out Main

where the second classpath overrides the value of the first one. Effectively running with only -classpath out.

We need to merge both classpaths into one and only emit that one. Executing something like this (note the place out):

exec "/usr/bin/java"  -classpath "out:.:./dist-bootstrapped/target/pack/lib//dotty-library_0.5-0.5.0-bin-SNAPSHOT.jar:./dist-bootstrapped/target/pack/lib//scala-library-2.12.4.jar" Main

We need to do something similar to the args as https://github.com/lampepfl/dotty/pull/3436/files#diff-215113124f1de02f228327ba7abb45f7R635 does but in bash.

On another note your issue makes me realize that we should also detect if the user defines several -classpath and print a warning. Not sure if we should join them all or take the last one as java does.

@nicolasstucki
Copy link
Contributor Author

Also, the -classpath will not necessarily be the first argument.

rsoeldner added a commit to rsoeldner/dotty that referenced this issue Nov 16, 2017
rsoeldner added a commit to rsoeldner/dotty that referenced this issue Nov 16, 2017
rsoeldner added a commit to rsoeldner/dotty that referenced this issue Nov 17, 2017
allanrenucci pushed a commit to rsoeldner/dotty that referenced this issue Nov 20, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants