1. 程式人生 > >maven編譯異常錯誤loading CharSequence class file is broken

maven編譯異常錯誤loading CharSequence class file is broken

  在用maven對專案進行編譯打包時,遇到了下面奇怪的編譯錯誤

"C:\Program Files\Java\jdk1.8.0\bin\java" "-Dmaven.home=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\plugins\maven\lib\maven3" "-Dclassworlds.conf=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\plugins\maven\lib\maven3\bin\m2.conf" -Didea.launcher.port=7532 "-Didea.launcher.bin.path=C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\bin" -Dfile.encoding=UTF-8 -classpath "C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\plugins\maven\lib\maven3\boot\plexus-classworlds-2.4.jar;C:\Program Files (x86)\JetBrains\IntelliJ IDEA Community Edition 2016.2.1\lib\idea_rt.jar" com.intellij.rt.execution.application.AppMain org.codehaus.classworlds.Launcher -Didea.version=2016.2.1 -s D:\apache-maven-3.2.5\conf\settings.xml package
[INFO] Scanning for projects...
[WARNING] 
[WARNING] Some problems were encountered while building the effective model for com.fangdd.data:house-profile:jar:1.0-SNAPSHOT
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-install-plugin is missing. @ line 181, column 21
[WARNING] 'build.plugins.plugin.version' for org.apache.maven.plugins:maven-deploy-plugin is missing. @ line 173, column 21
[WARNING] 
[WARNING] It is highly recommended to fix these problems because they threaten the stability of your build.
[WARNING] 
[WARNING] For this reason, future Maven versions might no longer support building such malformed projects.
[WARNING] 
[INFO]                                                                         
[INFO] ------------------------------------------------------------------------
[INFO] Building house-profile 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO] 
[INFO] --- maven-enforcer-plugin:1.4.1:enforce (enforce) @ house-profile ---
[INFO] 
[INFO] --- maven-resources-plugin:2.5:resources (default-resources) @ house-profile ---
[debug] execute contextualize
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\git-repository\house-profile\src\main\resources\prod
[INFO] Copying 4 resources
[INFO] 
[INFO] --- maven-compiler-plugin:2.3.2:compile (default-compile) @ house-profile ---
[INFO] Nothing to compile - all classes are up to date
[INFO] 
[INFO] --- scala-maven-plugin:3.2.2:compile (default) @ house-profile ---
[WARNING]  Expected all dependencies to require Scala version: 2.10.0
[WARNING]  com.twitter:chill_2.10:0.5.0 requires scala version: 2.10.4
[WARNING] Multiple versions of scala libraries detected!
[INFO] D:\git-repository\house-profile\src\main\java:-1: info: compiling
[INFO] D:\git-repository\house-profile\src\main\scala:-1: info: compiling
[INFO] Compiling 27 source files to D:\git-repository\house-profile\target\classes at 1498550091810
[ERROR] error: error while loading CharSequence, class file 'C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar(java/lang/CharSequence.class)' is broken
[INFO] (class java.lang.RuntimeException/bad constant pool tag 15 at byte 1501)
[ERROR] error: error while loading AnnotatedElement, class file 'C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar(java/lang/reflect/AnnotatedElement.class)' is broken
[INFO] (class java.lang.RuntimeException/bad constant pool tag 15 at byte 2713)
[ERROR] error: error while loading ConcurrentMap, class file 'C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar(java/util/concurrent/ConcurrentMap.class)' is broken
[INFO] (class java.lang.RuntimeException/bad constant pool tag 15 at byte 2447)
[ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemAddressProcessor.scala:21: error: overloaded method value replaceAllIn with alternatives:
[ERROR]   (target: CharSequence,replacer: scala.util.matching.Regex.Match => String)String <and>
[ERROR]   (target: CharSequence,replacement: String)String
[ERROR]  cannot be applied to (String, String)
[ERROR]       val addressReg = Constants.SPECIAL_CHAR_REG.r.replaceAllIn(address, "")
[ERROR]                                                     ^
[ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemNameProcessor.scala:24: error: type mismatch;
[ERROR]  found   : String
[ERROR]  required: CharSequence
[ERROR]       if (StringUtils.isNotBlank(name)) {
[ERROR]                                  ^
[ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemNameProcessor.scala:44: error: type mismatch;
[ERROR]  found   : String
[ERROR]  required: CharSequence
[ERROR]       if (StringUtils.isNotBlank(name)) {
[ERROR]                                  ^
[ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemNameProcessor.scala:55: error: overloaded method value indexOf with alternatives:
[ERROR]   (CharSequence,CharSequence)Int <and>
[ERROR]   (CharSequence,Int)Int
[ERROR]  cannot be applied to (String, String)
[ERROR]          val baseName = StringUtils.substring(tmp1, 0, StringUtils.indexOf(tmp1, ""))
[ERROR]                                                                    ^
[ERROR] error: error while loading Pattern, class file 'C:\Program Files\Java\jdk1.8.0\jre\lib\rt.jar(java/util/regex/Pattern.class)' is broken
[INFO] (class java.lang.RuntimeException/bad constant pool tag 15 at byte 14717)
[ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\processor\ItemNameProcessor.scala:127: error: type mismatch;
[ERROR]  found   : String
[ERROR]  required: CharSequence
[ERROR]             if (StringUtils.equals(srcNameNormalized, tgtNameNormalized)) {
[ERROR]                                    ^
[ERROR] D:\git-repository\house-profile\src\main\scala\com\fangdd\data\profile\util\ItemAddressProcessor.scala:22: error: overloaded method value replaceAllIn with alternatives:
[ERROR]   (target: CharSequence,replacer: scala.util.matching.Regex.Match => String)String <and>
[ERROR]   (target: CharSequence,replacement: String)String
[ERROR]  cannot be applied to (String, String)
[ERROR]       val addressReg = Constants.SPECIAL_CHAR_REG.r.replaceAllIn(address, "")
[ERROR]                                                     ^
[ERROR] 10 errors found
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.241s
[INFO] Finished at: Tue Jun 27 15:54:55 CST 2017
[INFO] Final Memory: 19M/259M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal net.alchim31.maven:scala-maven-plugin:3.2.2:compile (default) on project house-profile: wrap: org.apache.commons.exec.ExecuteException: Process exited with an error: 1 (Exit value: 1) -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException

Process finished with exit code 1

最後發現是maven編譯外掛配置的原因,編譯外掛版本不完整配置的是scala.binary.version,應該採用完整版本scala.complete.version才能找到具體的class
 <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
        <java.version>1.8</java.version>
        <maven.version.min>3.0.5</maven.version.min>
        <scala.binary.version>2.11</scala.binary.version>
        <scala.complete.version>${scala.binary.version}.4</scala.complete.version>
        <spark.version>1.6.2</spark.version>
        <spark-sql.version>1.6.2</spark-sql.version>
        <spark-hive.version>1.6.2</spark-hive.version>
 </properties>

<plugin>
    <groupId>net.alchim31.maven</groupId>
    <artifactId>scala-maven-plugin</artifactId>
    <version>3.2.2</version>
    <configuration>
        <scalaVersion>${scala.complete.version}</scalaVersion>
        <args>
            <arg>-unchecked</arg>
            <arg>-deprecation</arg>
            <arg>-feature</arg>
        </args>
        <javacArgs>
            <javacArg>-source</javacArg>
            <javacArg>${java.version}</javacArg>
            <javacArg>-target</javacArg>
            <javacArg>${java.version}</javacArg>
        </javacArgs>
    </configuration>
    <executions>
        <execution>
            <phase>compile</phase>
            <goals>
                <goal>compile</goal>
            </goals>
        </execution>
    </executions>
</plugin>