How to import non-package class in JSP ?

We have develped an enterprise solution in java 1.3 . Some of the controller and controller helper classes donot have any package structure. So they are been kept in web_inf/classes. When any jsp tries to refrence these classes class not found exception arise.

One solution is to put these classes in package and write approprite import statement. But this involve lot of changes. Kindly suggest a solution which can have minimum impact.

I have even jared all these classes into a jar and put that jar in the class path. But still its not working.

[567 byte] By [sunilpratapsingha] at [2007-11-26 21:45:46]
# 1
Sorry. That's what you get for not using packages. Do it right the first time.
bckrispia at 2007-7-10 3:34:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2

It should not be web_inf , the case and the spelling matters it should be WEB-INF , make that correction and see if it works.

If not then, use an IDE to refactor your code.

Some good IDEs with refactoring capabilities are

IntelliJ IDEA - commercial

NetBeans - open source I think (not sure)

Eclipse Web Tools - also open source

Using packages is a good practice, and will make your application more understandable.

Message was edited by:

appy77

appy77a at 2007-7-10 3:34:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

Here is a fast dirty trick, make a package name to import and

simply replicate the classes into it, but if they can't operate

without the classes above you will need to refactor as the

person above said. note: "classes" in WEB-NF is the default

package so if you use

@ page import="Aclassname,Bclassname"

it should assume the classes default package.

nicephotoga at 2007-7-10 3:34:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 4
Since Java1.4 you cannot access classes in the 'unnamed" package from an named package. Sorry, but the only way to make it work is to put those classes into packages.Read all about the 'bugfix' here: http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4361575
evnafetsa at 2007-7-10 3:34:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 5
> Since Java1.4 you cannot access classes in the> 'unnamed" package from an named package. > Sorry, but the only way to make it work is to put> those classes into packages.I.E. : Do It Right The First Time
bckrispia at 2007-7-10 3:34:48 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 6

>

> I.E. : Do It Right The First Time

It's hard for newbies to do it right the first time, because they don't know what *right* is ... until they learn the hard way or by reading before attempting something more complex.

I agree one should make an attempt to follow coding conventions and good practices at a minimum, on of my bosses didn't care about coding conventions she wrote package names like this com.somepackage.MyPackage.anotherPackage

and wrote variable names like this

String MyStringVariable , instead of String myStringVariable

I was very surprised that she was my boss and not my peer.

appy77a at 2007-7-10 3:34:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 7

> >

> > I.E. : Do It Right The First Time

>

> It's hard for newbies to do it right the first time,

> because they don't know what *right* is ... until

> they learn the hard way or by reading before

> attempting something more complex.

>

@OP mentioned that putting everything in packages would be difficult because it would involve "A lot of changes". How did this mistake make it this far? The lack of packages would be an instant red flag in even the most rudimantary code review. The problem should have been nipped in the bud early on, but now, it's gotten to the point where fixing could involve a bit of effort.

bckrispia at 2007-7-10 3:34:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 8

Agreed ... if at all there was a code review.

Some projects have managers who don't understand anything about code but only want get things done - which ever way , just get it done by this deadline - .

And unfortunately, some senior /lead developers don't care either because they don't know any better about packages.

Because power sometimes rules over intellect situations like these arise.

I'm sure there are other problems on the project and not just packages.

I respect the fact that you are encouraging mandatory or even better coding practices, not many people do.

appy77a at 2007-7-10 3:34:49 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...