473,385 Members | 1,356 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Problem with specifying build path

Dear all,

I'm developing a servlet to handle file upload requests. Despite importing all required classes in the build path, I still receive the 'classNotFoundException' for FileItemFactory. I have also included the file-upload library in the build path of my project. Does anyone know why this is happening? As you can see below I've done a lot of redundant importing as well hoping it would solve the problem but it hasn't. I've been trying to create new projects, etc but I still get the same error.

In the doPost() method I've written my code as follows:

Expand|Select|Wrap|Line Numbers
  1. public void doPost( HttpServletRequest req, HttpServletResponse res )
  2.     {
  3.       File disk = null;
  4.       FileItem item = null;
  5.       FileItemFactory factory = new DiskFileItemFactory();
  6.       java.util.Iterator iter = null;
  7.       List items = null;
  8.       ServletFileUpload upload = new ServletFileUpload( factory );
  9.  
  10.       try
  11.       {
  12.         items = upload.parseRequest( req );
  13.         iter = items.iterator();
  14.  
  15.  
  16.         while( iter.hasNext() )
  17.         {
  18.           // Get the current item in the iteration
  19.           item = ( FileItem )iter.next();
  20.             disk = new File(item.getName());
  21.             item.write( disk );
  22.         }
  23.  
  24.  
  25.       } 
  26.        catch( IOException ioe ) {
  27.         ioe.printStackTrace();
  28.       } catch( Exception e ) {
  29.         e.printStackTrace();
  30.       }
  31.     }
  32.  
I've also imported all the necessary packages and classes using :

Expand|Select|Wrap|Line Numbers
  1. import java.io.IOException;
  2. import java.io.File;
  3. import javax.servlet.ServletException;
  4. import javax.servlet.http.HttpServlet;
  5. import javax.servlet.http.HttpServletRequest;
  6. import javax.servlet.http.HttpServletResponse;
  7. import org.apache.commons.fileupload.servlet.ServletFileUpload;
  8. import org.apache.commons.fileupload.disk.DiskFileItemFactory;
  9. import org.apache.commons.fileupload.FileItemFactory;
  10. import org.apache.commons.fileupload.FileItem;
  11. import org.apache.commons.fileupload.FileUpload;
  12. import org.apache.commons.*;
  13. import org.apache.commons.fileupload.*;
  14. import java.util.List;
  15. import org.apache.commons.io.*;
  16.  
Can anyone tell me why this is happening?

Thanks and regards,

Nikhil
Apr 5 '09 #1
7 2519
JosAH
11,448 Expert 8TB
Those classes you're trying to import are all stored in a .jar file. Did you mention that/those jar(s) in your classpath?

kind regards,

Jos
Apr 5 '09 #2
Thanks for the quick response, Jos. They are in a jar file and since I'm using Eclipse Ganymede as my IDE I merely included those jar files in my build-path. This is a practice that I've used without issues before.

Cheers,

Nikhil
Apr 5 '09 #3
JosAH
11,448 Expert 8TB
@ne0lithic
What happens when you refresh (F5) your entire project? In the rare event that Eclipse FU'd its entire workspace project data you could give it a try to start eclipse with the -clean flag ...

kind regards,

Jos
Apr 5 '09 #4
I tried refreshign the project and trying eclipse with the -clean option. It still shows me the same error.I've already tried another workspace as well

Cheers,

Nikhil
Apr 5 '09 #5
JosAH
11,448 Expert 8TB
@ne0lithic
I assume that you have WTP (Web Tools Platform) installed for Eclipse but those classes are ordinary classes. If all else fails you might try to stick those jars in the lib/ext subdirectory of your JRE installation (beware: they don't really belong there).

kind regards,

Jos
Apr 5 '09 #6
r035198x
13,262 8TB
If you have created a web application, add the commons-fileupload jar to your web app's WEB-INF/lib folder.
Apr 6 '09 #7
Thanks for the help. That's exactly what I did and it's working just fine now.

Cheers,

Nikhil
Apr 14 '09 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Sri | last post by:
Hi, I'm having trouble specifying the classpath (to Ant) when I'm running Ant from within a servlet. Whatever directory I try to specify, Ant is trying to build the path starting at c:\ on my...
1
by: Bren | last post by:
Hi, Pardon my stupid, but I'm having a problem building Boost.Python as per the instructions at http://www.boost.org/libs/python/doc/building.html I got boost-build-2.0-m6.zip from...
0
by: Jose Vicente Nunez Z | last post by:
Greetings, I wrote a couple of custom dummy extensions in Python (one a pure Python and the other a C) and i managed to compile and install them without a problem: $ make python2 setup.py...
1
by: | last post by:
Hello, I tried to build Python 2.4.1 on a Reliant Unix system. Just after the python executable program has been built, I get the following error: ==== begin make output === CC -W1...
3
by: Gordon Watts | last post by:
Hi there, I've got a special header file which I run an small external program over to produce a .cpp file that I want to have my project build. The special header file includes a second header...
15
by: Ken Allen | last post by:
I have been developing a suite of assemblies over the past couple of weeks, and this afternoon somethign started misbehaving. If I do not run the IDE and compiler the code from the command line,...
11
by: brianlanning | last post by:
We have a web application in 2003. The solution contains the project for the web application and five other projects for shared assemblies. We have two issues. The first is that we want to...
7
by: plumb and tree | last post by:
I've been trying for days to build 64 bit python with Solaris 10 + Sun Studio 12. Can anyone helpl please. This is how I tried to do build: # ./configure --prefix=/opt/python2.4...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.