• Post Reply Bookmark Topic Watch Topic
  • New Topic

having problems compiling code from Craig Walls book

 
Kevin Simonson
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay, I read some of the articles posted on this forum, and they seem to indicate that the fourth edition of Craig Walls' book Spring in Action is a good book for someone unfamiliar with Spring to read to get to know how to use Spring. So I've read chapter one, and in section 2.2.1 of chapter two it lists four sections of Java code, namely:

and

and

and, finally

I have a "Src" directory, and a "soundsystem" directory beneath it, and all four of the files listed above are in the "soundsystem" directory. From the "Src" directory I compiled the interfact just fine, and I verified that there's a "CompactDisc.class" in directory "Bin\soundsystem". But when I try to execute "javac -d ..\Bin soundsystem\SgtPeppers.java" I get error messages:

soundsystem\SgtPeppers.java:2: error: package org.springframework.stereotype doe
s not exist
import org.springframework.stereotype.Component;
                                     ^
soundsystem\SgtPeppers.java:4: error: cannot find symbol
@Component
^
  symbol: class Component
2 errors

Apparently my compiler can't find package org.springframework.stereotype. Is there something I have to do to get visibility to this package, so I can use its Component annotation?
 
Mark Case
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

I can't tell from the information provided , the way you have structured your project ... i.e.; packages layout..

But in any case, try

package org.springframework.stereotype.soundsystem on the first line of each of the files below.

Hope this helps
 
Kevin Simonson
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Case wrote:Hi

I can't tell from the information provided , the way you have structured your project ... i.e.; packages layout..

But in any case, try

package org.springframework.stereotype.soundsystem on the first line of each of the files below.

Hope this helps

Thanks for trying to help me but, alas, it did not help. My files are now:

and

and they both reside in my "Spr\Src\soundsystem" directory. The other two files I mentioned previously are also in that directory. The "soundsystem" directory is the only contents of "Spr\Src" and the only contents of "Spr" are "Src" and "Bin". When I started out, "Spr\Bin" was empty. While in the "Spr" directory, if I execute "javac -d Bin Src\soundsystem\CompactDisc.java", then that command succeeds, and that command brings into existence a "Spr\Bin\org" directory, a "Spr\Bin\org\springframework" directory, a "Spr\Bin\org\springframework\stereotype" directory, and a "Spr\Bin\org\springframework\stereotype\soundsystem" directory, and it creates a "CompactDisc.class" file in that last directory. But then when I execute "java -d Bin -cp Bin Src\soundsystem\SgtPeppers.java", I get the same complaint as I got before. My compiler says it cannot find symbol {Component} in package {stereotype} and, of course, where my code uses the "@Component" annotation, my compiler complains once again that it cannot find the symbol {Component}.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65678
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mark Case wrote:But in any case, try

package org.springframework.stereotype.soundsystem on the first line of each of the files below.


No, no, no, no no!

You shouldn't put your packages in the Spring packages. That's nonsense.

What needs to happen is for the jar containing the missing class to be part of the compilation classpath.
 
Kevin Simonson
Ranch Hand
Posts: 197
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:
Mark Case wrote:But in any case, try

package org.springframework.stereotype.soundsystem on the first line of each of the files below.


No, no, no, no no!

You shouldn't put your packages in the Spring packages. That's nonsense.

What needs to happen is for the hat containing the missing class to be part of the compilation classpath.

How do I get "the hat containing the missing class to be part of the compilation classpath"?
 
Campbell Ritchie
Marshal
Posts: 53184
124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to cap the source.
Either that or Bear has gone down with a bad attack of the predictive texts. I think it is a strange spelling of jar.
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 15767
74
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, you have to include the necessary Spring jar files in the classpath when you compile and run your application.

I don't have the book, but I can't imagine that it does not tell you how to do this.

Because Spring depends on other libraries, that in turn depend on other libraries, this will also be a lot easier when you use a build tool such as Maven for managing the dependencies of your project. When your Maven project is setup correctly, Maven will automatically download all the necessary jar files and make sure they are on the classpath when you compile and run your application. You can do it manually without Maven, but that means you have to find out exactly which jar files you need, and then make sure yourself that they are included in the classpath when compiling and running your application.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65678
129
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:You need to cap the source.
Either that or Bear has gone down with a bad attack of the predictive texts. I think it is a strange spelling of jar.

Dang autocorrect! 
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!