This week's book giveaway is in the OCAJP forum.
We're giving away four copies of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) and have Khalid A Mughal & Rolf W Rasmussen on-line!
See this thread for details.
Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

[Agile Java - Langr, p127] Class not found "sis.AllTests"

 
Mark Pawelek
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
[Agile Java - Langr, p127]

Working through the long tutorial, I've got to page 127. After creating the new directory structure, moving the files and refactoring, I can't run my java program. The first line compiles with no problems. [Appendix 1]

The 2nd line consistently gives an error message [Class not found "sis.AllTests"]


Appendix 1: Java compile and command to execute all tests:

javac -classpath .\sis;.\sis\studentinfo;.\sis\report;C:\Programs\junit4.9\junit-4.9.jar sis\studentinfo\*.java sis\report\*.java sis\*.java
java -classpath .\sis;.\sis\studentinfo;.\sis\report;C:\Programs\junit4.9\junit-4.9.jar junit.textui.TestRunner sis.AllTests


Appendix 2: New directory structure


--sis
|
+--- report
|
+--- studentinfo


Appendix 3: Source for the class that "can't be found". Note that the first line from Appendix 1 produces a .class file in the same directory [sis].

 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just FYI, if you give the root of a classpath, you don't need to give its sub-packages/dirs as well.

But the root cause is that you're giving the classpath as ".\sis" when it should just be ".", the current directory. Since the package of the class is "sis", it's going to look for the class in ".\sis\sis" as it's assuming ".\sis" is a root classpath, but it isn't: the current directory is.
 
Mark Pawelek
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks.

This worked:

javac -classpath .\sis;.\sis\studentinfo;.\sis\report;C:\Programs\junit4.9\junit-4.9.jar sis\studentinfo\*.java sis\report\*.java sis\*.java
java -classpath .\;C:\Programs\junit4.9\junit-4.9.jar junit.textui.TestRunner sis.AllTests

Nevertheless, I managed to get the ant build going as well so I no longer need the batch file.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic