anjanb
anjanb

Reputation: 13867

what gotchas using cygwin for java development?

We're using windows, linux and solaris for our development. Currently, on windows, we're using the windows shell and batch(.BAT) scripts to run build related scripts. We use subversion as our version control tool.

We want to standardize on bash scripts so that they work same on Windows, Linux and solaris. What are the issues I can expect if I want to move the windows dev environment from CMD.EXE to cygwin ?

Also, we're currently using Ant but will be moving to maven very soon. eclipse is our dev environment.

If it helps at all, we're developing multi-threaded servers -- the product runs in production only on solaris or linux(not on windows).

Thank you,

Upvotes: 0

Views: 442

Answers (3)

artbristol
artbristol

Reputation: 32407

It's easier not to use shell scripts or batch files at all. Maven should be able to do everything you would put in a script, and it's cross-platform.

Upvotes: 3

Mike Samuel
Mike Samuel

Reputation: 120506

I did this once and ran into a few kinds of trouble detailed below. If you separate all your environment declaration and tool paths out into one file with sanity checks, and you're judicious in your use of symlinks you should be able to maintain one build across both environments.

Windows uses ; as a path separator instead of :

If your scripts use PATH and CLASSPATH and other environment variables inherited from the windows environment, then scripts that assume they can split/join paths on : are going to be confused.

Likewise, paths that contain semicolons are confusing. Few scripts do this since semicolon is a special character in bash anyway, but it's good to keep in the back of your mind when debugging.

Symlinks kind of work

Some build systems I've seen build trees of symlinks. Symlinks on cygwin work fine with tools compiled for cygwin, but if you pass a symlink to a java program and expect it to dereference it automatically then you'll probably be surprised.

There is no single root directory

Carefully written java programs can work around the problem that there is no single / and binaries compiled/bundled with cygwin can deal because there's the fake /cygdrive/ directory and a fake / but other tools might not.

This hasn't been a real problem for me since build scripts shouldn't traverse from / but I mention it as another source of confusion.

Upvotes: 2

AngerClown
AngerClown

Reputation: 6229

As long as your cygwin scripts do not need any OS specific programs, cygwin should translate pretty faithfully to Unix. The harder parts will be things like user creation and directory permissions, assuming your scripts need to install, not just run.

Your biggest issue is probably going to be directories.

  1. Standardize on using / separators in all your scripts (bash and ANT) and in Java, it will make your life much easier. Java on Windows (including ANT) is smart enough to parse something like C:/Program Files/myprogram correctly.
  2. Avoid directory names with spaces if possible.
  3. Use the cygwin /cygdrive/c notation instead of C:/ in your scripts.

For Eclipse, I would also standardize on UTF-8 and Unix newlines in all your sources. See Preferences -> General -> Workspace, Preferences -> Web -> (CSS | HTML | JSP Files) and Preferences -> XML -> XMLFiles.

A final consideration is how you want to execute scripts in Cygwin. You can either have a batch file that calls the script via bash.exe or you can just put cygwin in your path and execute bash directly.

Upvotes: 2

Related Questions