marisusis
marisusis

Reputation: 342

How to change jar output directory when running as maven install in Eclipse?

I am making a Minecraft plugin for Bukkit 1.8, and everything works fine. I right click on the project name > Run As > Maven install. It outputs the .jar file to the target directory. I then copy the file to the plugins folder of my Minecraft server.

I would like to have it output the jar directly into my plugins folder.

Upvotes: 3

Views: 2695

Answers (1)

Tunaki
Tunaki

Reputation: 137319

A simple way to do that would be to bind an execution of the maven-antrun-plugin to the install phase. This execution would copy the main artifact to the Minecraft server folder.

<plugin>
  <groupId>org.apache.maven.plugins</groupId>
  <artifactId>maven-antrun-plugin</artifactId>
  <version>1.8</version>
  <executions>
    <execution>
      <phase>install</phase>
      <configuration>
        <target>
          <copy file="${project.build.directory}/${project.build.finalName}.jar"
                todir="/path/to/server/plugins" />
        </target>
      </configuration>
      <goals>
        <goal>run</goal>
      </goals>
    </execution>
  </executions>
</plugin>

(This snippet must be placed inside the <build><plugins> element).

Running mvn clean install (or "Run As... > Maven Install" in Eclipse), Maven will do what you want. ${project.build.directory}/${project.build.finalName}.jar refers to the main artifact present in the build directory (which is target by default). You'll need to update the path to the server in the snippet above.

Upvotes: 2

Related Questions