aspose file tools*
The moose likes Struts and the fly likes JavaBean not instantiating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "JavaBean not instantiating" Watch "JavaBean not instantiating" New topic
Author

JavaBean not instantiating

shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
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

Joined: Sep 29, 2008
Posts: 12617

Your compilation environment is not set up correctly.
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
How do I recitify it then ?
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 07, 2008
Posts: 180
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 07, 2008
Posts: 180
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

Joined: Sep 29, 2008
Posts: 12617

Like I said--without any more info it's impossible to help.
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
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

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Sep 07, 2008
Posts: 180
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Forgot to add the compiling method:

javac -classpath C:/struts/xwork-2.0.7.jar ActionClass.java
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

...

This could go much faster.

You still haven't said how you're compiling it or what your classpath is.
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
Check the post above yours.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You don't have your compiled bean class on the classpath.
shaf maff
Ranch Hand

Joined: Sep 07, 2008
Posts: 180
You know it really sucks being a newbie. Thanks, it works now!
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Gotta start somewhere
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JavaBean not instantiating