Java升级异常从1.6到1.8

时间:2016-02-15 00:34:43

标签: gradle groovy java-8 jibx

我正在尝试将我的项目从Java 1.6升级到Java 1.8,而在做Gradle构建时我正在使用JIBX绑定编译Error。如果我使用Java 1.6运行它可以正常工作。

我使用的是JIBX 1.2.5版,Gradle 2.9版.JAVA 1.8.0_71,Groovy 2.4.4。

将我的jibx.gradle附加到

下面
<plugins>
    <plugin>
        <groupId>org.jibx</groupId>
        <artifactId>jibx-maven-plugin</artifactId>
        <version>1.2.6</version>
        <configuration>
            <schemaBindingDirectory>src/main/resources/jibx</schemaBindingDirectory>
            <includeSchemaBindings>
                <includeSchemaBindings>common-config-JibX.xml</includeSchemaBindings>
            </includeSchemaBindings>
            <verbose>true</verbose>
        </configuration>
        <dependencies>
            <!-- Workaround to avoid error compiling with JDK 1.8 -->
            <dependency>
                <groupId>org.apache.bcel</groupId>
                <artifactId>bcel</artifactId>
                <version>6.0-SNAPSHOT</version>
            </dependency>
        </dependencies>
        <executions>
            <execution>
                <goals>
                    <goal>bind</goal>
                </goals>
            </execution>
        </executions>
    </plugin>

我在执行bind方法时遇到错误

附加我在pom中使用的JIBX插件

* What went wrong:
Execution failed for task ':war:compileJava'.
> JiBXException in JiBX binding compilation

* Try:
Run with --info or --debug option to get more log output.

* Exception is:
org.gradle.api.tasks.TaskExecutionException: Execution failed for task ':war:com
pileJava'.
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:69)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecute(ExecuteActionsTaskExecuter.java:46)
        at org.gradle.api.internal.tasks.execution.PostExecutionAnalysisTaskExec
uter.execute(PostExecutionAnalysisTaskExecuter.java:35)
        at org.gradle.api.internal.tasks.execution.SkipUpToDateTaskExecuter.exec
ute(SkipUpToDateTaskExecuter.java:64)
        at org.gradle.api.internal.tasks.execution.ValidatingTaskExecuter.execut
e(ValidatingTaskExecuter.java:58)
        at org.gradle.api.internal.tasks.execution.SkipEmptySourceFilesTaskExecu
ter.execute(SkipEmptySourceFilesTaskExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipTaskWithNoActionsExecuter
.execute(SkipTaskWithNoActionsExecuter.java:52)
        at org.gradle.api.internal.tasks.execution.SkipOnlyIfTaskExecuter.execut
e(SkipOnlyIfTaskExecuter.java:53)
        at org.gradle.api.internal.tasks.execution.ExecuteAtMostOnceTaskExecuter
.execute(ExecuteAtMostOnceTaskExecuter.java:43)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTa
skWorker.execute(DefaultTaskGraphExecuter.java:203)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter$EventFiringTa
skWorker.execute(DefaultTaskGraphExecuter.java:185)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.processTask(AbstractTaskPlanExecutor.java:66)
        at org.gradle.execution.taskgraph.AbstractTaskPlanExecutor$TaskExecutorW
orker.run(AbstractTaskPlanExecutor.java:50)
        at org.gradle.execution.taskgraph.DefaultTaskPlanExecutor.process(Defaul
tTaskPlanExecutor.java:25)
        at org.gradle.execution.taskgraph.DefaultTaskGraphExecuter.execute(Defau
ltTaskGraphExecuter.java:110)
        at org.gradle.execution.SelectedTaskExecutionAction.execute(SelectedTask
ExecutionAction.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:37)
        at org.gradle.execution.DefaultBuildExecuter.access$000(DefaultBuildExec
uter.java:23)
        at org.gradle.execution.DefaultBuildExecuter$1.proceed(DefaultBuildExecu
ter.java:43)
        at org.gradle.execution.DryRunBuildExecutionAction.execute(DryRunBuildEx
ecutionAction.java:32)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:37)
        at org.gradle.execution.DefaultBuildExecuter.execute(DefaultBuildExecute
r.java:30)
        at org.gradle.initialization.DefaultGradleLauncher$4.run(DefaultGradleLa
uncher.java:154)
        at org.gradle.internal.Factories$1.create(Factories.java:22)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(Defaul
tBuildOperationExecutor.java:90)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(Defaul
tBuildOperationExecutor.java:52)
        at org.gradle.initialization.DefaultGradleLauncher.doBuildStages(Default
GradleLauncher.java:151)
        at org.gradle.initialization.DefaultGradleLauncher.access$200(DefaultGra
dleLauncher.java:32)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradl
eLauncher.java:99)
        at org.gradle.initialization.DefaultGradleLauncher$1.create(DefaultGradl
eLauncher.java:93)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(Defaul
tBuildOperationExecutor.java:90)
        at org.gradle.internal.progress.DefaultBuildOperationExecutor.run(Defaul
tBuildOperationExecutor.java:62)
        at org.gradle.initialization.DefaultGradleLauncher.doBuild(DefaultGradle
Launcher.java:93)
        at org.gradle.initialization.DefaultGradleLauncher.run(DefaultGradleLaun
cher.java:82)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter$DefaultBuildCon
troller.run(InProcessBuildActionExecuter.java:94)
        at org.gradle.tooling.internal.provider.ExecuteBuildActionRunner.run(Exe
cuteBuildActionRunner.java:28)
        at org.gradle.launcher.exec.ChainingBuildActionRunner.run(ChainingBuildA
ctionRunner.java:35)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:43)
        at org.gradle.launcher.exec.InProcessBuildActionExecuter.execute(InProce
ssBuildActionExecuter.java:28)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(Contin
uousBuildActionExecuter.java:77)
        at org.gradle.launcher.exec.ContinuousBuildActionExecuter.execute(Contin
uousBuildActionExecuter.java:47)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.exe
cute(DaemonUsageSuggestingBuildActionExecuter.java:51)
        at org.gradle.launcher.exec.DaemonUsageSuggestingBuildActionExecuter.exe
