简体   繁体   English

检查库是否适用于特定的Java版本

[英]Check if library will work on a specific verion of Java

What approach can be taken to verify that a library is compatible on a specific version of Java? 可以采用什么方法来验证库是否与特定版本的Java兼容?

Example: Library X was compiled on Java 1.7, therefor it might not work on Java 1.7 or lower. 示例:库X是在Java 1.7上编译的,因此它可能无法在Java 1.7或更低版​​本上运行。

Thank you. 谢谢。

The best is to check the byte code via an enforcer rule which can be applied to your build by using the maven-enforcer-plugin ... 最好的方法是通过强制规则检查字节代码,该规则可以通过使用maven-enforcer-plugin应用于您的构建...

<project>
  [...]
  <build>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-enforcer-plugin</artifactId>
        <version>1.4.1</version>
        <executions>
          <execution>
            <id>enforce-bytecode-version</id>
            <goals>
              <goal>enforce</goal>
            </goals>
            <configuration>
              <rules>
                <enforceBytecodeVersion>
                  <maxJdkVersion>1.7</maxJdkVersion>
                </enforceBytecodeVersion>
              </rules>
              <fail>true</fail>
            </configuration>
          </execution>
        </executions>
        <dependencies>
          <dependency>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>extra-enforcer-rules</artifactId>
            <version>1.0-beta-4</version>
          </dependency>
        </dependencies>
      </plugin>
    </plugins>
  </build>
  [...]
</project>

compile with the version you want: 使用您想要的版本进行编译:

javac -target ...

see that: How do i compile a .java with support for older versions of java? 看到: 我如何编译支持旧版Java的.java?

and check jar dependencies: with Jdepend for example 并检查jar依赖项:例如使用Jdepend

Analyze JAR dependencies in a Java project 分析Java项目中的JAR依赖项

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM