Maven 3神器问题

Mar*_*ens 33 java eclipse struts2 m2eclipse maven-3

我使用struts2-archtype-starter在eclipse中创建了一个新的struts项目.

在做任何事情之前我的项目中已经出现了一些错误.解决了他们中的大多数,但有1仍然给我一些问题.

Missing artifact com.sun:tools:jar:1.5.0:system pom.xml

我试图手动将tools.jar添加到我的存储库,但这并没有解决问题.

我的pom看起来像这样

<?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/maven-v4_0_0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>com.divespot</groupId>
    <artifactId>website</artifactId>
    <packaging>war</packaging>
    <version>0.0.1-SNAPSHOT</version>
    <name>E-Divespot diving community</name>
    <url>http://www.e-divespot.com</url>
    <description>A website to support divers from all around the world.</description>

    <dependencies>
        <!-- Junit -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.8.2</version>
            <scope>test</scope>
        </dependency>

        <!--  Struts 2 -->
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-core</artifactId>
            <version>2.0.11.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-sitemesh-plugin</artifactId>
            <version>2.0.11.2</version>
        </dependency>
        <dependency>
            <groupId>org.apache.struts</groupId>
            <artifactId>struts2-spring-plugin</artifactId>
            <version>2.0.11.2</version>
        </dependency>

        <!-- Servlet & Jsp -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
            <version>2.4</version>
            <scope>provided</scope>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jsp-api</artifactId>
            <version>2.0</version>
            <scope>provided</scope>
        </dependency>

        <!-- Jakarta Commons -->
        <dependency>
            <groupId>commons-fileupload</groupId>
            <artifactId>commons-fileupload</artifactId>
            <version>1.1.1</version>
        </dependency>

        <!-- Dwr -->
        <dependency>
            <groupId>uk.ltd.getahead</groupId>
            <artifactId>dwr</artifactId>
            <version>1.1-beta-3</version>
        </dependency>
    </dependencies>

    <build>
      <finalName>website</finalName>
        <plugins>
            <plugin>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                   <source>1.6</source>
                   <target>1.6</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.mortbay.jetty</groupId>
                <artifactId>maven-jetty-plugin</artifactId>
                <version>6.1.5</version>
                <configuration>
                    <scanIntervalSeconds>10</scanIntervalSeconds>
                </configuration>
            </plugin>
        </plugins>
    </build>
</project>
Run Code Online (Sandbox Code Playgroud)

Joh*_*int 45

您看到的错误可能是因为您没有正确设置JAVA_HOME路径.你看到类似的东西C:\{directories to jre}\..\lib\tools.jar吗?

您可以通过更改eclipse.ini并添加类似的东西,使用内置的JDK启动eclipse

-vm
C:\{directories to JDK}\bin\javaw.exe
Run Code Online (Sandbox Code Playgroud)

我学到的是默认情况下eclipse将使用你的系统jre来启动eclipse.您可能在启动eclipse时看到了一条消息,类似于"Eclipse在JRE下运行而m2eclipse需要JDK,某些插件无法正常工作"

如果你去(在eclipse中)帮助 - >安装细节并寻找-vm,你可能会看到它指向一个没有它期望的路径结构的地方.

注意:出于任何原因,当我遇到此问题时,maven中的java.home是从eclipse的启动位置进行评估的.因此,当它试图将tools.jar从它看作java.home时拉出来时,它实际上可能不是你实际设置为env/system变量的JAVA_HOME.

  • 你想确保它在-vmargs之前放置在正确的位置,你可能需要在该位置周围加上引号(即Program Files ...).我会花时间尝试让这个工作,因为我相信它会解决你的问题. (3认同)

Tha*_*asu 10

<dependency>
    <groupId>org.apache.struts</groupId>
    <artifactId>struts2-core</artifactId>
    <version>${struts2.version}</version>
    <exclusions>
        <exclusion>
            <artifactId>tools</artifactId>
            <groupId>com.sun</groupId>
        </exclusion>
    </exclusions>
</dependency>
Run Code Online (Sandbox Code Playgroud)