dependency.dependency.version'丢失错误

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

我正在尝试使用 apache maven 创建一个包。当我运行

mvn clean install
命令时,出现以下错误:

缺少

dependency.dependency.version' javax.servlet:servlet-api.jar

我已将“servlet-api.jar”放置在我的项目的资源文件夹中

有人可以告诉我应该将该 jar 文件放在哪里吗?

更新: 这是我的 pom.xml

    <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">

 <parent>
   <artifactId>felix-parent</artifactId>
   <groupId>org.apache.felix</groupId>
   <version>2.1</version>
   <relativePath>../pom/pom.xml</relativePath>
 </parent>

 <modelVersion>4.0.0</modelVersion>

 <artifactId>maven-bundle-plugin</artifactId>
 <version>2.4.1-SNAPSHOT</version>
 <packaging>maven-plugin</packaging>

 <name>Maven Bundle Plugin</name>
 <description>
  Provides a maven plugin that supports creating an OSGi bundle
  from the contents of the compilation classpath along with its
  resources and dependencies. Plus a zillion other features.
  The plugin uses the Bnd tool (http://www.aqute.biz/Code/Bnd)
 </description>

 <scm>
  <connection>scm:svn:http://svn.apache.org/repos/asf/felix/trunk/bundleplugin</connection>
  <developerConnection>scm:svn:https://svn.apache.org/repos/asf/felix/trunk/bundleplugin</developerConnection>
  <url>http://svn.apache.org/repos/asf/felix/trunk/bundleplugin</url>
 </scm>

 <build>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-compiler-plugin</artifactId>
    <configuration>
     <source>1.5</source>
     <target>1.5</target>
    </configuration>
   </plugin>
  </plugins>
 </build>

 <dependencies>
        <!-- Provided APIs -->
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>servlet-api</artifactId>
        </dependency>

    </dependencies>

 <reporting>
  <plugins>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-plugin-plugin</artifactId>
    <version>3.2</version>
   </plugin>
   <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-changes-plugin</artifactId>
    <version>2.9</version>
    <configuration>
     <component>12311143</component>
     <versionPrefix>maven-bundle-plugin-</versionPrefix>
     <statusIds>Resolved,Closed</statusIds>
     <maxEntries>1000</maxEntries>
     <issueManagementSystems>
      <issueManagementSystem>JIRA</issueManagementSystem>
     </issueManagementSystems>
     <useJql>true</useJql>
    </configuration>
   </plugin>
  </plugins>
 </reporting>

</project>

谢谢 安德森

java maven-2 osgi-bundle
4个回答
24
投票

您尚未在

version
中添加
dependency
标签。

<dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>1.0.0</version>   //Add the version.
</dependency>

11
投票

由于略有不同的原因,我遇到了同样的错误。

我的项目使用依赖管理(由于某种原因有 2 个

<dependencyManagement>
部分)并且有许多模块和子模块。

顶级 pom 具有:

    <dependencyManagement>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.10</artifactId>
            <version>${spark.version}</version>
        </dependency>
    </dependencyManagement>

子级别pom有

    <dependencyManagement>
        <dependency>
            <groupId>org.apache.spark</groupId>
            <artifactId>spark-core_2.10</artifactId>
            <scope>provided</scope>
        </dependency>
    </dependencyManagement>

叶球

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.10</artifactId>
    </dependency>

为了解决这个问题,我从中层 pom 中删除了

<dependencyManagement>
部分,并将 leaf pom 更改为具有

    <dependency>
        <groupId>org.apache.spark</groupId>
        <artifactId>spark-core_2.10</artifactId>
        <scope>provided</scope>
    </dependency>

3
投票

消息非常明确:在 pom 的

dependencies
元素内,有一个
dependency
元素和人工制品
javax.servlet:servlet-api.jar
。而在这个
dependency
元素里面,一定有一个 version 元素,但是你没有提供它。

<dependencies>
    <!-- Provided APIs -->
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>

        <!-- missing version here: -->
        <version>3.0</version>
    </dependency>
</dependencies>

请注意,3.0 只是一个示例。提供正确的版本。


0
投票

您必须添加依赖项,并且版本和范围是可选的。 目前 javax.servlet 的最新版本是 3.0-alpha-1。

<!-- https://mvnrepository.com/artifact/javax.servlet/servlet-api -->
   <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>servlet-api</artifactId>
      <version>3.0-alpha-1</version>
      <scope>provided</scope>
   </dependency>
© www.soinside.com 2019 - 2024. All rights reserved.