开发者

compiling a Java EE 6 project using maven fails

I am a beginner in Java EE 6 and now trying to learn Java EE 6 with help of a book 'Java EE 6 novice to professional'. It is using maven to build a project, but when I tried to compile the downloaded source code of that book without using any IDE it fails and showing some errors as follows

C:\Utilities\Java utilities\Java EE 6 book source programs\Chapter02\src>mvn compile

[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [compile]
[INFO] ------------------------------------------------------------------------
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-plugin
s/8/maven-plugins-8.pom
Downloading: http://repo1.maven.org/maven2/org/apache/maven/maven-parent/5/maven
-parent-5.pom
Downloading: http://repo1.maven.org/maven2/org/apache/apache/3/apache-3.pom
Downloading: http://repo1.maven.org/maven2/org/apache/maven/plugins/maven-compil
er-plugin/2.0.2/maven-compiler-plugin-2.0.2.jar
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot execute mojo: resources. It requires a project with an existing po
m.xml, but the build is not using one.
[INFO] ------------------------------------------------------------------------
[INFO] For more information, run Maven with the -e switch
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 10 seconds
[INFO] Finished at: Sun Jan 16 18:33:38 IST 2011
[INFO] Final Memory: 3M/56M
[INFO] ------------------------------------------------------------------------
C:\Utilities\Java utilities\Java EE 6 book source programs\Chapter02\src>mvn -e comp
ile
+ Error stacktraces are turned on.
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Default Project
[INFO]    task-segment: [compile]
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Cannot execute mojo: resources. It requires a project with an existing po
m.xml, but the build is not usi开发者_JAVA百科ng one.
[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.lifecycle.LifecycleExecutionException: Cannot execute mojo: res
ources. It requires a project with an existing pom.xml, but the build is not usi
ng one.
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:584)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalWithLi
fecycle(DefaultLifecycleExecutor.java:500)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoal(Defau
ltLifecycleExecutor.java:479)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoalAndHan
dleFailures(DefaultLifecycleExecutor.java:331)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeTaskSegmen
ts(DefaultLifecycleExecutor.java:292)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.execute(DefaultLi
fecycleExecutor.java:142)
        at org.apache.maven.DefaultMaven.doExecute(DefaultMaven.java:345)
        at org.apache.maven.DefaultMaven.execute(DefaultMaven.java:132)
        at org.apache.maven.cli.MavenCli.main(MavenCli.java:290)
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.
java:39)
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAcces
sorImpl.java:25)
        at java.lang.reflect.Method.invoke(Method.java:597)
        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.plugin.MojoExecutionException: Cannot execute mojo:
resources. It requires a project with an existing pom.xml, but the build is not
using one.
        at org.apache.maven.plugin.DefaultPluginManager.executeMojo(DefaultPlugi
nManager.java:380)
        at org.apache.maven.lifecycle.DefaultLifecycleExecutor.executeGoals(Defa
ultLifecycleExecutor.java:559)
        ... 16 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: < 1 second
[INFO] Finished at: Sun Jan 16 18:34:13 IST 2011
[INFO] Final Memory: 3M/56M
[INFO] ------------------------------------------------------------------------

As I am not familiar even with j2ee, I couldn't solve it. Can anyone help me???


It seems that you are missing a pom.xml file.


It looks like it is a problem with maven, not java (ee). You have to create a pom.xml file for your project to tell maven which dependencies your program has and how to compile the program. Unfortunately I am not very familiar with maven, but I suggest that you read a maven beginner tutorial.


Not sure if you've fixed the issue. I think you need to run the mvn compile command from here:

C:\Utilities\Java utilities\Java EE 6 book source programs\Chapter02>

that is because this the pom.xml is in this folder.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