没有在下载的Selenium jar中找到Java类。

huangapple go评论84阅读模式
英文:

No java classes in downloaded Selenium jar

问题

我正在尝试升级到 Selenum 4.0.0-alpha-6(同样的问题也发生在版本 3.141.59),这个版本似乎可以在 [Maven 仓库](https://mvnrepository.com/artifact/org.seleniumhq.selenium/selenium-java) 中找到。我首先尝试将此依赖项添加到我的 pom.xml 文件中:

<dependency>            
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.0.0-alpha-6</version>
</dependency>

在 IntelliJ 中,该版本显示为红色,因为某种原因它将 3.12.0 视为最后可用版本。我知道 IntelliJ 看到的版本是因为我可以在 \<version\> 标签内部按下 CTRL-space。

运行 `mvn install` 也会抱怨找不到该版本。所以我的第一个问题是,为什么 IntelliJ 和 Maven 看不到 Selenium 的最新版本?

我回退到直接从 mvnrepository 下载 jar 文件(即从 [这里](https://repo1.maven.org/maven2/org/seleniumhq/selenium/selenium-java/4.0.0-alpha-6/selenium-java-4.0.0-alpha-6.jar) 下载),然后将其添加到我的本地仓库,如下所示:

mvn install:install-file -Dfile=selenium-java-4.0.0-alpha-6.jar 
-DgroupId=org.seleniumhq.selenium -DartifactId=selenium-java 
-Dversion=4.0.0-alpha-6 -Dpackaging=jar -DgeneratePom=true

现在,该 jar 文件出现在我的本地仓库中,Maven 依赖项不再显示为红色,但是我项目中所有与 Selenium 相关的引用都显示为红色。检查下载的 jar 文件发现它不包含 Java 类:

C:\Development\Java\Selenium>jar tf selenium-java-4.0.0-alpha-6.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/versions/9/
META-INF/versions/9/module-info.class

有什么想法我可能漏掉了什么?

更新:我在 [GitHub 上添加了一个小项目][1] 来演示这个问题。pom 文件只包含了 Selenium 依赖项。
只是运行 mvn install 会导致下面的错误。所以这不仅仅是 IntelliJ 的问题:

[ERROR] Failed to execute goal on project MySeleniumProject: Could not resolve dependencies for project com.my:MySeleniumProject:jar:1.0-SNAPSHOT: Failed to collect dependencies for [org.seleniumhq.selenium:selenium-java:jar:3.141.59 (compile)]: Failed to read artifact descriptor for org.seleniumhq.selenium:selenium-ja
va:jar:3.141.59: Could not transfer artifact org.seleniumhq.selenium:selenium-java:pom:3.141.59 from/to central (http://repo.maven.apache.org/maven2): Failed to
transfer file: http://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-java/3.141.59/selenium-java-3.141.59.pom. Return code is: 501 , ReasonPhras
e:HTTPS Required.


  [1]: https://github.com/yschondorf/pomTest
英文:

I am trying to upgrade to Selenum 4.0.0-alpha-6 (same issue happens also with version 3.141.59) which seems to be available in Maven repository. I tried first to add this dependency to my pom.xml:

<dependency>            
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>4.0.0-alpha-6</version>
</dependency>

The version appears red in IntelliJ which for some reason sees 3.12.0 as the last available version. I know what version IntelliJ sees because I can hit CTRL-space inside the <version> tag.

Running mvn install also complains that the version is not available. So my first question is why do Intellij and Maven not see the latest versions of Selenium?

I reverted to downloading the jar file directly from mvnrepository (that is from here) and adding it to my local repository as follows:

mvn install:install-file -Dfile=selenium-java-4.0.0-alpha-6.jar 
-DgroupId=org.seleniumhq.selenium -DartifactId=selenium-java 
-Dversion=4.0.0-alpha-6 -Dpackaging=jar -DgeneratePom=true

The jar appears now in my local repo, the Maven dependency does not appear red anymore, but all Selenium-related references in my project appear red. Examining the downloaded jar file reveals that it contains no Java classes:

C:\Development\Java\Selenium>jar tf selenium-java-4.0.0-alpha-6.jar
META-INF/
META-INF/MANIFEST.MF
META-INF/versions/9/
META-INF/versions/9/module-info.class

Any idea what I am missing?

Update: I have added a small project in GitHub that demonstrates the problem. The pom just has the Selenium dependency.
Just running mvn install results in the error below. So this is not just a problem with IntelliJ:

[ERROR] Failed to execute goal on project MySeleniumProject: Could not resolve dependencies for project com.my:MySeleniumProject:jar:1.0-SNAPSHOT: Failed to collect dependencies for [org.seleniumhq.selenium:selenium-java:jar:3.141.59 (compile)]: Failed to read artifact descriptor for org.seleniumhq.selenium:selenium-ja
va:jar:3.141.59: Could not transfer artifact org.seleniumhq.selenium:selenium-java:pom:3.141.59 from/to central (http://repo.maven.apache.org/maven2): Failed to
 transfer file: http://repo.maven.apache.org/maven2/org/seleniumhq/selenium/selenium-java/3.141.59/selenium-java-3.141.59.pom. Return code is: 501 , ReasonPhras
e:HTTPS Required.

答案1

得分: 0

尝试使用稳定的旧版本

<dependency>
    <groupId>org.seleniumhq.selenium</groupId>
    <artifactId>selenium-java</artifactId>
    <version>3.141.59</version>
</dependency>

同时检查一下,如果在pom文件中有其他错误,并且确保使用了正确的Java版本。

英文:

Try use stable older version

&lt;dependency&gt;
    &lt;groupId&gt;org.seleniumhq.selenium&lt;/groupId&gt;
    &lt;artifactId&gt;selenium-java&lt;/artifactId&gt;
    &lt;version&gt;3.141.59&lt;/version&gt;
&lt;/dependency&gt;

Check also, if you have other errors in pom, and have proper java version

答案2

得分: 0

我认为您的项目是正确的,问题出在Maven配置上。使用命令行查看您使用的Maven版本:maven -v。尝试在项目上使用mvn dependency:resolve命令 - 从命令行开始。

英文:

I think your project is correct and problem is with maven configuration. Use commandline to see what maven version you have? maven -v. Try use mvn dependency:resolve on the project - from command line

答案3

得分: 0

问题通过升级Maven解决。我之前使用的是Maven 3.0.5,升级到3.6.3后成功解决了依赖关系。

英文:

The problem is resolved by upgrading maven. I had Maven 3.0.5, and uprading to 3.6.3 resolved the dependency successfully.

huangapple
  • 本文由 发表于 2020年10月14日 14:40:27
  • 转载请务必保留本文链接:https://go.coder-hub.com/64347870.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定