aspose file tools*
The moose likes Linux / UNIX and the fly likes different command-line startup on linux (vs. windows) not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » Linux / UNIX
Bookmark "different command-line startup on linux (vs. windows) not working" Watch "different command-line startup on linux (vs. windows) not working" New topic
Author

different command-line startup on linux (vs. windows) not working

manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
hi,

want to check, if my app is portable to linux. but the startup of app does not work, because somehow the command-line in linux differs from the one on windows:

following is working (on windows):
..\jre1_6_0\bin\java -classpath .;mainApp.jar;lib/* path.to.MainClass

following, which should do the same is not working (on linux):
../jre1_6_0/bin/java -classpath .:mainApp.jar:lib/* path.to.MainClass

why is that? does the working dir differ, so main jar cannot be found? what command-line issues are different on linux vs windows?

thanks.


aldana software engineering blog & .more
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
i forgot to mention that it works when executing directly to command line, but linux command fails when executed in shell script .sh.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

What error are you seeing when you try to execute the shell script?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
NoClassDefFoundError of the main class
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Are you in the same directory when executing right from the command line as you are when you're calling this from the script?

You've got relative paths in your classpath and in your call to java.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

As a side note, the :lib/* might not be doing what you think it is.
A 'lib' directory, by convention holds jar files and jar files need to be added to the classpath explicitly and individually.
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308

Are you in the same directory when executing right from the command line as you are when you're calling this from the script?


yes, script is executed in same directory as direct command-line.



As a side note, the :lib/* might not be doing what you think it is.
A 'lib' directory, by convention holds jar files and jar files need to be added to the classpath explicitly and individually.


that is not quite correct. from java 1.5 it is possible to use the lib-expander *, which includes all jars from a folder.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I didn't know about the new wildcards.
Learn something new every day.

Have you verified that the jar file is OK?
jar tvf jarfile.jar

The only other thing I can think of (and I'm grabbing at straws) is that Unix is case sensitive where Windows is not. Are all of your resources spelled the same in your script?
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11508
    
  95

Are you using the same shell to execute your script that you are using when you have an interactive prompt?

That is, from the command line, I can look at the SHELL environmental variable to determine that I am currently using bash:However I can explicitly override that when I want to run a script:Side note: for those who are unfamiliar with the setenv command, the usage above is effectively the same as the sh, ksh, or bash commands: HELLO="Hello world"; export HELLO

So - the thing that I wanted to point out was that even though I executed this script from within my bash shell, the very first line of the script determined that it would be run from within the C shell (csh).

That ability to change what will interpret your script means that the sh suffix has little to no meaning within *nix environments. I personally would say that the name of the following script is wrong, simply because I personally think it should have an 'awk' suffix, but as far as *nix is concerned it is perfectly valid:




Now - on another point, and one which may be potentially far more use to you:

from java 1.5 it is possible to use the lib-expander *, which includes all jars from a folder.


This is true, however the Java expander gets applied after the shell expander. So in your example above, the Java expander would not have been invoked since the asterisks would have been expanded by your shell.

I would recommend putting your classpath inside single quotes: ' Don't use double quotes since they will still be expanded by the shell in most instances.

Regards, Andrew


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308

Have you verified that the jar file is OK?
jar tvf jarfile.jar

yes, jar is fine. when executing directly from shell it works.



Are you using the same shell to execute your script that you are using when you have an interactive prompt?

yes

to reduce problem sources (expanding etc.), i only included the jar of the main class. (though i must admit, that i ran this on a cygwin environment). i currently do not have access to a linux system (on which it did not work yesterday).

when typing above directly on command-line it starts. when executing from a script i again get a NoClassDefFoundError. the single-quote hint did not work either.


it is a real miracle...
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Miracle could be one word for it. :\

For kicks, I just tried this on my FC2 machine with a simple hello world app and it worked fine.


I was thinking that maybe there is another dependency in your program that is satisfied when you run it from the shell but not from a script but the script should have the same environment if it's being run as the same user from the same directory.


Two things that won't take long to try.
Try with fully qualified paths in your script; both to Java and to your jar file.

Try doing this with a small hello world program as I have just done and see if that works.
manuel aldana
Ranch Hand

Joined: Dec 29, 2005
Posts: 308
i know the last post has been quite a long time ago...

but still i want to kind of solve it a bit. it seemed to be a cygwin issue, running the scripts on linux (suse) they worked fine. on my windows cygwin environment it still does not work (it seems some little script adaptions to be neccessary)...
but i do not mind for the target system is linux (i just wanted to test scripts on cygwin for i hadn't had a linux environment which is the case now).

thanks again for you suggestions.
Tim Holloway
Saloon Keeper

Joined: Jun 25, 2001
Posts: 16246
    
  21

Oops. You shoulda said.

cygwin isn't QUITE the same as native Linux, since it's a little bit of Windows and a little bit of Linux. Paths and path seperators, in particular can be a nuisance,

I think that there's an example of dealing with that sort of issue on the catalina.sh script that comes with Tomcat.


Customer surveys are for companies who didn't pay proper attention to begin with.
 
Consider Paul's rocket mass heater.
 
subject: different command-line startup on linux (vs. windows) not working