aspecj 访问 java 11 中的 sun 包

问题描述 投票:0回答:1

我正在使用 ValidatorException 类,该类位于 java 11 中的 sun.security.validator.ValidatorException 包内。但是我收到以下错误:

AJC 编译器错误: sun.security.validator.ValidatorException 类型不可访问

在 Maven 编译器中,我使用编译器参数 --add-exports java.base/sun.security.validator=ALL-UNNAMED 修复了这个问题

但是我不知道如何使用AspectJ插件。

我的 maven 编译器的 pom.xml 快照

<plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <configuration>
          <compilerArgs>
            <arg>--add-exports</arg><arg>java.base/sun.security.validator=ALL-UNNAMED</arg>
          </compilerArgs>
        </configuration>
        <executions>
          <execution>
            <id>default-compile</id>
            <phase>none</phase>
          </execution>
        </executions>
</plugin>

为aspectj插件拍摄我的pom.xml

  <plugin>
    <groupId>org.codehaus.mojo</groupId>
    <artifactId>aspectj-maven-plugin</artifactId>
    <version>1.7</version>
    <configuration>
      <showWeaveInfo>true</showWeaveInfo>
      <verbose>true</verbose>
      <source>11</source>
      <target>11</target>
      <complianceLevel>11</complianceLevel>
    </configuration>
    <executions>
      <execution>
        <id>compile-with-aspectj</id>
        <phase>compile</phase>
        <goals>
          <goal>compile</goal>
        </goals>
        <configuration>
          <weaveDirectories>
            <weaveDirectory>${project.build.outputDirectory}/aspectJ-classes</weaveDirectory>
          </weaveDirectories>
        </configuration>
      </execution>
    </executions>
    <dependencies>
      <dependency>
        <groupId>com.sun</groupId>
        <artifactId>tools</artifactId>
        <version>11</version>
        <scope>system</scope>
        <systemPath>${project.basedir}/pom.xml</systemPath>
      </dependency>

      <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjrt</artifactId>
        <version>1.9.6</version>
      </dependency>
      <dependency>
        <groupId>org.aspectj</groupId>
        <artifactId>aspectjtools</artifactId>
        <version>1.9.6</version>
      </dependency>

    </dependencies>
  </plugin>
java maven java-11 aspectj-maven-plugin
1个回答
0
投票

https://github.com/eclipse-aspectj/aspectj/pull/146#issuecomment-1079883826

https://github.com/mojohaus/aspectj-maven-plugin/issues/139

https://github.com/eclipse-aspectj/aspectj/issues/145

使用我需要的其他两个不同包的示例

      import sun.security.tools.keytool.CertAndKeyGen;
      import sun.security.x509.X500Name;

但你明白了:

        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>3.8.1</version>
            <configuration>
                <!--fixes:
                               [ERROR] exporting a package from system module java.base is not allowed with &#45;&#45;releas-->
                <release combine.self="override"/>

                <compilerArgs>
                    <arg>--add-exports</arg>
                    <arg>java.base/sun.security.x509=ALL-UNNAMED</arg>
                    
                    <arg>--add-exports</arg>
                    <arg>java.base/sun.security.tools.keytool=ALL-UNNAMED</arg>
                </compilerArgs>
                <!-- this fixes: [142,6] error: cannot find symbol [ERROR]   symbol:   class sun.security.tools.keytool.CertAndKeyGen -->

                <source>${java.source.version}</source>
                <target>${java.target.version}</target>
                <showDeprecation>true</showDeprecation>
                <showWarnings>true</showWarnings>
            </configuration>
        </plugin>



        <!-- AspectJ Compile Time Weaving -->
        <plugin>
            <groupId>org.codehaus.mojo</groupId>
            <artifactId>aspectj-maven-plugin</artifactId>
            <configuration>
                <source>${java.source.version}</source>
                <target>${java.target.version}</target>
                <complianceLevel>${java.target.version}</complianceLevel>
                <XnoInline>true</XnoInline>
                <aspectLibraries>
                    <aspectLibrary>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-aspects</artifactId>
                    </aspectLibrary>
                </aspectLibraries>
                <verbose>true</verbose>
                <showWeaveInfo>true</showWeaveInfo>
                <additionalCompilerArgs>
                    <arg>--add-exports</arg>
                    <arg>java.base/sun.security.x509=ALL-UNNAMED</arg>
                    
                    <!-- fix for:                       [ERROR]   (package sun.security.tools.keytool is declared in module java.base, which does not export it)-->
                    <arg>--add-exports</arg>
                    <arg>java.base/sun.security.tools.keytool=ALL-UNNAMED</arg>
                </additionalCompilerArgs>
            </configuration>
            <dependencies>
                <dependency>
                    <groupId>org.aspectj</groupId>
                    <artifactId>aspectjtools</artifactId>
                    <version>${org.aspectj.version}</version>
                </dependency>
            </dependencies>
            <executions>
                <execution>
                    <goals>
                        <goal>compile</goal>
                        <goal>test-compile</goal>
                    </goals>
                </execution>
            </executions>
        </plugin>
© www.soinside.com 2019 - 2024. All rights reserved.