Maven – URI is non-hierarchical

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

Maven - URI is non hierarchial

问题

我正在尝试学习Spring和Maven,但我遇到了一些问题。

当我在终端中运行我的测试使用 mvn clean install 时,我得到了这个错误:java.lang.IllegalArgumentException: URI is not hierarchical。这是引发错误的代码块:

  1. LocationWeatherRootResponseTest.class.getClassLoader().getResource("extent.xml")).toURI()

当我将上面的代码更改为以下内容时,我得到了空指针异常。

  1. LocationWeatherRootResponseTest.class.getClassLoader().getResourceAsStream("extent.xml")))

更新

当我将代码更改为以下内容时,我得到了一个新的错误。

  1. File file = new File(WeatherTest.class.getClassLoader().getResource("extent.xml").getPath());
  2. Reporter.loadXMLConfig(file);

堆栈跟踪:

  1. java.io.FileNotFoundException: file:/home/user/IdeaProjects/spring-cucumber-test-harness/common/target/common-1.0-SNAPSHOT.jar!/extent.xml (No such file or directory)
英文:

Im trying learn Spring and Maven but im having some trouble.

When I go to run my tests from the terminal using mvn clean install I'm getting this error: java.lang.IllegalArgumentException: URI is not hierarchical . This is the block of code that throws the error :

  1. LocationWeatherRootResponseTest.class.getClassLoader().getResource("extent.xml")).toURI()

When I change the above code to the following Im getting a null pointer exception.

  1. LocationWeatherRootResponseTest.class.getClassLoader().getResourceAsStream("extent.xml")))

Update

When I change the code to the below Im getting a new error.

  1. File file = new File(WeatherTest.class.getClassLoader().getResource("extent.xml").getPath());
  2. Reporter.loadXMLConfig(file);

stacktrace :

  1. java.io.FileNotFoundException: file:/home/user/IdeaProjects/spring-cucumber-test-harness/common/target/common-1.0-SNAPSHOT.jar!/extent.xml (No such file or directory)

答案1

得分: 0

  1. 我使用了 `maven-remote-resources-plugin` 解决了这个问题。现在当我在主 `POM` 上运行 `mvn clean install` 时,框架从 e2e 运行。
  2. 在包含我想要共享资源的模块中,我在 POM 文件中添加了以下内容:
  3. <build>
  4. <plugins>
  5. <plugin>
  6. <artifactId>maven-remote-resources-plugin</artifactId>
  7. <version>1.7.0</version>
  8. <executions>
  9. <execution>
  10. <goals>
  11. <goal>bundle</goal>
  12. </goals>
  13. </execution>
  14. </executions>
  15. <configuration>
  16. <includes>
  17. <include>**/*.xml</include>
  18. </includes>
  19. </configuration>
  20. </plugin>
  21. </plugins>
  22. </build>
  23. 在我想要使用该资源的模块中,我添加了以下内容:
  24. <plugin>
  25. <groupId>org.apache.maven.plugins</groupId>
  26. <artifactId>maven-remote-resources-plugin</artifactId>
  27. <version>1.7.0</version>
  28. <configuration>
  29. <resourceBundles>
  30. <resourceBundle>{groupId}:{resource artifactId}:1.0-SNAPSHOT</resourceBundle>
  31. </resourceBundles>
  32. </configuration>
  33. <executions>
  34. <execution>
  35. <goals>
  36. <goal>process</goal>
  37. </goals>
  38. </execution>
  39. </executions>
  40. </plugin>
英文:

I managed to solve this issue using maven-remote-resources-plugin . Now when I run mvn clean install on the master POM the framework runs from e2e.

In the module containing the resources I wanted to share, I added the following to the POM file

  1. &lt;build&gt;
  2. &lt;plugins&gt;
  3. &lt;plugin&gt;
  4. &lt;artifactId&gt;maven-remote-resources-plugin&lt;/artifactId&gt;
  5. &lt;version&gt;1.7.0&lt;/version&gt;
  6. &lt;executions&gt;
  7. &lt;execution&gt;
  8. &lt;goals&gt;
  9. &lt;goal&gt;bundle&lt;/goal&gt;
  10. &lt;/goals&gt;
  11. &lt;/execution&gt;
  12. &lt;/executions&gt;
  13. &lt;configuration&gt;
  14. &lt;includes&gt;
  15. &lt;include&gt;**/*.xml&lt;/include&gt;
  16. &lt;/includes&gt;
  17. &lt;/configuration&gt;
  18. &lt;/plugin&gt;
  19. &lt;/plugins&gt;
  20. &lt;/build&gt;

In the module where I want to use the resource. I added the following

  1. &lt;plugin&gt;
  2. &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
  3. &lt;artifactId&gt;maven-remote-resources-plugin&lt;/artifactId&gt;
  4. &lt;version&gt;1.7.0&lt;/version&gt;
  5. &lt;configuration&gt;
  6. &lt;resourceBundles&gt;
  7. &lt;resourceBundle&gt;{groupId}:{resource artifactId}:1.0-SNAPSHOT&lt;/resourceBundle&gt;
  8. &lt;/resourceBundles&gt;
  9. &lt;/configuration&gt;
  10. &lt;executions&gt;
  11. &lt;execution&gt;
  12. &lt;goals&gt;
  13. &lt;goal&gt;process&lt;/goal&gt;
  14. &lt;/goals&gt;
  15. &lt;/execution&gt;
  16. &lt;/executions&gt;
  17. &lt;/plugin&gt;

huangapple
  • 本文由 发表于 2020年9月23日 08:28:55
  • 转载请务必保留本文链接:https://go.coder-hub.com/64019385.html
匿名

发表评论

匿名网友

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

确定