NEWARK, N.J. (AP) _ Libraries should not be expected to serve as homeless shelters, but they can not exclude people based on personal appearance and hygiene, a judge has ruled.

U.S. District Judge H. Lee Sarokin ruled that regulations adopted by a New Jersey library were unconstitutional because they were overly broad and violated the First Amendment by curtailing access to books, newspapers and other library materials.

''The danger in excluding anyone from a public building because their appearance or hygiene is obnoxious to others is self-evident,'' the judge wrote in his opinion. ''The danger becomes insidious if the conditions complained of are borne of poverty.''

Attorneys in the case said it was the first they knew of that dealt with the right of access to public places for homeless people.

The rules were imposed by the Joint Free Public Library of Morristown and Morris Township. Attorneys for the library had argued that its more cleanly patrons were falling ill from the smells of the homeless and being bothered by their staring.

The judge said that while he agreed libraries should not be transformed into shelters, regulations governing use need to be specific and not left to ''the whim or personal vagaries of the person in charge.''

''One person's hay fever is another person's ambrosia,'' Sarokin said. ''Jeans with holes represent inappropriate dress to some and high fashion to others.''

The logical end to the right to speak and to publish, the judge said, is the right to be heard and to read.

The American Civil Liberties Union and attorneys for a homeless man, Richard Kreimer, challenged the rules, which prohibited loitering, staring at people and hygiene that is a nuisance to other patrons.

Those who stared, stunk or didn't have reading material in front of them could be thrown out, as Kreimer was several times.

''I thought Judge Sarokin's ruling was very fair, very honest, very compassionate, very legal and very socially correct,'' Kreimer said.

Linda Wallace, spokeswoman for the American Library Association, which has 50,000 members, said that they have approved policies calling for libraries to promote equal access to all people.

Some libraries have opened special rooms for the homeless and have visited homeless shelters to provide reading material, she said.

Kreimer's attorney, Bruce Rosen, said he agreed libraries cannot be used as shelters, but said discrimination based on social status is as evil as any other form.

The library's attorney, Clifford Starrett, did not return a telephone message left Wednesday by The Associated Press. Library director Nancy Byouk also did not return a telephone message.