How do you import a Java Class Library into a Java

2019-08-13 20:51发布

问题:

I've already tried the options "Add folder...", "Add Library...", and "Add JAR/Folder...", but it's not working this time -- I've done this several times before without any problems.

I've also tried to add the folder / JAR file (.war-file) manually to the projects properties in every thinkable way, but still no success.

And so far, Google hasn't helped either..

Any help would really be appreciated.

(This is for a Java Web project with JavaServer Faces, using NetBeans 7.1)


Solved: I never found out what caused the problem. I ended up re-installing entire NetBeans, and re-created (a thousand times) the project I was trying to import. And in the end, I got it working.

回答1:

Put the JAR file in the WEB-INF/lib directory of your web project. All JARs in the WEB-INF/lib and all packages in WEB-INF/classes are automatically in the CLASSPATH.

Can you make "Hello, servlet" work? If not, why bother with JSF? Do a simple web app successfully and build up from there.



回答2:

I had this problem with netbeans, but it seems like all the answers I found are for Eclipse (I guess am wrong) as I dont see any WEB-INF/lib directoryin NetBeans, though I have a WEB-INF directory.

so here what I did.

I remove the tomcat server on NetBeans, go to C:\apache-tomcat-7.0.30\lib , put the jstl-1.2.jar file their, restart NetBeans and add a new (Tomcat) server, create a new web app, and their, I could find the jstl-1.2.jar file in the Libraries > Apache tomcat.

and for unknown reason, it worked.!