cute(DaemonUsageSuggestingBuildActionExecuter.java:28)
        at org.gradle.launcher.cli.RunBuildAction.run(RunBuildAction.java:43)
        at org.gradle.internal.Actions$RunnableActionAdapter.execute(Actions.jav
a:170)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:237)
        at org.gradle.launcher.cli.CommandLineActionFactory$ParseAndBuildAction.
execute(CommandLineActionFactory.java:210)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:35)
        at org.gradle.launcher.cli.JavaRuntimeValidationAction.execute(JavaRunti
meValidationAction.java:24)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:206)
        at org.gradle.launcher.cli.CommandLineActionFactory$WithLogging.execute(
CommandLineActionFactory.java:169)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:33)
        at org.gradle.launcher.cli.ExceptionReportingAction.execute(ExceptionRep
ortingAction.java:22)
        at org.gradle.launcher.Main.doAction(Main.java:33)
        at org.gradle.launcher.bootstrap.EntryPoint.run(EntryPoint.java:45)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.runNoExit(ProcessBoots
trap.java:54)
        at org.gradle.launcher.bootstrap.ProcessBootstrap.run(ProcessBootstrap.j
ava:35)
        at org.gradle.launcher.GradleMain.main(GradleMain.java:23)
Caused by: : JiBXException in JiBX binding compilation
        at org.jibx.binding.ant.CompileTask.execute(CompileTask.java:252)
        at org.apache.tools.ant.UnknownElement.execute(UnknownElement.java:292)
        at org.apache.tools.ant.dispatch.DispatchUtils.execute(DispatchUtils.jav
a:106)
        at org.gradle.api.internal.project.ant.BasicAntBuilder.nodeCompleted(Bas
icAntBuilder.java:78)
        at org.gradle.api.internal.project.ant.BasicAntBuilder.doInvokeMethod(Ba
sicAntBuilder.java:93)
        at jibx_50hfomxu8u1392vt31qdevxoj$_compileJibx_closure5.doCall(C:\sandee
p\JavaUpgrade\DI-services\war\jibx.gradle:32)
        at org.gradle.api.internal.ClosureBackedAction.execute(ClosureBackedActi
on.java:67)
        at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:130)
        at org.gradle.util.ConfigureUtil.configure(ConfigureUtil.java:91)
        at org.gradle.api.internal.project.AbstractProject.ant(AbstractProject.j
ava:816)
        at org.gradle.api.internal.BeanDynamicObject$MetaClassAdapter.invokeMeth
od(BeanDynamicObject.java:235)
        at org.gradle.api.internal.BeanDynamicObject.invokeMethod(BeanDynamicObj
ect.java:130)
        at org.gradle.api.internal.CompositeDynamicObject.invokeMethod(Composite
DynamicObject.java:150)
        at org.gradle.groovy.scripts.BasicScript.methodMissing(BasicScript.java:
79)
        at jibx_50hfomxu8u1392vt31qdevxoj.compileJibx(C:\sandeep\JavaUpgrade\DI-
services\war\jibx.gradle:27)
        at jibx_50hfomxu8u1392vt31qdevxoj$_run_closure4.doCall(C:\sandeep\JavaUp
grade\DI-services\war\jibx.gradle:42)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(Abstra
ctTask.java:554)
        at org.gradle.api.internal.AbstractTask$ClosureTaskAction.execute(Abstra
ctTask.java:535)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteAction(ExecuteActionsTaskExecuter.java:80)
        at org.gradle.api.internal.tasks.execution.ExecuteActionsTaskExecuter.ex
