Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/400.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
不使用aspectj maven插件的Java模块_Java_Maven_Aspectj - Fatal编程技术网

不使用aspectj maven插件的Java模块

不使用aspectj maven插件的Java模块,java,maven,aspectj,Java,Maven,Aspectj,我正在尝试将java项目迁移到11并使用模块,但aspectj编译器似乎无法识别maven依赖项中的模块 错误: mvn clean compile [INFO] Scanning for projects... [INFO] [INFO] ---------------------------< com.test:test >---------------------------- [INFO] Building test 1 [INFO] -------------------

我正在尝试将java项目迁移到11并使用模块,但aspectj编译器似乎无法识别maven依赖项中的模块

错误:

mvn clean compile
[INFO] Scanning for projects...
[INFO] 
[INFO] ---------------------------< com.test:test >----------------------------
[INFO] Building test 1
[INFO] --------------------------------[ jar ]---------------------------------
[INFO] 
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) @ test ---
[INFO] Deleting /Users/piotr/Documents/mvntest/target
[INFO] 
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ test ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory /Users/piotr/Documents/mvntest/src/main/resources
[INFO] 
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) @ test ---
[INFO] Required filename-based automodules detected: [passay-1.6.0.jar]. Please don't publish this project to a public artifact repository!
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to /Users/piotr/Documents/mvntest/target/classes
[INFO] 
[INFO] --- aspectj-maven-plugin:1.12.6:compile (default) @ test ---
[INFO] Showing AJC message detail for messages of types: [error, warning, fail]
[ERROR] passay cannot be resolved to a module
    /Users/piotr/Documents/mvntest/src/main/java/module-info.java:2
requires passay;
         ^

[ERROR] Must declare a named package because this compilation unit is associated to the named module 'test'
    /Users/piotr/Documents/mvntest/src/main/java/main.java:1
(no source information available)

[ERROR] The type org.passay.PasswordValidator is not accessible
    /Users/piotr/Documents/mvntest/src/main/java/main.java:1
import org.passay.PasswordValidator;
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^

[ERROR] PasswordValidator cannot be resolved to a type
    /Users/piotr/Documents/mvntest/src/main/java/main.java:5
System.out.println(new PasswordValidator());
                       ^^^^^^^^

[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time:  2.169 s
[INFO] Finished at: 2020-12-14T10:22:00+01:00
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal com.nickwongdev:aspectj-maven-plugin:1.12.6:compile (default) on project test: AJC compiler errors:
[ERROR] error at requires passay;
[ERROR]          ^
[ERROR] /Users/piotr/Documents/mvntest/src/main/java/module-info.java:2:0::0 passay cannot be resolved to a module
[ERROR] error at (no source information available)
[ERROR] /Users/piotr/Documents/mvntest/src/main/java/main.java:1:0::0 Must declare a named package because this compilation unit is associated to the named module 'test'
[ERROR] error at import org.passay.PasswordValidator;
[ERROR]        ^^^^^^^^^^^^^^^^^^^^^^^^^^^
[ERROR] /Users/piotr/Documents/mvntest/src/main/java/main.java:1:0::0 The type org.passay.PasswordValidator is not accessible
[ERROR] error at System.out.println(new PasswordValidator());
[ERROR]                        ^^^^^^^^
[ERROR] /Users/piotr/Documents/mvntest/src/main/java/main.java:5:0::0 PasswordValidator cannot be resolved to a type
[ERROR] 
[ERROR] -> [Help 1]
[ERROR] 
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR] 
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoExecutionException
src/main/java/main.java:

import org.passay.PasswordValidator;

public class main {
    public static void main() {
        System.out.println(new PasswordValidator());
    }
}

为了实现这一点,AspectJ Maven插件必须至少支持AspectJ编译器ajc的命令行参数
--module info
,类似于javac。ajc命令行帮助中没有记录该参数的存在,而是间接记录在中

我以前从未使用过Java9+模块,尽管我出于其他原因使用了最新的Java版本。为了找出如何从命令行编译和运行您的项目,我必须进行一些实验,基本上是这样的:

