Maven – URI is non-hierarchical

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

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

&lt;build&gt;
    &lt;plugins&gt;
        &lt;plugin&gt;
            &lt;artifactId&gt;maven-remote-resources-plugin&lt;/artifactId&gt;
            &lt;version&gt;1.7.0&lt;/version&gt;
            &lt;executions&gt;
                &lt;execution&gt;
                    &lt;goals&gt;
                        &lt;goal&gt;bundle&lt;/goal&gt;
                    &lt;/goals&gt;
                &lt;/execution&gt;
            &lt;/executions&gt;
            &lt;configuration&gt;
                &lt;includes&gt;
                    &lt;include&gt;**/*.xml&lt;/include&gt;
                &lt;/includes&gt;
            &lt;/configuration&gt;
        &lt;/plugin&gt;
    &lt;/plugins&gt;
&lt;/build&gt;

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

&lt;plugin&gt;
                    &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                    &lt;artifactId&gt;maven-remote-resources-plugin&lt;/artifactId&gt;
                    &lt;version&gt;1.7.0&lt;/version&gt;
                    &lt;configuration&gt;
                        &lt;resourceBundles&gt;
                            &lt;resourceBundle&gt;{groupId}:{resource artifactId}:1.0-SNAPSHOT&lt;/resourceBundle&gt;
                        &lt;/resourceBundles&gt;
                    &lt;/configuration&gt;
                    &lt;executions&gt;
                        &lt;execution&gt;
                            &lt;goals&gt;
                                &lt;goal&gt;process&lt;/goal&gt;
                            &lt;/goals&gt;
                        &lt;/execution&gt;
                    &lt;/executions&gt;
                &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:

确定