我想将输出jar和jar-with-dependencies放入另一个文件夹(不在target/
但在../libs/
中)。
我该怎么做?
答案 0 :(得分:48)
您可以使用maven-jar-plugin的 outputDirectory 参数来实现此目的:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<outputDirectory>../libs</outputDirectory>
</configuration>
</plugin>
...
</plugins>
</build>
...
</project>
但正如cdegroot写的那样,你最好不要对抗maven方式。
答案 1 :(得分:43)
如果要将工件复制到项目外的目录中,解决方案可能是:
maven-jar-plugin
并配置outputDirectory
maven-antrun-plugin
并复制任务copy-maven-plugin
作者:Evgeny Goldin copy-maven-plugin
的示例是:
<plugin>
<groupId>com.github.goldin</groupId>
<artifactId>copy-maven-plugin</artifactId>
<version>0.2.5</version>
<executions>
<execution>
<id>deploy-to-local-directory</id>
<phase>install</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<skipIdentical>false</skipIdentical>
<failIfNotFound>false</failIfNotFound>
<resources>
<resource>
<description>Copy artifact to another directory</description>
<targetPath>/your/local/path</targetPath>
<directory>${project.build.directory}</directory>
<includes>
<include>*.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
答案 2 :(得分:14)
另一种方式是maven-resources-plugin:
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
<executions>
<execution>
<id>copy-files-on-build</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/[TO-DIR]</outputDirectory>
<resources>
<resource>
<directory>[FROM-DIR]</directory>
<!--<include>*.[MIME-TYPE]</include>-->
<filtering>false</filtering>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
答案 3 :(得分:8)
我会这样做:
exports.urlPubkey = functions.https.onRequest((req, res) => {
database.ref('pubkeys').orderByChild('url').equalTo(req).once('value', snapshot =>
if (snapshot..hasChild(pubkey)) {
res.status(200).send(snapshot.val().pubkey)");
}
});
答案 4 :(得分:2)
这项技术对我很有用:
http://maven.apache.org/plugins/maven-dependency-plugin/examples/copying-artifacts.html
<project>
[...]
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>copy</id>
<phase>package</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<artifactItems>
<artifactItem>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<type>jar</type>
<overWrite>false</overWrite>
<outputDirectory>${project.build.directory}/alternateLocation</outputDirectory>
<destFileName>optional-new-name.jar</destFileName>
</artifactItem>
</artifactItems>
<outputDirectory>${project.build.directory}/wars</outputDirectory>
<overWriteReleases>false</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
[...]
</project>
答案 5 :(得分:0)
我特别喜欢使用 maven-resources-plugin
的解决方案(参见 here),因为它已经包含在 maven 中,所以不需要额外下载,并且非常可配置以在特定阶段进行复制您的项目(请参阅here以了解和理解阶段)。这种方法最好的部分是它不会弄乱您以前的任何流程或构建:)
<project>
...
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.2.0</version>
<executions>
<execution>
<id>copy-resources</id>
<!-- here the phase you need -->
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>/dir/where/you/want/to/put/jar</outputDirectory>
<resources>
<resource>
<directory>/dir/where/you/have/the/jar</directory>
<filtering>false</filtering>
<includes>
<include>file-you-want-to.jar</include>
<include>another-file-you-want-to.jar</include>
</includes>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
...
</build>
...
</project>
当然,您也可以在整个 XML 中使用内插变量,例如 ${baseDir}
和其他类似的好东西。你可以使用通配符来解释here