Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

quick question on excluding certain files from javac...

 
Grary Stimon
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I hoped to avoid a potentially lengthy and frustrating detour into regex syntax land and ask the following (I hope) simple question here...

How do I exclude compilation of java files with a certain string in their file names? In my case, I want to javac all files in a package except those containing the string "Test", e.g., RmiImplTest.java.

I hoped the experienced hands on the Ranch would know this cold!

Thanks,

Grary
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

I am assuming you are looking into writing a batch file or shellscript? if so, you need to give more details, such as OS, etc.

Henry
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Peculiar. Most people have the opposite problem, namely how to ensure that a certain file is compiled at all. If I remember correctly, the javac tool assumes that .java files imported from packages have already been compiled. It doesn't seem to compile them unless you instruct it to compile them.

How about

javac mypackage/*Test.java

?

And this is too difficult for beginners. Moving.
 
Grary Stimon
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your replies.

No, I'm not writing a script. In development, I had wanted to test certain package-access class behaviors, so I included test files inside some packages. I do not want those test classes included in the final jar. So, I just want to exclude from my compilation via javac any .java files with the segment "Test" in their filename. So, I'm looking for some regex that does that.

Thanks for any further comment.

Thanks again,

Grary
 
Henry Wong
author
Marshal
Pie
Posts: 20997
76
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, I'm not writing a script.


Then you need to elaborate. Just exactly what are you using to build the jar files?

Henry
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Exclude them without Test. Oh sorry, I misread the original post.

How about what follows?

. . .


Find the classic Daconta paper about Runtime.exec(). Go through your package folder with the methods of the File class. Find all the file names. You can probably scan them with the indexOf method of String.
Then compile those which pass the test, using Runtime.exec().
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're using Ant this is trivial. Or Unix-like shell.

I'm more used to seeing test code in a completely separate directory, which is the easiest solution of all.
 
Grary Stimon
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks all for your comments. It seems that I should start using Ant.

Grary
 
Campbell Ritchie
Sheriff
Posts: 48652
56
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're welcome
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic