java 8:编译错误:无法访问同步

时间:2017-10-04 12:58:05

标签: java hibernate java-8 jta

我有一个为Java 6编写的遗留代码,我想用Jdk 8

编译它

此代码使用seamhibernate,我没有更改依赖项版本。事实上,我真的只是改变了jdk。

我对Hibernate的getSession方法有一个编译错误:

@SuppressWarnings("serial")
public abstract class AbstractComponent  implements java.io.Serializable
{
    @In(value="grogDatabase", create = true, required = true)
    private Session _grogDatabase;

    /**
     * @return the hibernate database {@link Session} injected via Seam into this component.
     * Warning : DO NOT use injected data in component constructors !
     */
    protected Session getSession()
    {
        return _grogDatabase;
    }
}

@SuppressWarnings({"serial", "SeamAnnotationsInconsistencyInspection"})
public abstract class AbstractConversationComponent extends AbstractComponent
{
    @In(value="myDatabase", scope = CONVERSATION)
    private org.jboss.seam.persistence.ManagedHibernateSession _myDatabase;

    /**
     * @return the hibernate database {@link Session} injected via Seam into this component.
     * Warning : DO NOT use injected data in component constructors !
     */
    @Override
    protected Session getSession()
    {
        try
        {
            Session hSession = _myDatabase.getSession();
            return hSession;
        }
        catch (Exception e)
        {
            return null;
        }
    }
 }

我收到的错误消息是

 /.../AbstractConversationComponent.java:32: error: cannot access Synchronization
    [javac]             Session hSession = _myDatabase.getSession();
    [javac]                                             ^
    [javac]   class file for javax.transaction.Synchronization not found

我认为这是一个缺少的依赖,javax.transaction.jta说,但为什么Jdk中的更改意味着我的依赖项发生了变化?

包含依赖项而不能检查其兼容性对我来说似乎很危险..

编辑:以下是使用各种Jdk进行相同编译的一些痕迹:

1.6:

$ JAVA_HOME=/usr/lib/jvm/java-1.6.0-openjdk-amd64 ant clean deploy.local.archive
...
[javac] 5 warnings

1.7:

$ JAVA_HOME=/usr/lib/jvm/j2sdk1.7-oracle/ ant clean deploy.local.archive
...
[javac] 5 warnings

1.8:

$ JAVA_HOME=/usr/lib/jvm/jdk-8-oracle-x64/ ant clean deploy.local.archive
...
[javac] 1 error
[javac] 5 warnings

编辑:我检查过,jta.jar确实是正在运行的类路径的一部分,但不是编译类路径的一部分。

所以我在build.xml中将其他人手动添加到列表中,现在它与jdk 8一起工作。但这对我来说仍然没有意义,我真的很想知道为什么会这样。 :)

<path id="class.path">
    <pathelement location="${env.JAVA_HOME}/lib/tools.jar"/><!-- Only for ExcludeTaglet -->
    <pathelement location="${project.ext.dir}/dev/servlet.jar"/>
    <pathelement location="${project.ext.dir}/run/log4j.jar"/>
    <pathelement location="${project.ext.dir}/run/dom4j.jar"/>
    <pathelement location="${project.ext.dir}/run/castor.jar"/>
    <pathelement location="${project.ext.dir}/run/commons-httpclient.jar"/>
    <pathelement location="${project.ext.dir}/run/commons-io.jar"/>
    <pathelement location="${project.ext.dir}/run/commons-lang.jar"/>
    <pathelement location="${project.ext.dir}/run/commons-validator.jar"/>
    <pathelement location="${project.ext.dir}/run/commons-vfs.jar"/>
    <pathelement location="${project.ext.dir}/run/commons-net.jar"/>
    <pathelement location="${project.ext.dir}/run/hibernate.jar"/>
    <pathelement location="${project.ext.dir}/run/hibernate-validator.jar"/>
    <pathelement location="${project.ext.dir}/run/jboss-seam.jar"/>
    <pathelement location="${project.ext.dir}/run/persistence-api.jar"/>
    <!-- added for jdk 1.8 --> 
    <pathelement location="${project.ext.dir}/run/jta.jar"/>

    <pathelement location="${project.ext.dir}/run/jsf-api.jar"/>
    <pathelement location="${project.ext.dir}/run/jcaptcha-all.jar"/>
    <pathelement location="${project.ext.dir}/run/richfaces-ui-3.3.1.CR3.jar"/>
    <pathelement location="${project.ext.dir}/run/richfaces-impl-3.3.1.CR3.jar"/>
    <pathelement location="${project.ext.dir}/run/yarfraw.jar"/>
    <pathelement location="${project.ext.dir}/wrapper/${platform}/lib/wrapper.jar"/>
</path>

0 个答案:

没有答案