相关疑难解决方法(0)

正确修复Java 10抱怨jaxb-impl 2.3.0的非法反射访问?

我们正在考虑将一些遗留代码升级到Java 10.由于JAXB默认不可见(编辑:正确的长期解决方案不是使用各种JVM标志来规避症状,而是正确修复它)我已将此片段添加到我的pom.xml:

    <!-- https://mvnrepository.com/artifact/javax.xml.bind/jaxb-api -->
    <dependency>
        <groupId>javax.xml.bind</groupId>
        <artifactId>jaxb-api</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-core</artifactId>
        <version>2.3.0</version>
    </dependency>
    <dependency>
        <groupId>com.sun.xml.bind</groupId>
        <artifactId>jaxb-impl</artifactId>
        <version>2.3.0</version>
    </dependency>
Run Code Online (Sandbox Code Playgroud)

不幸的是,在stderr启动时仍然会出现警告.显然这不是正确的解决方法.

WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.sun.xml.bind.v2.runtime.reflect.opt.Injector (file:/home/tra/.m2/repository/com/sun/xml/bind/jaxb-impl/2.3.0/jaxb-impl-2.3.0.jar) to method java.lang.ClassLoader.defineClass(java.lang.String,byte[],int,int)
WARNING: Please consider reporting this to the maintainers of com.sun.xml.bind.v2.runtime.reflect.opt.Injector
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Run Code Online (Sandbox Code Playgroud)

完整的输出--illegal-access=debug是:

WARNING: Illegal …
Run Code Online (Sandbox Code Playgroud)

java jaxb maven java-10

36
推荐指数
3
解决办法
8850
查看次数

--add-modules仅用于编译

我正在使用maven和构建我的项目.我在我的pom.xml文件中添加了:

<plugin>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>${maven-compiler-plugin.version}</version>
    <configuration>
        <source>${java.version}</source>
        <target>${java.version}</target>
        <compilerArgs>
            <arg>--add-modules</arg>
            <arg>java.xml.bind</arg>
        </compilerArgs>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

但是,为了运行应用程序,我必须像这样运行它:

java -jar --add-modules java.xml.bind my-app.jar
Run Code Online (Sandbox Code Playgroud)

有没有办法构建应用程序,从命令行运行而不是--add-modules java.xml.bindjava命令行参数?

java jaxb maven maven-compiler-plugin java-9

27
推荐指数
1
解决办法
3万
查看次数

Maven:javac:源版本1.6需要目标版本1.6

注意:这似乎是"javac"程序中的限制.

我有需要为Java 5 JVM构建的Java 6代码.我之前使用javac ant目标(使用JDK编译器和ecj)的工作使我相信它只是设置javac的源和目标.因此这个pom.xml片段:

<plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <version>2.3.2</version>
    <configuration>
        <source>1.6</source>
        <target>1.5</target>
    </configuration>
</plugin>
Run Code Online (Sandbox Code Playgroud)

它可以在Eclipse 3.7中使用Maven支持按预期工作.不幸的是,直接从命令行运行Maven给了我

javac: source release 1.6 requires target release 1.6
Run Code Online (Sandbox Code Playgroud)

与生成的相同javac -source 1.6 -target 1.5.为了澄清,这是Ubuntu的官方OpenJDK 6

x@JENKINS:~$ javac -version
javac 1.6.0_20
x@JENKINS:~$ javac -source 1.6 -target 1.5
javac: source release 1.6 requires target release 1.6
x@JENKINS:~$
Run Code Online (Sandbox Code Playgroud)

官方Oracle Java 7 JDK for Windows显示了相同的行为.

注意:我不想构建Java 5库或任何东西.只是活动的javac生成Java 5 兼容的字节码.

如何在仍然与Eclipse Maven插件兼容的同时获得我想要的内容?

(编辑:除了@Override我还想在Java 6中使用JAX-WS库进行编译时使用,但仍然生成Java 5字节代码 - 我可以在部署时故意在Web容器中添加JAX-WS库到Java 5安装)


编辑:事实证明maven-compiler-plugin可以被告知使用另一个编译器,Eclipse编译器可以这样做:

        <plugin>
            <!-- Using the eclipse compiler allows …
Run Code Online (Sandbox Code Playgroud)

java javac maven

26
推荐指数
2
解决办法
5万
查看次数

标签 统计

java ×3

maven ×3

jaxb ×2

java-10 ×1

java-9 ×1

javac ×1

maven-compiler-plugin ×1