Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JavaBean not instantiating

 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Guys

I am trying to instantiate a JavaBean in my action class but it doesnt work. This is what I have in my classes/beans directory:



I am trying to use it in the following action class as follows (this file is in the classes directory):



When I compile the AddNew action I get an error that the beans.* package does not exist and that "testBean" cannot be found.

Do I need to edit the struts.xml file or something?
[ December 19, 2008: Message edited by: shaf maff ]
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your compilation environment is not set up correctly.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do I recitify it then ?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Set it up correctly?

Not knowing how it's set up now, or how you're compiling, or your directory structure, or anything else, it's hard to know how to fix it. In any case, it isn't a Struts issue, it's a compilation/classpath issue.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well thats the thing, I have another project on the same server which isnt using struts and it works perfectly fine using the exact same method. I dont know what possibly could be wrong, unless I need to specify something in the struts.xml file.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Except that it's not complaining about anything related to Struts: it's complaining that it can't find *your* package.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I know - That is why I am baffled. The bean is located in classes/beans/testBean.java - It is set as package beans;

So if I want to include it in my action class then I would use import beans.*; or import beans.testBean; none of which work. Like I said I have the exact some bean setup with my other projects and they work perfectly fine.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Like I said--without any more info it's impossible to help.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok - Well, as you already know the dirs for the beans is /classes/beans/*

I compile as follows: javac beans/testBean.java

I dont know what exactly your looking for by classpath.
[ December 19, 2008: Message edited by: shaf maff ]
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's not complaining when you compile the bean class. It's complaining when you compile the *action* class. It'd be more helpful to tell me about *that*, although I'm not convinced the Struts forum is the best place for basic Java compilation issues.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgot to add the compiling method:

javac -classpath C:/struts/xwork-2.0.7.jar ActionClass.java
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
...

This could go much faster.

You still haven't said how you're compiling it or what your classpath is.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check the post above yours.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't have your compiled bean class on the classpath.
 
shaf maff
Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You know it really sucks being a newbie. Thanks, it works now!
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Gotta start somewhere
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic