Why can't my jar files and my .war file be fou

2019-07-04 19:31发布

问题:

Ok so I'm trying to test my Maven app locally with this command:

java -jar target/dependency/jetty-runner.jar target/*.war

But I'm getting this error:

"Unable to access jarfile target/dependency/jetty-runner.jar."

It also can't seem to access my .war file. I don't know what's going on. I tried manually downloading the jetty-runner.jar file and exporting my project into a war, and then running the command from my desktop where the two files were located, and that worked. So it's gotta be a problem with finding these files.

I found that code online. What is the target/dependency folder? Why isn't my jetty-runner there? It is also unable to find the .war file in target. I know this cause I used my manually downloaded jetty-runner.jar with target/.war and it still failed with this:

"java.net.MalformedURLException: no protocol: target/*war"

I did include the jetty-runner in my pom.xml:

<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.3</version>
<executions>
    <execution>
        <phase>package</phase>
        <goals><goal>copy</goal></goals>
        <configuration>
            <artifactItems>
                <artifactItem>
                    <groupId>org.mortbay.jetty</groupId>
                    <artifactId>jetty-runner</artifactId>
                    <version>7.4.5.v20110725</version>
                    <destFileName>jetty-runner.jar</destFileName>
                </artifactItem>
            </artifactItems>
        </configuration>
    </execution>
</executions>

So what gives? What is this target folder? and why can't anything be found? Thanks!

回答1:

Solved it, had to run:

mvn package

or in my case, I ran my project as Maven Build... in eclipse and typed "package" into goal. This put the files in the necessary places