How to copy dependencies to gae war/WEB-INF/lib

2019-04-09 01:07发布

I'm coming from Ant perspective, so pardon me. I realise there are quite a few questions here already on how to maven dependencies, but none of them seem to tell how to do what need to do.

Question 1: Currently, in conjunction with using maven-war-plugin, when I run mvn war:war, it creates a war folder in target folder.

However, I wish copy all the dependencies' jars to war/WEB-INF/lib set up by google eclipse plugin (with gae enabled, gwt disabled), without overwriting the jars that google eclipse plugin placed there.

I don't wish to setup a war file or war directory. I just need to copy/consolidate all the non-gae jars with the gae jars so that when the project is run as a gae web app, Eclipse would not complain ClassNotFoundException.

Question 2: When using Ant in Eclipse, I could run Ant targets within Eclipse.

Right now, I have to perform mvn commands from a shell window (which is mutually oblivious to the existence of an Eclipse session). It appears that the only thing that is automatically done is whenever I update dependencies.

Is there a way, or any plugin for eclipse that would allow me to run mvn goals within Eclipse?

Additional info:

mvn dependency:copy-dependencies persists in copying to target/dependency directory, with the following:

  <plugin>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>copy-dependencies</id>
        <phase>process-resources</phase>
        <goals>
          <goal>copy-dependencies</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>false</overWriteSnapshots>
          <overWriteIfNewer>true</overWriteIfNewer>
          <excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds>
        </configuration>
      </execution>
    </executions>
  </plugin>

I even tried changing to absolute path

<outputDirectory>
  /home/geek/eclipse/workspace/Demo-autoshoppe/holycow
</outputDirectory>

But holycow directory is still empty and mvn still persists in copying to target/dependency directory. My current solution is to softlink target/dependency as war/WEB-INF/lib, which is a very very bad kludge. Why is maven not sensitive to outputDirectory specification? I am using Ubuntu's maven 2.2.

3条回答
成全新的幸福
2楼-- · 2019-04-09 01:28

I have the real answer for you, my man.

Use the "default-cli" execution id. Make sure you're using Maven 2.2+. This exec-id applies to command-line executions of the mojo.

  <build>
    <pluginManagement>
      <plugins>
        <!-- Copy dependencies to war/WEB-INF/lib for GAE proj compliance. -->
        <plugin>
          <groupId>org.apache.maven.plugins</groupId>
          <artifactId>maven-dependency-plugin</artifactId>
          <executions>
            <execution>
              <id>default-cli</id>
              <goals>
                <goal>copy-dependencies</goal>
              </goals>
              <configuration>
                <outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory>
                <overWriteReleases>false</overWriteReleases>
                <overWriteSnapshots>false</overWriteSnapshots>
                <overWriteIfNewer>true</overWriteIfNewer>
                <excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds>
              </configuration>
            </execution>
          </executions>
        </plugin>
      </plugins>
    </pluginManagement>
  </build>

Cheers.

查看更多
倾城 Initia
3楼-- · 2019-04-09 01:31

An associate emailed me this answer which works. Trigger the follow through mvn build or mvn package but not directly thro mvn dependency:copy-dependencies.

  <plugin>
    <groupId>org.apache.maven.plugins</groupId>
    <artifactId>maven-dependency-plugin</artifactId>
    <executions>
      <execution>
        <id>copy-dependencies</id>
        <phase>package</phase>
        <goals>
          <goal>copy-dependencies</goal>
        </goals>
        <configuration>
          <outputDirectory>${basedir}/war/WEB-INF/lib/</outputDirectory>
          <overWriteReleases>false</overWriteReleases>
          <overWriteSnapshots>false</overWriteSnapshots>
          <overWriteIfNewer>true</overWriteIfNewer>
          <excludeArtifactIds>gwt-user,gwt-dev</excludeArtifactIds>
        </configuration>
      </execution>
    </executions>
  </plugin>
查看更多
Animai°情兽
4楼-- · 2019-04-09 01:47

Regarding #1: I'd suggest creating your maven project based off this plugin and archetype http://code.google.com/p/maven-gae-plugin/ (see the GWT based example if you are writing a GWT app for GAE).

Regarding #2: Check out m2eclipse plugin for full maven integration in eclipse. It's written by Sonatype (the creators of maven): http://m2eclipse.sonatype.org/

查看更多
登录 后发表回答