ajc-11——模块路径“C:\Users\alexa\.m2\repository\org\passay\passay\1.6.0\passay-1.6.0.jar”-cp“C:\Users\alexa\.m2\repository\org\aspectj\aspectjrt\1.9.6\aspectjrt-1.9.6.jar”-sourceroot src\main\java-outjar target\test-1.jar
java——模块路径target\test-1.jar;C:\Users\alexa\.m2\repository\org\passay\passay\1.6.0\passay-1.6.0.jar;C:\Users\alexa\.m2\repository\org\aspectj\aspectjrt\1.9.6\aspectjrt-1.9.6.jar——模块测试/de.scrum\u master.stackoverflow.q65286736.Application
抱歉,我已将您的主类移到默认包之外,如下所示(
main
方法也是没有任何参数的伪代码):

模块测试{
需要通行证;
}
package de.scrum_master.stackoverflow.q65286736;
导入org.passay.PasswordValidator;
公共类应用程序{
公共静态void main(字符串[]args){
System.out.println(新密码验证器());
}
}
然后,我实验性地向插件添加了一个参数
javaModules
,正如您在我的。您可以通过克隆我的应用程序自行构建它

然后修改POM,如下所示:


4.0.0
com.test
测试
罐子
1.
11
UTF-8
1.9.6
org.passay
帕赛
1.6.0
org.aspectj
aspectjrt
${aspectj.version}
org.apache.maven.plugins
maven编译器插件
3.8.1
${java.version}
假的
com.nickwongdev
aspectj maven插件
1.12.7-快照
org.aspectj
aspectjtools
${aspectj.version}
${java.version}
${project.build.sourceEncoding}
真的
忽视
org.passay
帕赛
过程源
编译
测试编译
当然,决定性的区别在于新参数的使用:


org.passay
帕赛
现在项目已经编译,您还可以使用上面发布的第二个命令运行应用程序,即
java--module path target\test-1.jar。对于我来说,IntelliJ IDEA在POM语法突出显示中识别了新参数,并且运行应用程序时没有任何问题


这并不是对您所能想到的所有Java模块相关参数的完全支持,但我认为这是一个起点。欢迎反馈。

为了实现这一点,AspectJ Maven插件必须至少支持AspectJ编译器ajc的命令行参数
--module info
,类似于javac。ajc命令行帮助中没有记录该参数的存在,而是间接记录在中

我以前从未使用过Java9+模块,尽管我出于其他原因使用了最新的Java版本。为了找出如何从命令行编译和运行您的项目,我必须进行一些实验,基本上是这样的:

ajc-11——模块路径“C:\Users\alexa\.m2\repository\org\passay\passay\1.6.0\passay-1.6.0.jar”-cp“C:\Users\alexa\.m2\repository\org\aspectj\aspectjrt\1.9.6\aspectjrt-1.9.6.jar”-sourceroot src\main\java-outjar target\test-1.jar
java——模块路径target\test-1.jar;C:\Users\alexa\.m2\repository\org\passay\passay\1.6.0\passay-1.6.0.jar;C:\Users\alexa\.m2\repository\org\aspectj\aspectjrt\1.9.6\aspectjrt-1.9.6.jar——模块测试/de.scrum\u master.stackoverflow.q65286736.Application
抱歉,我已将您的主类移到默认包之外,如下所示(
main
方法也是没有任何参数的伪代码):

模块测试{
需要通行证;
}
package de.scrum_master.stackoverflow.q65286736;
导入org.passay.PasswordValidator;
公共类应用程序{
公共静态void main(字符串[]args){
System.out.println(新密码验证器());
}
}
然后,我实验性地向插件添加了一个参数
javaModules
,正如您在我的。您可以通过克隆我的应用程序自行构建它

然后修改POM,如下所示:


4.0.0
com.test
测试
罐子
1.
11
UTF-8
1.9.6
org.passay
帕赛
1.6.0
org.aspectj
aspectjrt
${aspectj.version}
org.apache.maven.plugins
maven编译器插件
3.8.1
${java.version}
假的
com.nickwongdev
aspectj maven插件
1.12.7-快照
org.aspectj
aspectjtools
${aspectj.version}
${java.version}
${project.build.sourceEncoding}
真的
忽视
module test {
    requires passay;
}
import org.passay.PasswordValidator;

public class main {
    public static void main() {
        System.out.println(new PasswordValidator());
    }
}