6 Replies Latest reply: Jan 4, 2008 7:25 AM by 807601 RSS

    How to compile ALL java files in OR UNDER a given directory?

    800308
      G'Day Folkies,

      At face value, TikeSwing looks like the money shot for enforcing MVC in my version of minesweeper http://forum.java.sun.com/thread.jspa?forumID=54&threadID=5248903

      I'm attempting to build the "Hello World" example which comes with TikeSwing.
      http://www.javaworld.com/javaworld/jw-06-2005/jw-0620-tikeswing.html

      It compiles ok
      C:\Java\lib\tikeswing-1.5\example\src\fi\mmm\hello>javac -d C:\Java\home\classes -cp C:\Java\lib\tikeswing-1.5\src;C:\Java\lib\tikes
      wing-1.5\lib\commons-beanutils.jar;C:\Java\lib\tikeswing-1.5\lib\commons-lang-2.0.jar;C:\Java\lib\tikeswing-1.5\lib\commons-logging.
      jar;C:\Java\lib\tikeswing-1.5\lib\log4j.jar;C:\Java\lib\tikeswing-1.5\example\src;. HelloApplication.java
      Note: Some input files use unchecked or unsafe operations.
      Note: Recompile with -Xlint:unchecked for details.
      But it doesn't run
      I presume that javac isn't detecting all dependancies, presumably because Tike "decouples M from V from C" using reflections.
      C:\Java\lib\tikeswing-1.5\example\src\fi\mmm\hello>java -cp C:\Java\home\classes;C:\Java\lib\tikeswing-1.5\lib\commons-beanutils.jar
      ;C:\Java\lib\tikeswing-1.5\lib\commons-lang-2.0.jar;C:\Java\lib\tikeswing-1.5\lib\commons-logging.jar;C:\Java\lib\tikeswing-1.5\lib\
      log4j.jar;C:\Java\lib\tikeswing-1.5\example\src;C:\Java\lib\tikeswing-1.5\src;. fi.mmm.hello.HelloApplication
      Exception in thread "main" java.lang.NoClassDefFoundError: fi/mmm/yhteinen/swing/core/component/YFrame
              at java.lang.ClassLoader.defineClass1(Native Method)
              at java.lang.ClassLoader.defineClass(ClassLoader.java:620)
              at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:124)
              at java.net.URLClassLoader.defineClass(URLClassLoader.java:260)
              at java.net.URLClassLoader.access$000(URLClassLoader.java:56)
              at java.net.URLClassLoader$1.run(URLClassLoader.java:195)
              at java.security.AccessController.doPrivileged(Native Method)
              at java.net.URLClassLoader.findClass(URLClassLoader.java:188)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
              at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:276)
              at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
              at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
              at fi.mmm.hello.HelloController.<init>(HelloController.java:8)
              at fi.mmm.hello.HelloApplication.main(HelloApplication.java:8)
      So, Please, is there a way of telling javac to just build *.java in or under C:\Java\lib\tikeswing-1.5\src\ ... regardless of dependencies?

      Thanking You for any thoughts. Keith.
        • 1. Re: How to compile ALL java files in OR UNDER a given directory?
          3004
          I only read your title, not your message.

          You have to give javac the names of all the files. On unix, you could do something like
          javac $(find * -name \*.java)
          I don't know the cmd.exe equivalent.

          You may also need to explicitly tell javac the classpath to use. And I don't even remember what the -soucepath argument is for anymore. It's been so long since I've directly used javac for anything more than no-package, few-source-file toy programs.

          If it's more than a few files in 1 or 2 directories, I'd look into ant. If the number of libraries gets large, or you have to maintain lots of versions, or your dependencies on specific versions of certain libs gets complex, you might also want to look into maven. It's more complex than ant, but has more features, including some that go beyond just building your apaplication.
          • 2. Re: How to compile ALL java files in OR UNDER a given directory?
            807601
            Go the directory and the following is the command to be entered.

            javac -d . *.java
            • 3. Re: How to compile ALL java files in OR UNDER a given directory?
              800308
              jverd & vimalkumar,

              Thank you both... I was hoping there was an "easy way" to do what I supposed was/is a common problem... but google found diddly (probably coz I didn't even know the key words to search for)... so... I shall write a wee batch script (or maybe an ant script) to do the job, and post it once I get it working.

              PS: This much I know: find . -name *.java == dir /s /b *.java

              Thanx again.
              • 4. Re: How to compile ALL java files in OR UNDER a given directory?
                800308
                FYI.... Here's the quick and dirty, slower than a wet week, ugly, but effective batch script
                set TIKE=C:\Java\lib\tikeswing-1.5
                set SRC=%TIKE%\src
                set LIB=%TIKE%\lib
                set CLASSPATH=%LIB%\commons-beanutils.jar;%LIB%\commons-lang-2.0.jar;%LIB%\commons-logging.jar;%LIB%\log4j.jar;.
                
                FOR /R %SRC% %%f IN (*.java) DO javac -d C:\Java\home\classes -cp %CLASSPATH% %%f
                
                @ECHO OFF
                REM http://www.robvanderwoude.com/ntfor.html
                REM Walks the directory tree rooted at [drive:]path, executing the FOR statement
                REM in each directory of the tree. If no directory specification is specified 
                REM after /R then the current directory is assumed. If set is just a single 
                REM period (.) character then it will just enumerate the directory tree.
                I can't figure out how do the equivalent of javac `dir /s /b *.java` (ie: cmd doesn't seem to have a built-in facility for expanding the results of a command into the command line) which would be a lot quicker and cleaner.

                Cheers all. Thanx for the help. I appreciate it.
                • 5. Re: How to compile ALL java files in OR UNDER a given directory?
                  807601
                  corlettk wrote:
                  jverd & vimalkumar,

                  Thank you both... I was hoping there was an "easy way" to do what I supposed was/is a common problem
                  Ant.

                  http://ant.apache.org/.
                  • 6. Re: How to compile ALL java files in OR UNDER a given directory?
                    807601
                    cotton.m wrote:
                    corlettk wrote:
                    jverd & vimalkumar,

                    Thank you both... I was hoping there was an "easy way" to do what I supposed was/is a common problem
                    Ant.

                    http://ant.apache.org/.
                    I'll see your Ant, and raise you one Maven

                    http://maven.apache.org

                    :-)