无法解决maven依赖:找不到javax.persistence:ejb:jar:3.0-public-draft-20



我试图复活一个旧的项目。我想使用Maven来管理依赖/构建等。,我已经走了很远,但是现在我遇到了一个错误,我似乎无法解决,我似乎找不到任何关于:

在项目scanit上执行目标失败:无法解析项目net.cbojar:scanit:jar:0.2:无法找到工件javax.persistence:ejb:jar:3.0-public-draft-20060327在maven2 (http://repo1.maven.org/maven2/)

它想下载一个ejb-3.0-public-draft-20060327.jar文件,但是这个文件在repo中不存在。

我对maven比较陌生,我想用这个作为实践,但我现在把自己画进了一个角落。下面是我的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/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <groupId>net.cbojar</groupId>
    <artifactId>scanit</artifactId>
    <version>1.0</version>
    <build>
        <sourceDirectory>${basedir}/src</sourceDirectory>
        <testSourceDirectory>${basedir}/test</testSourceDirectory>
        <outputDirectory>${basedir}/bin/classes</outputDirectory>
        <testOutputDirectory>${basedir}/bin/test</testOutputDirectory>
        <directory>${basedir}/bin</directory>
        <finalName>${project.artifactId}-${project.version}</finalName>
        <plugins>
            <plugin>
                <!-- Build an executable JAR -->
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>2.4</version>
                <configuration>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                            <mainClass>net.cbojar.scanit.App</mainClass>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <version>3.3</version>
                <configuration>
                    <source>8</source>
                    <target>8</target>
                </configuration>
            </plugin>
        </plugins>
    </build>
    <repositories>
        <repository>
            <id>maven2</id>
            <name>Central Maven Repository</name>
            <url>http://repo1.maven.org/maven2/</url>
            <layout>default</layout>
        </repository>
        <!--These are needed for Swing/Netbeans -->
        <repository>
            <id>maven2-repository.netbeans.maven2</id>
            <name>Netbeans Maven Repository</name>
            <url>http://bits.netbeans.org/maven2/</url>
            <layout>default</layout>
        </repository>
    </repositories>
    <dependencies>
        <!-- TODO: Update to JUnit 4 -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.netbeans.external</groupId>
            <artifactId>AbsoluteLayout</artifactId>
            <version>RELEASE701</version>
        </dependency>
        <dependency>
            <groupId>antlr</groupId>
            <artifactId>antlr</artifactId>
            <version>2.7.6</version>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm</artifactId>
            <version>1.5.3</version>
        </dependency>
        <dependency>
            <groupId>asm</groupId>
            <artifactId>asm-attrs</artifactId>
            <version>1.5.3</version>
        </dependency>
        <dependency>
            <groupId>cglib</groupId>
            <artifactId>cglib</artifactId>
            <version>2.1_3</version>
        </dependency>
        <dependency>
            <groupId>commons-collections</groupId>
            <artifactId>commons-collections</artifactId>
            <version>2.1.1</version>
        </dependency>
        <dependency>
            <groupId>commons-logging</groupId>
            <artifactId>commons-logging</artifactId>
            <version>1.0.4</version>
        </dependency>
        <dependency>
            <groupId>org.apache.derby</groupId>
            <artifactId>derby</artifactId>
            <version>10.2.2.0</version>
        </dependency>
        <dependency>
            <groupId>dom4j</groupId>
            <artifactId>dom4j</artifactId>
            <version>1.6.1</version>
        </dependency>
        <dependency>
            <groupId>net.sf.ehcache</groupId>
            <artifactId>ehcache</artifactId>
            <version>1.2.3</version>
        </dependency>
        <dependency>
            <groupId>org.freemarker</groupId>
            <artifactId>freemarker</artifactId>
            <version>2.3.23</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate</artifactId>
            <version>3.2.1.ga</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.1beta9</version>
        </dependency>
        <dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-commons-annotations</artifactId>
            <version>3.1.0.GA</version>
        </dependency>
        <dependency>
            <groupId>hibernate</groupId>
            <artifactId>hibernate-tools</artifactId>
            <version>2.1.3</version>
        </dependency>
        <dependency>
            <groupId>javax.transaction</groupId>
            <artifactId>jta</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>net.sf.jtidy</groupId>
            <artifactId>jtidy</artifactId>
            <version>r938</version>
        </dependency>
        <dependency>
            <groupId>org.netbeans</groupId>
            <artifactId>lib</artifactId>
            <version>3.6</version>
        </dependency>
        <dependency>
            <groupId>javax.persistence</groupId>
            <artifactId>persistence-api</artifactId>
            <version>1.0.2</version>
        </dependency>
        <dependency>
            <groupId>org.swinglabs</groupId>
            <artifactId>swing-layout</artifactId>
            <version>1.0.3</version>
        </dependency>
    </dependencies>
    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
    </properties>
</project>

既然要将现有项目转换为Maven,就应该尊重原始依赖项。这意味着将与原始依赖项完全相同的版本添加为Maven依赖项,并排除未使用的传递依赖项(因为原始项目不需要它,并且它可以正常工作,那么我们可以安全地将它们从pom中排除)。

表明javax.persistence:ejb:jar:3.0-public-draft-20060327org.hibernate:hibernate-annotations:3.1beta9的传递依赖关系。如果原始项目不需要它,您可以像这样将它从pom中排除:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.1beta9</version>
    <exclusions>
        <exclusion>
            <groupId>javax.persistence</groupId>
            <artifactId>ejb</artifactId>
        <exclusion>
    </exclusions>
</dependency>

删除

<dependency>
            <groupId>org.hibernate</groupId>
            <artifactId>hibernate-annotations</artifactId>
            <version>3.1beta9</version>
</dependency>

和使用:

<dependency>
    <groupId>org.hibernate</groupId>
    <artifactId>hibernate-annotations</artifactId>
    <version>3.5.6-Final</version>
</dependency>

这就是导致这个问题的依赖项。这是2006年的。我还建议您将依赖项版本更新到最新版本。

编辑

由于这样的升级可能会破坏您的代码,并且没有进一步的细节,您可能应该坚持使用更接近您试图使用的版本。

查看maven repo中所有可用的hibernate注释版本。

你可能需要在你的项目pom.xml:

    <dependency>
        <groupId>javax.persistence</groupId>
        <artifactId>ejb-3.0-public-draft</artifactId>
        <version>20050627</version>
        <type>pom</type>
    </dependency>

最新更新