2013-03-17 28 views
0

我有一个程序,客户端上传文件并将文件存储在数据库中。在我的电脑上更新Java之前,我的项目工作正常。现在我得到FileNotFoundException。 Eclipse告诉我:在Java更新后的Eclipse中的FileNotFoundException

JAR文件C:\ Program Files \ Java \ jre7 \ lib \ rt.jar没有源 附件。

有人遇到过这个问题吗?

我的用于上载文件servlet代码是标准:

if (!ServletFileUpload.isMultipartContent(request)) 
    {return;} 

try 
{ 
    List<FileItem> items = new ServletFileUpload(new DiskFileItemFactory()).parseRequest(request); 
    courseID = items.get(0).getString(); 
    homeworkID = items.get(1).getString(); 
    File storeFile = new File(items.get(2).getName()); 
    String fileName = storeFile.getName(); 
    String mimeType = new MimetypesFileTypeMap().getContentType(storeFile); //for putting file into database 
    putFileIntoDB(uName, courseID, homeworkID, fileName, mimeType, storeFile); 
}//try 
catch (Exception ex) 
{ 
    request.setAttribute("msg", "There was an error: " + ex.getMessage()); 
    request.getRequestDispatcher("/upload.jsp").forward(request, response); 
    } 

有误差在putFileIntoDB方法发现在该行中创建的FileInputStream当f是=新的FileInputStream(F):

void putFileIntoDB(String username, String courseID, String homeworkID, String fileName, String mime, File f) throws SQLException, IOException 
{ 
    FileInputStream fis = null; 
    java.sql.PreparedStatement pstmt = null; 
    java.sql.Connection conn = null; 
    try { 
      conn = ConnectionManager.getConnection(); 
      conn.setAutoCommit(true); 

      fis = new FileInputStream(f); 

      pstmt = conn.prepareStatement("insert into files(username, courseID, assignmentID, fileName, mimeType, contents) values (?, ?, ?, ?, ?, ?)"); 
      pstmt.setString(1, username); 
      pstmt.setString(2, courseID); 
      pstmt.setString(3, homeworkID); 
      pstmt.setString(4, fileName); 
      pstmt.setString(5, mime); 
      pstmt.setAsciiStream(6, fis, (int) f.length()); 

      pstmt.executeUpdate(); 
      conn.commit(); 
     } 
    catch (Exception e) 
    { 
     System.err.println("Error: " + e.getMessage()); 
     e.printStackTrace(); 
    } 
    finally 
    { 
     pstmt.close(); 
     fis.close(); 
     conn.close(); 
    } 
} 

还有人遇到过这个问题吗?

+0

你检查过,如果那个罐子在那个位置可用? – Parth 2013-03-17 18:38:06

+0

是的,当我导航到那个位置时,rt.jar文件就在那里。这就是为什么我不明白为什么它告诉我它没有源附件。 – Lani1234 2013-03-17 18:45:30

回答

1

请尝试以下步骤;

第1步 - 配置Eclilpse使用JDK而不是JRE。

Window->Preferences->Java->Installed JREs 
Click "Add", "Standard VM", "Next" 
For "JRE Home" click "Directory" 
Locate your JDK directory... 
Ex: C:\java\jdk1.6.0_24 
Click "Finish" 
Next check the JDK vs the JRE that is listed. 
Click "Ok" 

第2步 - 将项目配置为使用JDK,因为它是使用JRE作为“已安装的JRE”创建的。新项目应该可以。

Right click the project's name. 
Choose "Properties", "Java Build Path" 
Click the tab "Libraries". 
Click "Add Libraries", select "JRE System Library", Next 
Select the bottom item: Workspace default JRE (jdk1.x.x. etc....) 
(Notice that it is now a JDK and not the JRE!) 
Click "Finish" 
Now remove the JRE libarary so you only have the JDK library. 
ex: JRE System Library [JavaSE-1.6] 
Click "OK" 
+0

嗯,我试过这个,不幸的是我仍然有同样的问题。我不知道我的eclipse设置发生了什么。我正在考虑放弃它并重新安装它。你知道是否有办法恢复到以前的工作时间? – Lani1234 2013-03-19 01:14:29

+0

不,你不能恢复。检查类似isse这里:http://stackoverflow.com/questions/10367286/m2eclipse-is-unable-to-locate-c-program-files-java-jre6-lib-tools-jar – 2013-03-19 06:14:01