sbt-native-packager icon indicating copy to clipboard operation
sbt-native-packager copied to clipboard

Created bin/ scripts fail if path where they are contains :

Open arturaz opened this issue 8 years ago • 4 comments

Execution with set -x

tlp@pebbles:~/game-configs/server/current$ bin/server
+ declare -a residual_args
+ declare -a java_args
+ declare -a app_commands
++ realpath bin/server
++ TARGET_FILE=bin/server
++ CHECK_CYGWIN=
+++ dirname bin/server
++ cd bin
+++ basename bin/server
++ TARGET_FILE=server
++ COUNT=0
++ '[' -L server -a 0 -lt 100 ']'
++ '[' server == . -o server == .. ']'
++ TARGET_FILEPATH=/server
++ [[ x == \x ]]
+++ pwd -P
++ echo /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/server
+ declare -r real_script_path=/home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/server
+++ dirname /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/server
++ realpath /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin
++ TARGET_FILE=/home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin
++ CHECK_CYGWIN=
+++ dirname /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin
++ cd /home/tlp/game-configs/server/2016-12-04T16:21:25.469
+++ basename /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin
++ TARGET_FILE=bin
++ COUNT=0
++ '[' -L bin -a 0 -lt 100 ']'
++ '[' bin == . -o bin == .. ']'
++ TARGET_FILEPATH=/bin
++ [[ x == \x ]]
+++ pwd -P
++ echo /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin
+ declare -r app_home=/home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin
++ realpath /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/../lib
++ TARGET_FILE=/home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/../lib
++ CHECK_CYGWIN=
+++ dirname /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/../lib
++ cd /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/..
+++ basename /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/../lib
++ TARGET_FILE=lib
++ COUNT=0
++ '[' -L lib -a 0 -lt 100 ']'
++ '[' lib == . -o lib == .. ']'
++ TARGET_FILEPATH=/lib
++ [[ x == \x ]]
+++ pwd -P
++ echo /home/tlp/game-configs/server/2016-12-04T16:21:25.469/lib
+ declare -r lib_dir=/home/tlp/game-configs/server/2016-12-04T16:21:25.469/lib
+ app_mainclass=("-jar" "$lib_dir/com.tinylabproductions.server-1.0.0-launcher.jar")
+ declare -a app_mainclass
+ declare -r script_conf_file=/home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/../conf/application.ini
+ declare -r app_classpath=
++ get_java_cmd
++ [[ -n '' ]]
++ echo java
+ declare java_cmd=java
+ [[ -f /home/tlp/game-configs/server/2016-12-04T16:21:25.469/bin/../conf/application.ini ]]
+ run
+ process_args
+ local no_more_snp_opts=0
+ [[ 0 -gt 0 ]]
+ [[ -n no_more_snp_opts ]]
+ [[ 0 -gt 0 ]]
+ is_function_defined process_my_args
+ declare -f process_my_args
+ set --
+ argumentCount=0
+ is_cygwin
++ uname -s
+ local os=Linux
+ case "$os" in
+ return 1
+ [[ ! -n '' ]]
+ java_version_check
++ awk -F '"' '/version/ {print $2}'
++ java -version
+ readonly java_version=1.8.0_77
+ java_version=1.8.0_77
+ [[ 1.8.0_77 == '' ]]
+ [[ ! 1.8.0_77 > 1.6 ]]
+ '[' -n '' ']'
+ mainclass=("${app_mainclass[@]}")
+ [[ '' != '' ]]
++ fix_classpath ''
++ cp=
++ is_cygwin
+++ uname -s
++ local os=Linux
++ case "$os" in
++ return 1
++ echo ''
+ execRunner java -cp '' -jar /home/tlp/game-configs/server/2016-12-04T16:21:25.469/lib/com.tinylabproductions.server-1.0.0-launcher.jar
+ [[ -n '' ]]
+ [[ -n '' ]]
+ exec java -cp '' -jar /home/tlp/game-configs/server/2016-12-04T16:21:25.469/lib/com.tinylabproductions.server-1.0.0-launcher.jar
Error: Could not find or load main class com.tinylabproductions.game_configs.ServerMain

arturaz avatar Dec 04 '16 16:12 arturaz

Hi,

Thanks for your report. Does the script work without the set -x (xtrace) option? The error message says

Error: Could not find or load main class com.tinylabproductions.game_configs.ServerMain

Your main class cannot be found. I'm not sure how the debugging option could break this. Please also add

  • The version of native-packager you are using
  • A small project / build.sbt to reproduce this
  • The system you are executing the script

muuki88 avatar Dec 05 '16 08:12 muuki88

The -x flag does not impact the failure.

I think it fails because the -cp option the script runs does not escape : in directory names and java uses : as classpath separator.

So -cp foo:bar/a.jar:foo:bar/b.jar becomes foo, bar/a.jar, foo, bar/b.jar as far as java is concerned.

On Dec 5, 2016 10:33 AM, "Nepomuk Seiler" [email protected] wrote:

Hi,

Thanks for your report. Does the script work without the set -x (xtrace) option? The error message says

Error: Could not find or load main class com.tinylabproductions.game_configs.ServerMain

Your main class cannot be found. I'm not sure how the debugging option could break this. Please also add

  • The version of native-packager you are using
  • A small project / build.sbt to reproduce this
  • The system you are executing the script

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/sbt/sbt-native-packager/issues/926#issuecomment-264794757, or mute the thread https://github.com/notifications/unsubscribe-auth/AAAyg7cbPQ9X0jZ6OvEh8Z3nWac9Fgz8ks5rE8xqgaJpZM4LDoO9 .

arturaz avatar Dec 05 '16 09:12 arturaz

I seem to have the same problem with sbt native packager version 1.4.1 . The generated script calls realpath to get the lib_dir. If the realpath contains a colon somewhere, which is valid in unix filenames, the parameters given to -cp are split the wrong way.

It doesn't depend on the build.sbt file, as far as I can see, so I don't think it's useful to provide build.sbt for reproduction here.

To reproduce, use any project packaged with the native packager, create a directory with a colon in it (eg mkdir /tmp/foo:bar), copy the package into that directory (eg. cp -r package /tmp/foo:bar/) and then call /tmp/foo:bar/package/bin/yourMainClass and it should fail.

Thanks a lot for this great project. After switching from assembly to native packager, I never looked back.

felher avatar Feb 05 '20 13:02 felher

Thanks a lot @felher for the additional information on this. I'll reopen this. If you like to make a pull request, I'm more than happy to help you :smiley:

muuki88 avatar Feb 10 '20 13:02 muuki88