2014-01-20 46 views
0

通過控制檯(Windows上的v0.13.1)運行sbt test當我嘗試創建com.sun.rowset.CachedRowSetImpl對象的實例時拋出MissingResourceException: : Can't find bundle for base name com/sun/rowset/RowSetResourceBundle, locale en_CA。如果我使用IntelliJ來運行Specs測試,那麼相同的代碼運行得非常好;它只在嘗試通過SBT控制檯運行時失敗。MissingResourceException:找不到基本名稱的包com/sun/rowset/RowSetResourceBundle(SBT項目)

這裏是specs2測試我試圖運行:

import org.specs2.mutable.SpecificationWithJUnit 
import javax.sql.rowset.CachedRowSet; 
import com.sun.rowset.CachedRowSetImpl 

class DatabaseTest extends SpecificationWithJUnit { 
    "CachedRowSet Test" should { 
    "Create a new CachedRowSetImpl instance" in { 
     val rowSet: CachedRowSet = new CachedRowSetImpl() 
     rowSet must_!= null 
    } 
    } 
} 

而由此導致的異常:

[error] MissingResourceException: : Can't find bundle for base name com/sun/rowset/RowSetResourceBundle, locale en_CA (null:-1) 
[error] com.sun.rowset.JdbcRowSetResourceBundle.<init>(Unknown Source) 
[error] com.sun.rowset.JdbcRowSetResourceBundle.getJdbcRowSetResourceBundle(Unknown Source) 
[error] com.sun.rowset.CachedRowSetImpl.<init>(Unknown Source) 
[error] test.DatabaseTest$$anonfun$1$$anonfun$apply$1.apply(DatabaseTest.scala:10) 
[error] test.DatabaseTest$$anonfun$1$$anonfun$apply$1.apply(DatabaseTest.scala:9) 

更新:build.sbt內容:

scalacOptions ++= Seq("-deprecation", "-unchecked", "-feature") 

scalaVersion := "2.10.3" 

scalacOptions ++= Seq("-Yrangepos") 

javacOptions ++= Seq("-source", "1.6", "-target", "1.6", "-Xlint:deprecation", "-Xlint:unchecked") 

libraryDependencies in ThisBuild ++= Seq(
    "postgresql" % "postgresql" % "9.1-901.jdbc4" withSources(), 
    "org.specs2" %% "specs2" % "2.3.7" withSources() 
) 

lazy val root = project.in(file(".")) 
+0

如何構建配置的樣子 - 'build.sbt'或'project/*。scala'文件?如果你更新這個問題會很好。 –

回答

0

對CachedRowSetImpl是內部類在某些版本的JDK運行時中,但不是JDK的正式組成部分。你可以告訴它是內部的,因爲它的包以「com.sun」開頭,而不是「java」。您的Windows計算機可能有一個完全不同的JDK,它缺少這個內部類。

我強烈建議避免使用「com.sun」類,並找到用現有JDK完成工作的慣用方式。

+1

我的JDK運行時具有CachedRowSetImpl,並且jre/lib/resources.jar包含正確的資源文件。 IntelliJ IDEA運行代碼沒有問題,而SBT引發異常。此外,com.sun。*軟件包不是internal-sun。*軟件包(http://www.oracle.com/technetwork/java/faq-sun-packages-142232.html);他們是參考Java接口的Oracle實現。使用它們非常好,理解您需要Oracle JDK來運行您的應用程序。 –

0

只要你使用的Java 7 ...

從Java 7的存在是少數classesmethods從像您這樣的錯誤,保護你。針對界面進行開發(在提供商的幫助下),生活變得更加簡單。

import org.specs2.mutable.SpecificationWithJUnit 
import javax.sql.rowset._ 

class DatabaseTest extends SpecificationWithJUnit { 
    "CachedRowSet Test" should { 
    "Create a new CachedRowSetImpl instance" in { 
     val rsf = RowSetProvider.newFactory 
     val rowSet: CachedRowSet = rsf.createCachedRowSet 
     rowSet must_!= null 
    } 
    } 
} 

隨着Specs2測試,test爲我工作得很好。

> test 
[info] DatabaseTest 
[info] 
[info] CachedRowSet Test should 
[info] + Create a new CachedRowSetImpl instance 
[info] 
[info] Total for specification DatabaseTest 
[info] Finished in 41 ms 
[info] 1 example, 0 failure, 0 error 
[info] Passed: Total 1, Failed 0, Errors 0, Passed 1 

BTW:失蹤資源是在JRE lib/resources.jar,但無法弄清楚他們爲什麼報失蹤(即使他們在lib目錄中的項目結束了)。

0

具有相同的問題。不是在斯卡拉,而是Java。

com.sun.rowset.JdbcRowSetResourceBundle使用上下文類加載器加載資源。

在我的情況下context classloader是一個URLClassLoader

它看起來像一個非常奇怪的限制URLClassLoader - 當查找資源時,它不諮詢父類加載器,它只檢查自己的URL列表。

希望有所幫助。

1

我在使用SBT運行ScalaTest時遇到了此問題。在的IntelliJ測試都成功了,但在SBT的CachedRowSet的一個後期綁定的實現並沒有得到解決,下面的異常被拋出,

MissingResourceException異常:無法找到捆綁的基本名稱 COM /陽光/行集/ RowSetResourceBundle,現場EN_GB

這個問題似乎是在SBT線程不解決運行時類負載給JVM(缺少的資源被rt.jar中和resources.jar提供)。 這可以通過強制SBT線程通過把下面的指令到SBT的主體構建文件派生新的線程爲每個測試是固定的,

fork in Test := true 
+0

由於我有其他問題,還有其他一些想法,我無法承受Test:= true。我堅持這一點,提前thxs! –

相關問題