0
votes

I am new to sygwin, so I am probably doing something wrong.

Here is my shell script:

!/bin/sh
set [-x]
export myInstallDirectory='/cygdrive/c/cygwin64/usr/uTrace_ServerMachine'
echo "myInstallDirectory=" $myInstallDirectory
export JAVA_HOME=/cygdrive/c/Java_JDK_SE_8_u77_64_bit
echo "JAVA_HOME = " $JAVA_HOME
export PATH=$JAVA_HOME/bin:$PATH
echo "PATH =" $PATH
export CLASSPATH=$myInstallDirectory/bin/UtraceServer.jar:$CLASSPATH
echo "CLASSPATH=" $CLASSPATH
java -jar UtraceServer.jar
set [+x]

Here is what the log shows:

myInstallDirectory= /cygdrive/c/cygwin64/usr/uTrace_ServerMachine
JAVA_HOME =  /cygdrive/c/Java_JDK_SE_8_u77_64_bit
PATH = /cygdrive/c/Java_JDK_SE_8_u77_64_bit  

/bin:/usr/local/bin:/usr/bin:/cygdrive/c/windows/system32:/cygdrive/c/ProgramData/Oracle/Java/javapath:/cygdrive/c/Program Files/Intel/WiFi/bin:/cygdrive/c/Program Files/Common Files/Intel/WirelessCommon:/cygdrive/c/WINDOWS:/cygdrive/c/WinZip/WINZIP/WINZIP32.EXE:/cygdrive/c/Java_JDK_SE_8_u77_64_bit/bin:/cygdrive/c/Java_JDK_SE_8_u77_64_bit/lib/tools.jar:/cygdrive/c/Java_EE_SDK_7_u2/glassfish4/bin:/cygdrive/c/Java_EE_SDK_7_u2/glassfish4/glassfish/bin:/cygdrive/c/Java_EE_SDK_7_u2/glassfish4/glassfish/lib/javaee.jar:/cygdrive/c/IBM/Derby/db-derby-10.12.1.1-bin/lib/derbynet.jar:/cygdrive/c/IBM/Derby/db-derby-10.12.1.1-bin/lib/derbytools.jar:/cygdrive/c/IBM/Derby/db-derby-10.12.1.1-bin/lib/derbyoptionaltools.jar:/cygdrive/c/IBM/Derby/db-derby-10.12.1.1-bin/test/jakarta-oro-2.0.8.jar:/cygdrive/c/IBM/Derby/db-derby-10.12.1.1-bin/test/derbyTesting.jar:/cygdrive/c/IBM/Derby/db-derby-10.12.1.1-bin/lib/derbyrun.jar:/cygdrive/c/IBM/DB2_EX~1/java/db2java.zip:/cygdrive/c/IBM/DB2_EX~1/java/db2jcc.jar:/cygdrive/c/IBM/DB2_EX~1/java/sqlj.zip:/cygdrive/c/IBM/DB2_EX~1/java/db2jcc_license_cu.jar:/cygdrive/c/IBM/DB2_EX~1/bin:/cygdrive/c/IBM/DB2_EX~1/java/common.jar:/cygdrive/c/ORACLE/NetBeans 8.1/java/maven/bin:/cygdrive/c/Program Files (x86)/Skype/Phone:/cygdrive/c/Cygwin/bin:/cygdrive/c/Program Files/Microsoft Network Monitor 3:/cygdrive/c/My_Software_Development/Client_Monitoring/Client_Scripts

CLASSPATH= /cygdrive/c/cygwin64/usr/uTrace_ServerMachine /bin/UtraceServer.jar:.;C:\Java_JDK_SE_8_u77_64_bit\lib\tools.jar;C:\Java_EE_SDK_7_u2\glassfish4\glassfish\lib\javaee.jar;C:\IBM\Derby\db-derby-10.12.1.1-bin\lib\derbynet.jar;C:\IBM\Derby\db-derby-10.12.1.1-bin\lib\derbytools.jar;C:\IBM\Derby\db-derby-10.12.1.1-bin\lib\derbyoptionaltools.jar;C:\IBM\Derby\db-derby-10.12.1.1-bin\test\jakarta-oro-2.0.8.jar;C:\IBM\Derby\db-derby-10.12.1.1-bin\test\derbyTesting.jar;C:\IBM\Derby\db-derby-10.12.1.1-bin\lib\derbyrun.jar;C:\IBM\DB2_EX~1\java\db2java.zip;C:\IBM\DB2_EX~1\java\db2jcc.jar;C:\IBM\DB2_EX~1\java\sqlj.zip;C:\IBM\DB2_EX~1\java\db2jcc_license_cu.jar;C:\IBM\DB2_EX~1\bin;C:\IBM\DB2_EX~1\java\common.jar

Error: Unable to access jarfile UtraceServer.jar

The jarfile UtraceServer.jar is located in /cygdrive/c/cygwin64/usr/uTrace_ServerMachine/bin/UtraceServer.jar and as you can see it is in the CLASSPATH. Appreciate any help.

2

2 Answers

0
votes

Java is not a Cygwin application so it can not understand its PATH nor the cygdrive suffix.

JAVA_HOME = /cygdrive/c/Java_JDK_SE_8_u77_64_bit
PATH = /cygdrive/c/Java_JDK_SE_8_u77_64_bit

0
votes

As explained in How to run Java from Cygwin, you can use Cygwin paths in your script, but just before you call Java, you should convert them to Windows paths, for instance with cygpath -p:

!/bin/sh -x
export myInstallDirectory='/cygdrive/c/cygwin64/usr/uTrace_ServerMachine'
echo "myInstallDirectory = $myInstallDirectory"
export CLASSPATH="$myInstallDirectory/bin/UtraceServer.jar:$CLASSPATH"
echo "CLASSPATH = $CLASSPATH"
CLASSPATH="$(cygpath -pw "$CLASSPATH")"
echo "CLASSPATH (Windows) = $CLASSPATH"
java -jar UtraceServer.jar

(I've omitted the other paths from the script, because Java is clearly found.)

cygpath can (among others) convert a single path between POSIX and and different Windows formats, e.g. -w converts a path to a Windows path. With the addition of -p it treats its argument as a path list (separated by : for POSIX, by ; for Windows). See cygpath --help for the full info.

Important: when you use this in scripts, it is recommended always to use double quotes (as in the script above). Doing this consistently considerably reduces the risks for issues caused by (e.g.) spaces in path names.