Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 324
Blessed Geek Avatar asked Aug 06 '10 07:08

Blessed Geek


2 Answers

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.

like image 152
Steven Francolla Avatar answered Nov 09 '22 08:11

Steven Francolla


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>
like image 37
Blessed Geek Avatar answered Nov 09 '22 09:11

Blessed Geek