如何使用org.apache.commons.configuration2读取属性文件?

时间:2017-02-27 14:20:28

标签: java apache scala

我正在尝试使用org.apache.commons.configuration2读取属性文件并在下面收到错误,请告诉我我在哪里做错了我正在帮助给定链接https://commons.apache.org/proper/commons-configuration/userguide/quick_start.html

File:- xyz.properties

driver = "oracle.jdbc.driver.OracleDriver"
url = "jdbc:oracle:thin:@xxxx:1521/xxxx.xxxx"
username = "xxx"
password = "xxx"
input_file = "C:\\Users\\xxx\\test\\src\\main\\resources\\xxxx.xlsx"


code:- File.scala

import org.apache.commons.configuration2.builder.fluent.{Configurations}

object Configuration {

def main(args: Array[String]): Unit = {

    val config = new Configurations();
    val configs = config.properties(new File("xyz.properties"));


    val inputFile = configs.getString("input_file")

    val userName = configs.getString("username")
    val password = configs.getString("password")
    val driver = configs.getString("driver")
    val url = configs.getString("url")


    println("Inside config" + inputFile )       
}
}

Error :-
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/beanutils/BeanIntrospector
    at java.lang.Class.forName0(Native Method)
    at java.lang.Class.forName(Class.java:264)
    at com.sun.proxy.$Proxy0.<clinit>(Unknown Source)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
    at java.lang.reflect.Proxy.newProxyInstance(Proxy.java:739)
    at org.apache.commons.configuration2.builder.fluent.Parameters.createParametersProxy(Parameters.java:294)
    at org.apache.commons.configuration2.builder.fluent.Parameters.fileBased(Parameters.java:185)
    at org.apache.commons.configuration2.builder.fluent.Configurations.fileParams(Configurations.java:602)
    at org.apache.commons.configuration2.builder.fluent.Configurations.fileParams(Configurations.java:614)
    at org.apache.commons.configuration2.builder.fluent.Configurations.fileBasedBuilder(Configurations.java:132)
    at org.apache.commons.configuration2.builder.fluent.Configurations.propertiesBuilder(Configurations.java:238)
    at org.apache.commons.configuration2.builder.fluent.Configurations.properties(Configurations.java:282)
    at com.rxcorp.italy.config.Configuration$.<init>(File.scala:8)
    at com.rxcorp.italy.config.Configuration$.<clinit>(Configuration.scala)
    at com.rxcorp.paneldataloading.ItalyPanelData$.main(File.scala:19)

sbt档案

name := "xxx.xxxx.xxxxx"

scalaVersion := "2.10.6"

ivyScala := ivyScala.value map{ _.copy(overrideScalaVersion = true) }


libraryDependencies ++= Seq("org.apache.spark" %% "spark-core" % "2.1.0",
  "com.databricks" %% "spark-csv" % "1.5.0",
"org.apache.commons" % "commons-configuration2" % "2.1.1"  )

1 个答案:

答案 0 :(得分:0)

您需要在sbt中的libraryDependencies中添加commons-beanutils工件来解决此问题。所以你的sbt文件的<html> <head> <link type="text/css" rel="stylesheet" href="style_divs.css"> </head> <body> <div id="table"> <div id="year">2017</div> <div id="month"> <div id="previousMonth">Previous</div> <div id="nextMonth">Next</div> January </div> </div> </body> </html> 如下所示。

#table{
    width:25%;
    height:50%;
    background-color: red;
    margin: 0 auto;
}

#year{
    width:100%;
    height:10%;
    background-color: blue;
    margin: 0 auto;
    text-align: center;
}
#month{
    width:100%;
    height:10%;
    background-color: yellow;
    margin: 0 auto;
    text-align: center;
}

#previousMonth{
    width:12%;
    height:100%;
    background-color: green;
    margin-left: 0%;
    text-align: center;
}

#nextMonth{
    width:12%;
    height:100%;
    background-color: cyan;
    margin-left: 88%;
    text-align: center;
}