英文:
Maven - URI is non hierarchial
问题
我正在尝试学习Spring和Maven,但我遇到了一些问题。
当我在终端中运行我的测试使用 mvn clean install
时,我得到了这个错误:java.lang.IllegalArgumentException: URI is not hierarchical。这是引发错误的代码块:
LocationWeatherRootResponseTest.class.getClassLoader().getResource("extent.xml")).toURI()
当我将上面的代码更改为以下内容时,我得到了空指针异常。
LocationWeatherRootResponseTest.class.getClassLoader().getResourceAsStream("extent.xml")))
更新
当我将代码更改为以下内容时,我得到了一个新的错误。
File file = new File(WeatherTest.class.getClassLoader().getResource("extent.xml").getPath());
Reporter.loadXMLConfig(file);
堆栈跟踪:
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 :
LocationWeatherRootResponseTest.class.getClassLoader().getResource("extent.xml")).toURI()
When I change the above code to the following Im getting a null pointer exception.
LocationWeatherRootResponseTest.class.getClassLoader().getResourceAsStream("extent.xml")))
Update
When I change the code to the below Im getting a new error.
File file = new File(WeatherTest.class.getClassLoader().getResource("extent.xml").getPath());
Reporter.loadXMLConfig(file);
stacktrace :
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
我使用了 `maven-remote-resources-plugin` 解决了这个问题。现在当我在主 `POM` 上运行 `mvn clean install` 时,框架从 e2e 运行。
在包含我想要共享资源的模块中,我在 POM 文件中添加了以下内容:
<build>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.7.0</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*.xml</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
在我想要使用该资源的模块中,我添加了以下内容:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.7.0</version>
<configuration>
<resourceBundles>
<resourceBundle>{groupId}:{resource artifactId}:1.0-SNAPSHOT</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</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
<build>
<plugins>
<plugin>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.7.0</version>
<executions>
<execution>
<goals>
<goal>bundle</goal>
</goals>
</execution>
</executions>
<configuration>
<includes>
<include>**/*.xml</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
In the module where I want to use the resource. I added the following
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-remote-resources-plugin</artifactId>
<version>1.7.0</version>
<configuration>
<resourceBundles>
<resourceBundle>{groupId}:{resource artifactId}:1.0-SNAPSHOT</resourceBundle>
</resourceBundles>
</configuration>
<executions>
<execution>
<goals>
<goal>process</goal>
</goals>
</execution>
</executions>
</plugin>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论