java - Concatenate list of paths in bash-script, with colon as separator -


i have following difficult read script consisting of single command:

#!/bin/sh  /library/java/javavirtualmachines/jdk1.8.0_45.jdk/contents/home/bin/java \ -classpath /users/afarber/src/jetty-newbie/embeddedwebsocket/target/classes:/users/afarber/.m2/repository/org/eclipse/jetty/jetty-server/9.3.9.v20160517/jetty-server-9.3.9.v20160517.jar:/users/afarber/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar:/users/afarber/.m2/repository/org/eclipse/jetty/jetty-http/9.3.9.v20160517/jetty-http-9.3.9.v20160517.jar:/users/afarber/.m2/repository/org/eclipse/jetty/jetty-util/9.3.9.v20160517/jetty-util-9.3.9.v20160517.jar:/users/afarber/.m2/repository/org/eclipse/jetty/jetty-io/9.3.9.v20160517/jetty-io-9.3.9.v20160517.jar:/users/afarber/.m2/repository/org/eclipse/jetty/jetty-servlet/9.3.9.v20160517/jetty-servlet-9.3.9.v20160517.jar:/users/afarber/.m2/repository/org/eclipse/jetty/jetty-security/9.3.9.v20160517/jetty-security-9.3.9.v20160517.jar:/users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-api/9.3.9.v20160517/websocket-api-9.3.9.v20160517.jar:/users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-server/9.3.9.v20160517/websocket-server-9.3.9.v20160517.jar:/users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-common/9.3.9.v20160517/websocket-common-9.3.9.v20160517.jar:/users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.3.9.v20160517/websocket-client-9.3.9.v20160517.jar:/users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-servlet/9.3.9.v20160517/websocket-servlet-9.3.9.v20160517.jar \ de.afarber.myservlet 

as slight readability improvement list paths after -classpath in separate variable, each aligned after other:

paths=  /users/afarber/src/jetty-newbie/embeddedwebsocket/target/classes \         /users/afarber/.m2/repository/org/eclipse/jetty/jetty-server/9.3.9.v20160517/jetty-server-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/jetty-http/9.3.9.v20160517/jetty-http-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/jetty-util/9.3.9.v20160517/jetty-util-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/jetty-io/9.3.9.v20160517/jetty-io-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/jetty-servlet/9.3.9.v20160517/jetty-servlet-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/jetty-security/9.3.9.v20160517/jetty-security-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-api/9.3.9.v20160517/websocket-api-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-server/9.3.9.v20160517/websocket-server-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-common/9.3.9.v20160517/websocket-common-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-client/9.3.9.v20160517/websocket-client-9.3.9.v20160517.jar \         /users/afarber/.m2/repository/org/eclipse/jetty/websocket/websocket-servlet/9.3.9.v20160517/websocket-servlet-9.3.9.v20160517.jar  

this way can easier add , remove paths, , sort them in vim.

my question is: how join them command?

update:

if jar-files located in same dir, have used the new java 8 wildcard syntax java -classpath "/that/dir/*" de.afarber.myservlet - wasn't case here.

since using bash, can store directory names in array (with refactoring make example more readable):

repo=/users/afarber/.m2/repository jetty="$repo/org/eclipse/jetty" websocket="$jetty/websocket" paths=(     /users/afarber/src/jetty-newbie/embeddedwebsocket/target/classes     "$jetty"/jetty-server/9.3.9.v20160517/jetty-server-9.3.9.v20160517.jar     $repo/javax/servlet/javax.servlet-api/3.1.0/javax.servlet-api-3.1.0.jar     "$jetty"/jetty-http/9.3.9.v20160517/jetty-http-9.3.9.v20160517.jar     "$jetty"/jetty-util/9.3.9.v20160517/jetty-util-9.3.9.v20160517.jar     "$jetty"/jetty-io/9.3.9.v20160517/jetty-io-9.3.9.v20160517.jar     "$jetty"/jetty-servlet/9.3.9.v20160517/jetty-servlet-9.3.9.v20160517.jar     "$jetty"/jetty-security/9.3.9.v20160517/jetty-security-9.3.9.v20160517.jar     "$websocket"/websocket-api/9.3.9.v20160517/websocket-api-9.3.9.v20160517.jar     "$websocket"/websocket-server/9.3.9.v20160517/websocket-server-9.3.9.v20160517.jar     "$websocket"/websocket-common/9.3.9.v20160517/websocket-common-9.3.9.v20160517.jar     "$websocket"/websocket-client/9.3.9.v20160517/websocket-client-9.3.9.v20160517.jar     "$websocket"/websocket-servlet/9.3.9.v20160517/websocket-servlet-9.3.9.v20160517.jar  ) 

note don't need end each line backslash; whitespace (including newlines) separate elements of array. once have array, can join elements colon using parameter expansion modified value of ifs parameter.

/library/java/javavirtualmachines/jdk1.8.0_45.jdk/contents/home/bin/java \   -classpath "$(ifs=:; echo "${paths[*]}")" de.afarber.myservlet 

Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

java - Digest auth with Spring Security using javaconfig -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -