我正在用maven构建我的java项目,但是没有成功。那么,有谁能告诉我pom.xml中构建项目所需的基本标记及其对应的值吗?另外,如何从命令行手动添加风暴依赖项?
我的项目目录结构:
ROOT
|
|----com--->test----->newpackage---->*.class
|--- META-INF------>MANIFEST.MF
|----resource----->words.txt
|----pom.xml
|-----*.jar
最初我尝试maven链接并创建 pom.xml
这样地:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<phase>com.test.newpackage</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
但是,在那之后我用 mvn package
. 它引发以下异常:
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).
Project ID: unknown
POM Location: /home/naresh/Desktop/SharedFolder/StormEclipse/pom.xml
Reason: Not a v4.0.0 POM. for project unknown at /home/naresh/Desktop/SharedFolder/StormEclipse/pom.xml
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.reactor.MavenExecutionException: Not a v4.0.0 POM. for project unknown at /home/naresh/Desktop/SharedFolder/StormEclipse/pom.xml
at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:404)
at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:272)
at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:138)
at org.apache.maven.cli.MavenCli.main(MavenCli.java:362)
at org.apache.maven.cli.compat.CompatibleMain.main(CompatibleMain.java:60)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.codehaus.classworlds.Launcher.launchEnhanced(Launcher.java:315)
at org.codehaus.classworlds.Launcher.launch(Launcher.java:255)
at org.codehaus.classworlds.Launcher.mainWithExitCode(Launcher.java:430)
at org.codehaus.classworlds.Launcher.main(Launcher.java:375)
Caused by: org.apache.maven.project.InvalidProjectModelException: Not a v4.0.0 POM. for project unknown at /home/naresh/Desktop/SharedFolder/StormEclipse/pom.xml
at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1599)
at org.apache.maven.project.DefaultMavenProjectBuilder.readModel(DefaultMavenProjectBuilder.java:1571)
at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:506)
at org.apache.maven.project.DefaultMavenProjectBuilder.build(DefaultMavenProjectBuilder.java:200)
at org.apache.maven.DefaultMaven.getProject(DefaultMaven.java:604)
at org.apache.maven.DefaultMaven.collectProjects(DefaultMaven.java:487)
at org.apache.maven.DefaultMaven.getProjects(DefaultMaven.java:391)
... 12 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Mon Jul 22 14:38:24 IST 2013
[INFO] Final Memory: 1M/15M
[INFO] ------------------------------------------------------------------------
之后,我使用这个link maven link 2并创建了pom.xml,如下所示:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.test.newpackage</groupId>
<artifactId>wordcount</artifactId>
<version>0.0.1</version>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
<archive>
<manifest>
<mainClass>com.test.newpackage</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<!-- Repository where we can found the storm dependencies <repository>
<id>clojars.org</id> <url>http://clojars.org/repo</url> </repository> -->
</repositories>
<dependencies>
<!-- Storm Dependency -->
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.8.1</version>
</dependency>
</dependencies>
</project>
这次它抛出了以下异常:
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Failed to resolve artifact.
Missing:
----------
1) storm:storm:jar:0.8.1
Try downloading the file manually from the project website.
Then, install it using the command:
mvn install:install-file -DgroupId=storm -DartifactId=storm -Dversion=0.8.1 -Dpackaging=jar -Dfile=/path/to/file
Alternatively, if you host your own repository you can deploy the file there:
mvn deploy:deploy-file -DgroupId=storm -DartifactId=storm -Dversion=0.8.1 -Dpackaging=jar -Dfile=/path/to/file -Durl=[url] -DrepositoryId=[id]
Path to dependency:
1) com.test.newpackage:wordcount:jar:0.0.1
2) storm:storm:jar:0.8.1
----------
1 required artifact is missing.
for artifact:
com.test.newpackage:wordcount:jar:0.0.1
from the specified remote repositories:
central (http://repo1.maven.org/maven2)
3条答案
按热度按时间bmp9r5qi1#
最重要的标记是错误消息中提到的标记:
你在pom文件里漏掉了。
1wnzp6jl2#
您至少应该有这3个标签:
这是maven识别工件的方式,使用这3个属性(定义依赖项时)。
cczfrluj3#
关于您的结构:
maven假设java类处于
src/main/java
以及资源(文件夹中的任何内容)resource
和你的meta inf目录)在src/main/resources
. 由于根目录中的java类(递归),即使稍微调整maven,您描述的目录结构也不会工作。为什么不使用默认结构?你应该有个很好的理由来改变这个。风暴相关性:
您的pom中已经有到外部存储库的链接。但这一点却被置之不理。这应该像预期的那样起作用。如果在代理后面,则必须在settings.xml中定义代理