ecuteActions(ExecuteActionsTaskExecuter.java:61)
        ... 57 more
Caused by: org.jibx.runtime.JiBXException: Error running binding compiler
        at org.jibx.binding.Compile.compile(Compile.java:318)
        at org.jibx.binding.ant.CompileTask.execute(CompileTask.java:248)
        ... 76 more
Caused by: java.lang.IllegalStateException: Error loading class java.lang.CharSe
quence: Error reading path java/lang/CharSequence.class for class java.lang.Char
Sequence
        at org.jibx.binding.classes.ClassCache$ClassCacheLocator.getClassInfo(Cl
assCache.java:291)
        at org.jibx.binding.model.ClassHierarchyContext.accumulateInterfaces(Cla
ssHierarchyContext.java:95)
        at org.jibx.binding.model.ClassHierarchyContext.addTypedComponent(ClassH
ierarchyContext.java:121)
        at org.jibx.binding.model.DefinitionContext.addFormat(DefinitionContext.
java:527)
        at org.jibx.binding.model.BindingElement.defineBaseFormat(BindingElement
.java:843)
        at org.jibx.binding.model.BindingElement.runValidation(BindingElement.ja
va:865)
        at org.jibx.binding.model.BindingElement.runValidation(BindingElement.ja
va:899)
        at org.jibx.binding.model.BindingElement.validateBinding(BindingElement.
java:969)
        at org.jibx.binding.Utility.validateBinding(Utility.java:226)
        at org.jibx.binding.Utility.loadBinding(Utility.java:269)
        at org.jibx.binding.Utility.loadFileBinding(Utility.java:420)
        at org.jibx.binding.Compile.compile(Compile.java:217)
        ... 77 more


BUILD FAILED

附加错误

CoordinatorLayout

2 个答案:

答案 0 :(得分:1)

我遇到了类似的Jibx和java 8兼容性问题。

好消息:Jibx可以使用Java 8 !!

我检查了依赖树,bcel 5.0仍然存在(即使在从其中一个依赖项中排除之后)。在maven中使用mvn dependency:tree命令检查依赖树。

gradle gradle dependencies应该有希望(不确定)。

以下是我为解决此问题所做的工作:

在我的 pom.xml

<强> 1。为bcel-6.0快照依赖性添加了以下存储库

 <repositories>
        <repository>
            <id>apache.snapshots</id>
            <url>https://repository.apache.org/content/repositories/snapshots</url>
            <snapshots>
                <enabled>true</enabled>
                <updatePolicy>always</updatePolicy>
            </snapshots>
            <releases>
                <enabled>false</enabled>
            </releases>
        </repository>
    </repositories>

