Thijser Thijser - 1 year ago 70
Bash Question

Compiling java code with shellscript, including several files(.jars .class)

I have the following code to compile a java program in shellscript:

javac workshop/*.java -cp jars/\*
javac menu/*.java -cp jars/\* -cp workshop/

This code should compile everything java file in workshop and include everything in jars and then it should compile everything in menu while including every jar file in jars and every .class file in workshop.

However it's not as the second command gives me the error

menu/ error: package workshop does not exist
import workshop.*;

the package workshop is in the workspace.MyWorkShop.class (amongst others).

Now I'm probably doing somethign stupid but I'm not sure what I'm doing wrong, the code is based on a .bat files which does the following (and works on windows machines)

javac -classpath jars\javaview.jar;jars\jvx.jar;. workshop\*.java
javac -classpath jars\javaview.jar;jars\jvx.jar;. menu\*.java

Any ideas?

Answer Source

This shall work for you

for i in `ls jars/*.jar`; 
    export CLASSPATH=$CLASSPATH:$i; 
javac `find * -name *.java`
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download