0

I've been encountering a problem with cygwin where I cannot run a jar file with an error that the file cannot be found.

If it were easier i would "translate" the java source in bash, but unfortunately, due to the functionality implemented, there are some quite significant obstacles to achieve this, so I'd have to use the jar file.

Now, I've done a fair amount of research on my part to figure out how to do this, however, I couldn't succeed, and it is mandatory that i use cygwin.

Here's what I'm trying to essentially do:

lockfile="$specialfolder/$passedargument.lock
java -jar `cygpath -w ./cygdrive/driveletter/folder/folder/javafile.jar -joption cygpath -w $lockfile`

i also tried with double back-ticks, as follows:

pathtooutfile="${some_other_vars}/${that}_${work}.out"
java -jar `cygpath -w ./cygdrive/driveletter/folder/folder/javafile.jar` -joption `cygpath -w $lockfile`

i also tried using the $JAVA_HOME env var but that did not work as well. It is important to mention that the variables being called in lockfile var are defined as follows:

 homedir= "/cygdrive/driveletter/folder/folder"
 specialfolder= "$homedir/foler/$passedargument"
 passedargument= $1 ###argument passed with execution of bash script
 lockfile= "$specialfolder/$passedargument"

The error i keep getting is this: Error: Unable to access jarfile I have modified usage rights to 777 and that didn't work either. It might also be important to mention that -joption is either -aquire or -release corresponding to the lockfile since one of the things the jar does is manage multiple script executions through a lock file. I'm somewhat stuck so, any suggestions will be greatly appreciated. I think that this might be more of a cygwin issue.

10
  • What does cygpath -w ./cygdrive/driveletter/folder/folder/javafile.jar return if you run it on its own. (Please add the output to your question, not as a comment). Mar 10, 2016 at 9:22
  • always Error: Unable to access jarfile Mar 10, 2016 at 9:45
  • So the command, cygpath -w ./cygdrive/driveletter/folder/folder/javafile.jar on its own, with nothing else, gives you that error? Can you copy and paste you typing that command in and the output? In the question. You are using c or d (or something) in place of driveletter, rather than the word driveletter? Mar 10, 2016 at 10:16
  • 1
    Sorry, since you continue to resist adding any useful diagnostic information to your question, you prevent people helping. I'll just go answer someone elses question (I use cygpath myself in plenty of situations, but since we don't know what it's outputting in your instance, we can't help). Mar 10, 2016 at 13:31
  • 2
    Then edit your question with that detail, because right now, that's not what your question is asking. Mar 10, 2016 at 14:02

3 Answers 3

0

Have you tried cygpath -w -a .....

The -a returns absolute paths.

e.g.

$ cygpath -w ./screenshot.jpg
screenshot.jpg

$ cygpath -w -a ./screenshot.jpg
C:\cygwin64\home\tony\screenshot.jpg
0

If your expression

`cygpath -w ./cygdrive/driveletter/folder/folder/javafile.jar`

has embedded blanks, you should put double-quotes around it so that the result is passed to Java as a single token. It can help to understand the expressions and results if you turn on the shell trace, e.g., set -x.

Further reading:

0

Windows absolute paths always start with a drive letter, for example C:\folder1\folder2\item.ext. Cygwin absolute paths start with / - just like all UNIX/Linux filesystems - but provide a metafolder cygdrive that allows disparate Windows drive letters to be mapped seamlessly into the one filesystem tree, for example /cygdrive/c/folder1/folder2/item.ext. (In fact the two example file paths I've given would correspond to the same filesystem object.)

The fundamental problem here is that you have an invalid path. It's a relative path because it doesn't begin with /, but then it references what looks like an absolute path corresponding to a Windows drive letter and path:

cygpath -w ./cygdrive/driveletter/folder/folder/javafile.jar

What I think you probably meant was this, without the leading dot:

cygpath -w /cygdrive/driveletter/folder/folder/javafile.jar

Fixing the quoting and generally tidying up, that would make your script segment look like this:

lockfile="$specialfolder/$passedargument.lock"
java -jar "$(cygpath -w /cygdrive/driveletter/folder/folder/javafile.jar)" -joption "$(cygpath -w "$lockfile")"

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .