This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

Bug 201785 - Web App does not find Library Classes
Summary: Web App does not find Library Classes
Status: VERIFIED FIXED
Alias: None
Product: javaee
Classification: Unclassified
Component: Web Project (show other bugs)
Version: 7.0.1
Hardware: PC Windows Vista
: P2 normal (vote)
Assignee: David Konecny
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2011-09-07 22:40 UTC by bht
Modified: 2011-11-24 12:31 UTC (History)
0 users

See Also:
Issue Type: DEFECT
Exception Reporter:


Attachments
Empty classes package tree (9.91 KB, image/gif)
2011-09-08 15:30 UTC, bht
Details

Note You need to log in before you can comment on or make changes to this bug.
Description bht 2011-09-07 22:40:23 UTC
Product Version: NetBeans IDE 7.0.1 (Build 201107282000)
Java: 1.6.0_25; Java HotSpot(TM) Client VM 20.0-b11

How to reproduce:

File|New Project|Samples|Java Web|Servlet Stateless (Java EE 6)|Next|Finish

Server is GlassFish 3.x

Project Window|ServletStateless|Run

This works ok.

File|New Project|Java|Java Class Library|Next|JavaLibrary1|Finish
Project Window|JavaLibrary1|Source Packages|new|Java Package|test
Project Window|JavaLibrary1|Source Packages|test|New|Java Class|TestClass

    public static String getString(){
        return "TestString";
    }
Project Window|JavaLibrary1|Build

Menu|Tools|Libraries|New Library|TestLibrary
Classpath|Add Jar/Folder|<your project folder>JavaLibrary1\build\classes|OK

Project Window|ServletStateless|Properties|Libraries|Add Library|Test Library|Add Library|OK


In project ServletStateless, edit StatelessSessionBean

Replace
    return "Hello, " + name + "!\n";
with
    return TestClass.getString() + ", Hello, " + name + "!\n";        
Fix imports.

Project Window|ServletStateless|Run

java.lang.ClassNotFoundException: test.TestClass
Comment 1 Vince Kraemer 2011-09-08 00:02:48 UTC
I created a web app/library project that I targeted at tomcat using similar steps.

I ran into the same result.

So, it probably isn't a server-plugin/run-time issue.

I think the web app project's build breaks an assumption about the content of a web-apps WEB-INF/lib directory.

There are supposed to be jars under WEB-INF/lib...

I see a directories and class files under PROJECT/build/web/WEB-INF/lib when I follow these steps.

So, it seems like it is a web-app project issue.

The fix is to create the library based on the JAR resulting from the build of JavaLibrary1 project instead of build directory of the javaLibrary1 project.

The problem seems to be the result of poor error checking when the web-app project is building.

There is  a work-around... so this really isn't a p1.
Comment 2 bht 2011-09-08 01:50:11 UTC
The library manager tool lets me build a library with either jar files or class file directories.

A web project lets me attach a library that by extension has either jar files or class file directories.

So if the convention for the lib directory of the web project is that it must contain only jar files not class directories then the build process for a web project could create the jar files and print a warning that it does this because it slows down the build process.
Comment 3 bht 2011-09-08 05:32:32 UTC
Alternatively, classes from libraries could be copied to the WEB-INF/classes directory, which I think happens if simple jar files are added to the project libraries.
Comment 4 bht 2011-09-08 15:28:42 UTC
A more detailed description of a scenario where classes in Libraries are not found:

In project ServletStateless, create a directory " classes" in the project directory.

Extract into the classes directory the jar file from the NetBeans installation:

C:\Program Files\NetBeans 7.0.1\enterprise\modules\ext\jsf-1_2\commons-collections.jar

Add the classes directory to libraries:
Project Window|ServletStateless|Properties|Libraries|Add JAR/Folder|Add classes directory

Add to StatelessSessionBean: ArrayStack arrayStack = new ArrayStack();

Run the project, submit query.

java.lang.NoClassDefFoundError: org/apache/commons/collections/ArrayStack

In the Files window, expand the project. In my case, there are only empty directories (see attached gif file)

Deploy the project.

In my case, this copies the classes and submit works.
Comment 5 bht 2011-09-08 15:30:12 UTC
Created attachment 110541 [details]
Empty classes package tree
Comment 6 David Konecny 2011-09-15 21:20:49 UTC
Thanks. Valid issue. Workaround is to add directly classes folder to classpath instead of using library.

f2d4a7403ef9
Comment 7 Quality Engineering 2011-09-17 14:23:14 UTC
Integrated into 'main-golden'
Changeset: http://hg.netbeans.org/main-golden/rev/f2d4a7403ef9
User: David Konecny <dkonecny@netbeans.org>
Log: #201785 - Web App does not find Library Classes