javac not generating class files when there are errors


javac not generating class files when there are errors



I'm a hobby coder using CodeAnywhere to allow me to, well, code anywhere without having to set up a development environment. It's admittedly not the fullest featured IDE, but it gets the job done. One limitation is that I can't use Ant or Maven, so I have to figure out how to build using plain old javac (via SSH).



So I've created a little bash script that creates a file with the relative paths to all the source files, and then pumps that into javac:


find -name *.java > classes.txt
javac @classes.txt



The first line works fine and generates the anticipated output. The second one also appears to work, and even gives me compile errors (which I was expecting). However, there are a few classes that should compile, but the corresponding class files are not generated. Is this anticipated behavior? Why does it work when I manually include multiple file names as arguments (even when I include ones that generate errors), but not when I use the @file notation?





Try javac $(find . -name "*.java"). You might also consider a different IDE that supports Maven, Ant, SBT or Gradle.
– Elliott Frisch
Jul 2 at 0:09


javac $(find . -name "*.java")





Not supporting a build tool (like ant or gradle) is actually a pretty big deal. Netbeans is simple and lightweight, and supports Java fully. I don't think it runs on a phone, but it runs on pretty much anything else.
– markspace
Jul 2 at 0:15





I guess javac stops the process when it has listed enough number of errors. Anyway when there is a compile time failure, it does not matter even if it generates classes for java files which are fine. You will not run the application unless the application compiles completely.
– gagan singh
Jul 2 at 0:21





@markspace I use CodeAnywhere so I can code from my phone. If you can find another way for me to do that easily, I'm open.
– Stephen Carlson
Jul 2 at 0:24






Do the file names appear in the same order in classes.txt as what you have when you include them directly in the command line? It would help if you could give us a short, specific example (say, with two files, including full source) where it behaves differently when using the @file syntax and when listing the files directly on the command line.
– Ted Hopp
Jul 2 at 0:36



classes.txt


@file




1 Answer
1



Perhaps this can help:



find . -name '*.java' | xargs javac


find . -name '*.java' | xargs javac



Adding an alias makes it easier:



alias javac-all="find . -name '*.java' | xargs javac"


alias javac-all="find . -name '*.java' | xargs javac"



So you only need to invoke javac-all to compile all Java files in the current directory and below.


javac-all



NOTE 1: I don't know if you can edit your .bashrc in CodeAnywhere.


.bashrc



NOTE 2: Some tweaking can improve your experience, e.g. writing all class files to a separate output directory (see -d option), etc.


-d



NOTE 3: Be aware of package directories.





This does all files in the current directory and below, which could be exactly what he wants, but it isn't what it says in your answer.
– EJP
Jul 2 at 1:57






@EJP given that your comment was regarding an edit and has been reflected in the answer, please remove it.
– Hossein Pursultani
Jul 3 at 13:25






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Popular posts from this blog

How to add background colour in existing image using Swift?

Moria Casán

How to make file upload 'Required' in Contact Form 7?