Search code examples
javashellbatch-filecompilationjavac

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/PgElementSet_Menu.java:15: 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
@pause

Any ideas?


Solution

  • This shall work for you

    for i in `ls jars/*.jar`; 
    do 
        export CLASSPATH=$CLASSPATH:$i; 
    done
    export CLASSPATH=.:$CLASSPATH
    javac `find * -name *.java`