Converting Java batch file from windows to unix format

A

arun.hallan

My java application includes source files in packages, and jar
library's in a lib directory.
I have created a windows batch file that compiles all and then runs the
application.
It is in the form of "javac classpath[jar files] [all package folders]
java classpath[jarfiles] [MainClass]"
The batch file is as so:


___________________________________________________________________
javac -classpath
"lib\jdom.jar;lib\ant.jar;lib\ant-launcher.jar;lib\liquidlnf.jar;lib\tools.jar"
antigen\builders\*.java antigen\config\*.java

antigen\datastructure\*.java antigen\gui\*.java antigen\io\*.java
antigen\listeners\*.java antigen\wizard\*.java

java -classpath
".;lib\jdom.jar;lib\ant.jar;lib\ant-launcher.jar;lib\liquidlnf.jar;lib\tools.jar"
antigen.config.Antigen
____________________________________________________________________



I have attempted to create a unix version of this (well i have tried to
make it work in mac os 10).
I have created a script that will run when i call "source BatchFile"
from the command prompt.
The script is as follows:


______________________________________________________________________
javac -classpath
/lib/jdom.jar:/lib/ant.jar:/lib/ant-launcher.jar:/lib/liquidlnf.jar:/lib/tools.jar
antigen/builders/*.java antigen/config/*.java

antigen/datastructure/*.java antigen/gui/*.java antigen/io/*.java
antigen/listeners/*.java antigen/wizard/*.java

java -classpath
".;/lib/jdom.jar;/lib/ant.jar;/lib/ant-launcher.jar;/lib/liquidlnf.jar;/lib/tools.jar"
antigen.config.Antigen
______________________________________________________________________


Java attempts to compile the source, but it doesnt include the jar
files in the classpath. Therefore i get a lot of library specific
errors.
Does anyone know why? Does unix work with the classpath differently?
Can someone help me create a batch file for a unix system.

Thanks



PS I do not want to use a build tool, as the whole point of the
application is to allow use of ant without installing it.
 
L

Lans Redmond

in unix you need to set the classpath
example

export CLASSPATH=myjar.jar:another.jar

so you will need to add this to your script
 
E

EricF

Lans is correct but this may help ...

In *nix, the path and classpath separator is :
On Windows, it is ;

HTH

Eric

"Lans said:
in unix you need to set the classpath
example

export CLASSPATH=myjar.jar:another.jar

so you will need to add this to your script
My java application includes source files in packages, and jar
library's in a lib directory.
I have created a windows batch file that compiles all and then runs the
application.
It is in the form of "javac classpath[jar files] [all package folders]
java classpath[jarfiles] [MainClass]"
The batch file is as so:


___________________________________________________________________
javac -classpath
"lib\jdom.jar;lib\ant.jar;lib\ant-launcher.jar;lib\liquidlnf.jar;lib\tools.j
ar"
antigen\builders\*.java antigen\config\*.java

antigen\datastructure\*.java antigen\gui\*.java antigen\io\*.java
antigen\listeners\*.java antigen\wizard\*.java

java -classpath
".;lib\jdom.jar;lib\ant.jar;lib\ant-launcher.jar;lib\liquidlnf.jar;lib\tools
..jar"
antigen.config.Antigen
____________________________________________________________________



I have attempted to create a unix version of this (well i have tried to
make it work in mac os 10).
I have created a script that will run when i call "source BatchFile"
from the command prompt.
The script is as follows:


______________________________________________________________________
javac -classpath
/lib/jdom.jar:/lib/ant.jar:/lib/ant-launcher.jar:/lib/liquidlnf.jar:/lib/too
ls.jar
antigen/builders/*.java antigen/config/*.java

antigen/datastructure/*.java antigen/gui/*.java antigen/io/*.java
antigen/listeners/*.java antigen/wizard/*.java

java -classpath
".;/lib/jdom.jar;/lib/ant.jar;/lib/ant-launcher.jar;/lib/liquidlnf.jar;/lib/
tools.jar"
antigen.config.Antigen
______________________________________________________________________


Java attempts to compile the source, but it doesnt include the jar
files in the classpath. Therefore i get a lot of library specific
errors.
Does anyone know why? Does unix work with the classpath differently?
Can someone help me create a batch file for a unix system.

Thanks



PS I do not want to use a build tool, as the whole point of the
application is to allow use of ant without installing it.
 
J

John B. Matthews

______________________________________________________________________
javac -classpath
/lib/jdom.jar:/lib/ant.jar:/lib/ant-launcher.jar:/lib/liquidlnf.jar:/lib/tools
.jar
antigen/builders/*.java antigen/config/*.java

antigen/datastructure/*.java antigen/gui/*.java antigen/io/*.java
antigen/listeners/*.java antigen/wizard/*.java

java -classpath
".;/lib/jdom.jar;/lib/ant.jar;/lib/ant-launcher.jar;/lib/liquidlnf.jar;/lib/to
ols.jar"
antigen.config.Antigen
______________________________________________________________________

Java attempts to compile the source, but it doesnt include the jar
files in the classpath. Therefore i get a lot of library specific
errors.
[...]

Under unix, the classpath separator is ":", not";". Also, the
current path "." must be in the classpath for both compilation and
execution. I may be helpful to define your classpath once and use it
as needed:

#!/bin/sh
CLASSPATH=.:/lib/jdom.jar:/lib/ant.jar:...
javac -classpath $CLASSPATH antigen/builders/*.java ...
java -classpath $CLASSPATH antigen.config.Antigen
 
N

Nigel Wade

Lans said:
in unix you need to set the classpath
example

export CLASSPATH=myjar.jar:another.jar

No you don't. You can set the classpath on the javac command in exactly the
same way as you can in any other supported OS.
 
N

Nigel Wade

My java application includes source files in packages, and jar
library's in a lib directory.
I have created a windows batch file that compiles all and then runs the
application.
It is in the form of "javac classpath[jar files] [all package folders]
java classpath[jarfiles] [MainClass]"
The batch file is as so:


___________________________________________________________________
javac -classpath
"lib\jdom.jar;lib\ant.jar;lib\ant-launcher.jar;lib\liquidlnf.jar;lib\tools.jar"
antigen\builders\*.java antigen\config\*.java

antigen\datastructure\*.java antigen\gui\*.java antigen\io\*.java
antigen\listeners\*.java antigen\wizard\*.java

java -classpath
".;lib\jdom.jar;lib\ant.jar;lib\ant-launcher.jar;lib\liquidlnf.jar;lib\tools.jar"
antigen.config.Antigen
____________________________________________________________________


These jar files have been specified with a relave path.

I have attempted to create a unix version of this (well i have tried to
make it work in mac os 10).
I have created a script that will run when i call "source BatchFile"
from the command prompt.
The script is as follows:


______________________________________________________________________
javac -classpath
/lib/jdom.jar:/lib/ant.jar:/lib/ant-launcher.jar:/lib/liquidlnf.jar:/lib/tools.jar
antigen/builders/*.java antigen/config/*.java

antigen/datastructure/*.java antigen/gui/*.java antigen/io/*.java
antigen/listeners/*.java antigen/wizard/*.java

java -classpath
".;/lib/jdom.jar;/lib/ant.jar;/lib/ant-launcher.jar;/lib/liquidlnf.jar;/lib/tools.jar"
antigen.config.Antigen
______________________________________________________________________

These jar files have been specified with an absolute path. Are you jar files
in the /lib directory, or in the lib sub-directory of the current working
directory?

Also, change the semi-colons into colons in all the command lines. A
semi-colon in UNIX shell is a command-line separator.
Java attempts to compile the source, but it doesnt include the jar
files in the classpath. Therefore i get a lot of library specific
errors.
Does anyone know why? Does unix work with the classpath differently?

No, it works in exactly the same way with the classpath, except the delimter
is a colon not a semi-colon.
 
A

Aquila Deus

My java application includes source files in packages, and jar
library's in a lib directory.
I have created a windows batch file that compiles all and then runs the
application.
It is in the form of "javac classpath[jar files] [all package folders]
java classpath[jarfiles] [MainClass]"
The batch file is as so:


___________________________________________________________________
javac -classpath
"lib\jdom.jar;lib\ant.jar;lib\ant-launcher.jar;lib\liquidlnf.jar;lib\tools.jar"
antigen\builders\*.java antigen\config\*.java

antigen\datastructure\*.java antigen\gui\*.java antigen\io\*.java
antigen\listeners\*.java antigen\wizard\*.java

java -classpath
".;lib\jdom.jar;lib\ant.jar;lib\ant-launcher.jar;lib\liquidlnf.jar;lib\tools.jar"
antigen.config.Antigen
____________________________________________________________________



I have attempted to create a unix version of this (well i have tried to
make it work in mac os 10).
I have created a script that will run when i call "source BatchFile"
from the command prompt.
The script is as follows:


______________________________________________________________________
javac -classpath
/lib/jdom.jar:/lib/ant.jar:/lib/ant-launcher.jar:/lib/liquidlnf.jar:/lib/tools.jar
antigen/builders/*.java antigen/config/*.java

antigen/datastructure/*.java antigen/gui/*.java antigen/io/*.java
antigen/listeners/*.java antigen/wizard/*.java

java -classpath
".;/lib/jdom.jar;/lib/ant.jar;/lib/ant-launcher.jar;/lib/liquidlnf.jar;/lib/tools.jar"
antigen.config.Antigen

extract & dump all jars into jre/classes, then you won't need to deal
with classpath anymore :)
 
S

Steve W. Jackson

Lans Redmond said:
in unix you need to set the classpath
example

export CLASSPATH=myjar.jar:another.jar

so you will need to add this to your script

Not true. You do not NEED to set the CLASSPATH variable on any OS.
I've got my app running on Windows, Mac OS X and Linux and NONE of them
have a CLASSPATH variable set.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top