java 将 jar 与依赖项安装到 maven 存储库(Android gcm-server 推送库)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11989236/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Install jar with dependencies to maven repository (Android gcm-server push library)
提问by Sebastien Lorber
I work on an industrialized large maven project, and on an application module, I need to be able to send push notifications to Android (with new Google Cloud Messaging).
我在一个工业化的大型 maven 项目上工作,在一个应用程序模块上,我需要能够将推送通知发送到 Android(使用新的 Google Cloud Messaging)。
It seems google provide themselves the server-side library to send the notifications, and according to the mailing list they do not provide any maven repository.
似乎谷歌为自己提供了发送通知的服务器端库,并且根据邮件列表,他们不提供任何 maven 存储库。
The first step mentionned in the google documentation is:
谷歌文档中提到的第一步是:
Copy the gcm-server.jar file from the SDK's gcm-server/dist directory to your server classpath.
I'm not going to do that so i've added the jar to my local repository and will add it to our enterprise Nexus.
我不打算这样做,所以我已将 jar 添加到我的本地存储库并将其添加到我们的企业 Nexus。
mvn install:install-file
-Dfile=gcm-server.jar
-Dsources=gcm-server-sources.jar
-DgroupId=com.google.android.gcm
-DartifactId=gcm-server
-Dversion=r3
-DgeneratePom=true
-Dpackaging=jar
But i've just noticed that the library has dependencies (simple-json, mockito and junit). It's not precised if they are runtime or tests but i guess only simple-json is used at runtime. I think retrieving the GCM dependency from our Nexus should also permit to retrieve the transitive dependencies like this simple-json lib right?
但我刚刚注意到该库具有依赖项(simple-json、mockito 和 junit)。如果它们是运行时或测试,则不精确,但我想在运行时只使用 simple-json。我认为从我们的 Nexus 检索 GCM 依赖项也应该允许检索像这个 simple-json lib 这样的传递依赖项,对吗?
Thus what am i supposed to do? Should i create on my own a pom file for a project i don't own, and then import the project to my maven repository with -DpomFile=my-custom-pom.xml
?
所以我该怎么办?我应该为我不拥有的项目自己创建一个 pom 文件,然后使用 将项目导入我的 Maven 存储库-DpomFile=my-custom-pom.xml
吗?
Thanks
谢谢
回答by Sebastien Lorber
Finally i've ended creating my own pom.
最后,我结束了创建自己的 pom。
I've created a maven repository on github here: https://github.com/slorber/gcm-server-repository
我在 github 上创建了一个 maven 存储库:https: //github.com/slorber/gcm-server-repository
Thus anyone can download this jar with maven and also its transitive dependencies.
因此,任何人都可以使用 maven 及其传递依赖项下载这个 jar。
I've added the files/commands so that you know how i've done.
我已经添加了文件/命令,以便您知道我是怎么做的。
Add repository:
添加存储库:
<repository>
<id>gcm-server-repository</id>
<url>https://raw.githubusercontent.com/slorber/gcm-server-repository/master/releases/</url>
</repository>
And dependency:
和依赖:
<dependency>
<groupId>com.google.android.gcm</groupId>
<artifactId>gcm-server</artifactId>
<version>1.0.2</version>
</dependency>
回答by Tom
See https://groups.google.com/forum/#!msg/android-gcm/oukjcHpbLj4/lql_IzpjmUkJ%5B1-25%5D.
请参阅https://groups.google.com/forum/#!msg/android-gcm/oukjcHpbLj4/lql_IzpjmUkJ%5B1-25%5D。
It seems that google simply doesn't publish this jar in any maven repository. You have two options:
似乎谷歌根本没有在任何 maven 存储库中发布这个 jar。您有两个选择:
- Include all (transitively) dependent jars in your repository
- (like you said) Create your own pom file
- 在您的存储库中包含所有(可传递的)依赖 jar
- (就像你说的)创建你自己的 pom 文件
I would go for the second option. It's not that hard.
我会选择第二个选项。这并不难。
回答by Andrés Canavesi
Works using:
工作使用:
<dependency>
<groupId>com.google.android.gcm</groupId>
<artifactId>gcm-server</artifactId>
<version>1.0.2</version>
</dependency>
And
和
<repository>
<id>gcm-server-repository</id>
<url>https://github.com/slorber/gcm-server-repository/raw/master/releases/</url>
</repository>
回答by sancho21
If you use Linux or Mac, you may use the following script saved as mvn-intall-jar:
如果您使用 Linux 或 Mac,您可以使用以下保存为 mvn-intall-jar 的脚本:
#!/bin/sh
# Script to mavenize any JAR files
# by Muhammad Ichsan <[email protected]>
#
desc=
binary=
source=
if [ $# -lt 2 ]; then
echo "Usage <dependency>
<groupId>com.google.android.gcm</groupId>
<artifactId>gcm-server</artifactId>
<version>1.0.2</version>
</dependency>
<DESCRIPTION> <BINARY JAR FILE> [SOURCE JAR FILE]"
echo "e.g. ##代码## com.google.android.gcm/gcm-server/2.1.4 gcm-server.jar gcm-server-src.jar"
exit 1
fi
groupId=`echo $desc | awk -F '/' '{print }'`
artifactId=`echo $desc | awk -F '/' '{print }'`
version=`echo $desc | awk -F '/' '{print }'`
if [ "$version" = "" ]; then
echo "Invalid DESCRIPTION"
exit 1
fi
if [ "$source" != "" ]; then
mvn install:install-file\
-Dfile=$binary\
-DgroupId=$groupId\
-DartifactId=$artifactId\
-Dversion=$version\
-DgeneratePom=true\
-Dpackaging=jar\
-Dsources=$source
else
mvn install:install-file\
-Dfile=$binary\
-DgroupId=$groupId\
-DartifactId=$artifactId\
-Dversion=$version\
-DgeneratePom=true\
-Dpackaging=jar
fi
And use this:
并使用这个:
##代码##