Maven找不到Struts2依赖项

时间:2016-11-30 11:21:23

标签: java maven intellij-idea

我尝试使用maven和IntelliJ作为IDE设置Struts2项目。

但maven找不到大多数依赖项。例如:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId></groupId>
    <artifactId>brw</artifactId>
    <version>1.0-SNAPSHOT</version>
    <packaging>war</packaging>
    <name>brw</name>

    <properties>
        <struts2.version>2.5.5</struts2.version>
        <log4j2.version>${log4j2.version}</log4j2.version>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
    </properties>

    <dependencies>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-config-browser-plugin</artifactId>
            <version>${struts2.version}</version>
        </dependency>

        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-junit-plugin</artifactId>
            <version>${struts2.version}</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>org.apache.logging.log4j</groupId>
            <artifactId>log4j-core</artifactId>
            <version>${log4j2.version}</version>
        </dependency>

        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.5</version>
            <scope>test</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.1.0</version>
            <scope>provided</scope>
        </dependency>

        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

    </dependencies>

    <build>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <encoding>UTF-8</encoding>
                    <source>1.5</source>
                    <target>1.5</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>jetty-maven-plugin</artifactId>
                <version>8.1.16.v20140903</version>
                <configuration>
                    <stopKey>CTRL+C</stopKey>
                    <stopPort>8999</stopPort>
                    <systemProperties>
                        <systemProperty>
                            <name>xwork.loggerFactory</name>
                            <value>com.opensymphony.xwork2.util.logging.log4j2.Log4j2LoggerFactory</value>
                        </systemProperty>
                    </systemProperties>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                    <webAppSourceDirectory>${basedir}/src/main/webapp/</webAppSourceDirectory>
                    <webAppConfig>
                        <descriptor>${basedir}/src/main/webapp/WEB-INF/web.xml</descriptor>
                    </webAppConfig>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>

https://mvnrepository.com/artifact/org.apache.struts/struts2-core/2.5.5

的pom.xml

[INFO] Scanning for projects...
[ERROR] [ERROR] Some problems were encountered while processing the POMs:
[ERROR] Resolving expression: '${log4j2.version}': Detected the following recursive expression cycle in 'log4j2.version': [log4j2.version] @ 
[ERROR] Resolving expression: '${log4j2.version}': Detected the following recursive expression cycle in 'log4j2.version': [log4j2.version] @ 
[ERROR] 'dependencies.dependency.version' for org.apache.logging.log4j:log4j-core:jar must be a valid version but is '${log4j2.version}'. @ line 41, column 22
 @ 
[ERROR] The build could not read 1 project -> [Help 1]
[ERROR]   
[ERROR]   The project de.sambohl.brw:brw:1.0-SNAPSHOT (/Users/philipp/IdeaProjects/brw/pom.xml) has 3 errors
[ERROR]     Resolving expression: '${log4j2.version}': Detected the following recursive expression cycle in 'log4j2.version': [log4j2.version] -> [Help 2]
[ERROR]     Resolving expression: '${log4j2.version}': Detected the following recursive expression cycle in 'log4j2.version': [log4j2.version] -> [Help 2]
[ERROR]     'dependencies.dependency.version' for org.apache.logging.log4j:log4j-core:jar must be a valid version but is '${log4j2.version}'. @ line 41, column 22
[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/ProjectBuildingException
[ERROR] [Help 2] http://cwiki.apache.org/confluence/display/MAVEN/InterpolationCycleException

Process finished with exit code 1

错误

var test = 2;
var arrval= [1, 5, 2, 4];
var a = arrval.indexOf(test);
if(a>-1) console.log("Having");
else console.log("Not Having");

2 个答案:

答案 0 :(得分:2)

你的问题在这里

<log4j2.version>${log4j2.version}</log4j2.version>

确实,您的错误意味着“ $ {log4j2.version} ”不是有效版本。

您应该明确设置一个版本的log4j2而不是“ $ {log4j2.version} ”,例如,如果您想使用最新版本(可以使用2.7也是org.apache.struts:struts2-core:2.5.5依赖的版本,请参阅现有版本列表here

所以试试这个

<log4j2.version>2.7</log4j2.version>

答案 1 :(得分:0)

问题在于&lt; log4j2.version&gt;属性。

POM文件中的属性应该是一个常量值,可以在引用该属性时替换它。但在你的情况下,你指向同一属性,这是一个错误。

如果您想要包含特定版本,请在&lt; log4j2.version&GT;标签如:

&LT; log4j2.version&GT; 1.2.17&LT; /log4j2.version>

或者您可以使用

&LT; log4j2.version&GT;最新&LT; /log4j2.version>,

'LATEST'关键字可以自动从maven存储库中选择最新版本的依赖关系