2
votes

I am trying to teach myself Maven. I bought a book. Im on the first example and can not seem to get it to work. I try to type "mvn compile" and it fails. Ive added the pom.xml file and the output. Can you point me in the right direction to get this to compile. Sorry for the formatting of the pom.xml. Im not sure how to get xml to display correctly. Thanks

Source

<xml version="1.0" encoding="UTF-8"?>

<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>org.beginningee6.book</groupId>
<artifactId>chapter02</artifactId>
<version>2.0</version>
<name>Chapter 02 - JPA</name>

<parent>
    <groupId>org.beginningee6.book</groupId>
    <artifactId>chapters</artifactId>
    <version>2.0</version>
</parent>

<dependencies>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>javax.persistence</artifactId>
        <version>${javax.persistence-version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.eclipse.persistence</groupId>
        <artifactId>eclipselink</artifactId>
        <version>${eclipselink-version}</version>
        <scope>provided</scope>
    </dependency>
    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derbyclient</artifactId>
        <version>${derby-version}</version>
    </dependency>

    <dependency>
        <groupId>org.apache.derby</groupId>
        <artifactId>derby</artifactId>
        <version>${derby-version}</version>
        <!--<scope>test</scope>-->
    </dependency>
</dependencies>


dan@desktop:~/Documents/Beginning_Java_EE_6_with_GlassFish_3_Second_Edition-4636/chapter02$ mvn compile
[INFO] Scanning for projects...
Downloading: http://repo1.maven.org/maven2/org/beginningee6/book/chapters/2.0/chapters-2.0.pom
[INFO] Unable to find resource 'org.beginningee6.book:chapters:pom:2.0' in repository central (http://repo1.maven.org/maven2)
[INFO] ------------------------------------------------------------------------
[ERROR] FATAL ERROR
[INFO] ------------------------------------------------------------------------
[INFO] Error building POM (may not be this project's POM).


Project ID: org.beginningee6.book:chapter02:jar:2.0

Reason: Cannot find parent: org.beginningee6.book:chapters for project: org.beginningee6.book:chapter02:jar:2.0 for project org.beginningee6.book:chapter02:jar:2.0


[INFO] ------------------------------------------------------------------------
[INFO] Trace
org.apache.maven.reactor.MavenExecutionException: Cannot find parent: org.beginningee6.book:chapters for project: org.beginningee6.book:chapter02:jar:2.0 for project org.beginningee6.book:chapter02:jar:2.0
    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:616)
    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.ProjectBuildingException: Cannot find parent: org.beginningee6.book:chapters for project: org.beginningee6.book:chapter02:jar:2.0 for project org.beginningee6.book:chapter02:jar:2.0
    at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1396)
    at org.apache.maven.project.DefaultMavenProjectBuilder.buildInternal(DefaultMavenProjectBuilder.java:823)
    at org.apache.maven.project.DefaultMavenProjectBuilder.buildFromSourceFileInternal(DefaultMavenProjectBuilder.java:508)
    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
Caused by: org.apache.maven.project.ProjectBuildingException: POM 'org.beginningee6.book:chapters' not found in repository: Unable to download the artifact from any repository

  org.beginningee6.book:chapters:pom:2.0

from the specified remote repositories:
  central (http://repo1.maven.org/maven2)

 for project org.beginningee6.book:chapters
    at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:605)
    at org.apache.maven.project.DefaultMavenProjectBuilder.assembleLineage(DefaultMavenProjectBuilder.java:1392)
    ... 18 more
Caused by: org.apache.maven.artifact.resolver.ArtifactNotFoundException: Unable to download the artifact from any repository

  org.beginningee6.book:chapters:pom:2.0

from the specified remote repositories:
  central (http://repo1.maven.org/maven2)


    at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:228)
    at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:90)
    at org.apache.maven.project.DefaultMavenProjectBuilder.findModelFromRepository(DefaultMavenProjectBuilder.java:558)
    ... 19 more
Caused by: org.apache.maven.wagon.ResourceDoesNotExistException: Unable to download the artifact from any repository
    at org.apache.maven.artifact.manager.DefaultWagonManager.getArtifact(DefaultWagonManager.java:404)
    at org.apache.maven.artifact.resolver.DefaultArtifactResolver.resolve(DefaultArtifactResolver.java:216)
    ... 21 more
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 
1
The pom file for org.beginningee6.book.chapters referenced in <parent> tag is obviously missing in your local repository. Is this really the first pom file shown in the book?prasopes
Yes, this is the first example I have come across. I did not modify anything. All of the source code came directly from the vendor. Ive added a link to the source. Is it possible they left this file out?user489041
Did you download the source code for this book from kenai.com? It looks like the source code there differs from the book. I would recommend copying the example code from the book, the pom files on the website are referencing a parent project, which makes things unnecessary complicated.prasopes
I downloaded both. It seems the source provided by the book does not have the one pom.xml file. Which is why I was getting the error above. The kenai source does include it. Using the kenai version I was able to get it to compile. However, running the example, it fails. I get a runtime exception. It seems as if other people trying to do the same have also encountered this. Im just not sure if I should attribute it to bad source code/examples or if I am doing something wrong. You would think code provided with a book should be as simple as a "mvn compile" and "mvn exec"user489041
Could you edit your original question to show the exception?prasopes

1 Answers

1
votes

As mentioned by the author of the book Antonio Goncalves in this thread:

Can you try with the latest version of the code that you'll find here

(book Beginning Java EE 6 Platform with GlassFish 3: From Novice to Professional at Apress)