<强> 2。从所有依赖项中排除默认的bcel:

 <!-- JiBX -->
        <dependency>
            <groupId>org.jibx</groupId>
            <artifactId>jibx-run</artifactId>
            <version>${jibx.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>bcel</artifactId>
                    <groupId>bcel</groupId>
                </exclusion>
            </exclusions>
        </dependency>
        <dependency>
            <groupId>org.jibx</groupId>
            <artifactId>jibx-extras</artifactId>
            <version>${jibx.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>bcel</artifactId>
                    <groupId>bcel</groupId>
                </exclusion>
            </exclusions>
            <optional>true</optional>
        </dependency>
        <dependency>
            <groupId>org.jibx</groupId>
            <artifactId>jibx-bind</artifactId>
            <version>${jibx.version}</version>
            <exclusions>
                <exclusion>
                    <artifactId>bcel</artifactId>
                    <groupId>bcel</groupId>
                </exclusion>
            </exclusions>
        </dependency>

第3。在需要的地方添加了BCEL 6.0快照依赖项。

<plugin>
            <groupId>org.apache.cxf</groupId>
            <artifactId>cxf-codegen-plugin</artifactId>
            <version>${cxf.version}</version>
            <executions>
                <execution>
                    <phase>generate-sources</phase>
                    <configuration>
                        <sourceRoot>${project.build.directory}/generated-sources</sourceRoot>
                        <wsdlOptions>
                            <wsdlOption>
                                <wsdl>${project.basedir}/src/main/resources/abc.wsdl</wsdl>
                                <dataBinding>jibx</dataBinding>
                                <extraargs>
                                    <extraarg>-nexclude</extraarg>
                                    <extraarg>http://cs.xyz.abc.com/ws</extraarg>
                                </extraargs>
                            </wsdlOption>
                        </wsdlOptions>
                    </configuration>
                    <goals>
                        <goal>wsdl2java</goal>
                    </goals>
                </execution>
            </executions>
            <!-- added dependency to avoid jibx-java8 compatibility issues -->
            <dependencies>
                <dependency>
                    <groupId>org.apache.bcel</groupId>
                    <artifactId>bcel</artifactId>
                    <version>6.0-SNAPSHOT</version>
                </dependency>
            </dependencies>
        </plugin> 

        <plugin>
                <groupId>org.jibx</groupId>
                <artifactId>jibx-maven-plugin</artifactId>
                <version>${jibx.version}</version>
                <executions>
                    <!-- generate code from schema using JiBX with customization -->
                    <!-- This process will generate the 'cs.abc.axy.com.types' source 
                        classes and the JiBX binding definition file at the default location: ${project.build.directory}/generated-sources/binding.xml -->
                    <execution>
                        <id>generate-java-code-from-schema</id>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>schema-codegen</goal>
                        </goals>
                        <configuration>
                            <schemaLocation>${project.basedir}/src/main/resources</schemaLocation>
                            <customizations>
                                <customization>${project.basedir}/src/main/config/custom-jibx-codegen.xml</customization>
                            </customizations>
                        </configuration>
                    </execution>
                    <!-- run the JiBX binding compiler -->
                    <!-- The binding.xml file at the default location will be used here. -->
                    <execution>
                        <id>compile-binding</id>
                        <goals>
                            <goal>bind</goal>
                        </goals>
                        <configuration>
                            <schemaBindingDirectory>${project.build.directory}/generated-sources</schemaBindingDirectory>
                            <includeSchemaBindings>
                                <includeSchemaBinding>binding.xml</includeSchemaBinding>
                            </includeSchemaBindings>
                        </configuration>
                    </execution>
                </executions>
                <!-- added dependency to avoid jibx-java8 compatibility issues -->
                <dependencies>
                    <dependency>
                        <groupId>org.apache.bcel</groupId>
                        <artifactId>bcel</artifactId>
                        <version>6.0-SNAPSHOT</version>
                    </dependency>
                </dependencies>
        </plugin>

<强> 4。删除/刷新我的.m2目录。您可能需要执行重建索引或删除旧存储库的类似内容。

我希望这有帮助..

答案 1 :(得分:0)

我有类似的错误。只需将JIBX依赖项更新为1.3.1

即可
Private Sub GetText2()
Dim CellValue As String
Dim RowCrnt As Integer
Dim RowMaxB As Integer
Dim RowMaxC As Integer
Dim RowMaxA As Integer
Dim wsh As Worksheet
Dim i As Integer
Dim checkDup As Integer


Set wsh = ThisWorkbook.Sheets("Sheet1")
'get max row of each Row
RowMaxB = wsh.Cells(Rows.Count, "B").End(xlUp).Row
RowMaxC = wsh.Cells(Rows.Count, "C").End(xlUp).Row
RowMaxA = wsh.Cells(Rows.Count, "A").End(xlUp).Row

If RowMaxA > 2 Then
'Clear contents of column A before write value. if > 2 to case Column A is blank
wsh.Range("A2:A" & RowMaxA).ClearContents
End If

'Run each row of column B
  For RowCrnt = 2 To RowMaxB
  checkDup = 0
    CellValue = wsh.Cells(RowCrnt, 2).Value
    If CellValue <> "" Then
         If RowCrnt = 2 Then
         'if check row is first row so set first value of column C to it
         checkDup = 0
         Else

             For i = RowCrnt - 1 To 2 Step -1
             ' loop backwards to find duplicate value in column B
                If wsh.Cells(i, 2).Value = CellValue And wsh.Cells(i, 1).Value <> "" Then
                ' if exist duplicate value so run function to find next value of column C
                wsh.Cells(RowCrnt, 1).Value = findInColC(wsh, wsh.Cells(i, 1).Value, RowMaxC, "C")
                checkDup = 1
                Exit For
                Else

                End If

            Next
         End If

        If checkDup = 0 Then
            wsh.Cells(RowCrnt, 1).Value = wsh.Cells(2, 3).Value
        Else
        End If

    Else
    End If
  Next

'release variables
 CellValue = ""
 RowCrnt = 0
 RowMaxB = 0
 RowMaxC = 0
 RowMaxA = 0
 Set wsh = Nothing
 i = 0
 checkDup = 0

End Sub
Function findInColC(wshSheet As Worksheet, stringFind As String, lastRow As Integer, FindColumn As String) As String
Dim i As Integer
For i = 2 To lastRow
If stringFind = wshSheet.Cells(i, FindColumn).Value Then
    If i = lastRow Then
    'if value find in A is last value in column C so set first value of Column C for it.
    findInColC = wshSheet.Cells(2, FindColumn).Value
    Else
    findInColC = wshSheet.Cells(i + 1, FindColumn).Value
    End If

Else
End If
Next

End Function