Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Way Too Many Maven Dependencies

Tags:

java

maven

I've been trying to setup the simplest of simple hibernate applications and for reasons beyond my mediocre way of thinking I cannot get it running. Maven is easy enough - adding dependencies to the build path, updating the project, blah blah blah yadda yadda yadda

It started off as a single ClassNotFoundException which required a missing dependency. I would import the missing jar and run the app again, only to get another ClassNotFoundException. Next thing I know I HAVE A TON OF JARS AND NO WORKING APPLICATION

enter image description here

*Directories have been masked to protect the unfortunate

I've used both Maven and Hibernate in my last project in Eclipse Kepler and it was almost too easy, ha! Updating to Luna was a real pain trying to get Maven to run correctly - disabling the Java Compilier Compliance Level just to be able to update the Dynamic Web Module, not to mention manually creating the missing src/main/java and src/test/java folders that are standard with a maven-archetype-webapp, the list goes on. I've spent tooooo much time just to get the thing to not fail.

In my last project all I needed to import was:

<dependency>
   <groupId>javax.servlet</groupId>
   <artifactId>javax.servlet-api</artifactId>
   <version>3.1.0</version>
   <scope>provided</scope>
</dependency>
<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-core</artifactId>
   <version>4.3.6.Final</version>
</dependency>
<dependency>
   <groupId>org.hibernate</groupId>
   <artifactId>hibernate-c3p0</artifactId>
   <version>4.3.6.Final</version>
</dependency>
<dependency>
   <groupId>org.springframework</groupId>
   <artifactId>spring-core</artifactId>
   <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-web</artifactId>
  <version>4.1.0.RELEASE</version>
  </dependency>
<dependency>
  <groupId>org.springframework</groupId>
  <artifactId>spring-webmvc</artifactId>
  <version>4.1.0.RELEASE</version>
</dependency>
<dependency>
   <groupId>org.codehaus.jackson</groupId>
   <artifactId>jackson-mapper-asl</artifactId>
   <version>1.9.13</version>
</dependency>

That' was it! I was swimming in Session Factories and Updating database tables like it was my job (it is).

This leads me to believe some core functionality is missing from this new project. Perhaps I've overlooked something in the IDE Upgrade. Could almost guarantee its my Build Path. Please Help!

About my project - I'm using: Eclipse Luna (Kepler was 100x easier to setup with Maven) Maven Webapp Archetype JDK-1.7 Hibernate Core 4-3.6

My latest Exception was

 Exception in thread "main" java.lang.NoClassDefFoundError: javax/persistence/NamedStoredProcedureQuery
    at org.hibernate.cfg.AnnotationBinder.bindDefaults(AnnotationBinder.java:276)
    at org.hibernate.cfg.Configuration.secondPassCompile(Configuration.java:1402)
    at org.hibernate.cfg.Configuration.buildSessionFactory(Configuration.java:1844)
    at com.boa.ecris.test.Main.main(Main.java:22)
Caused by: java.lang.ClassNotFoundException: javax.persistence.NamedStoredProcedureQuery
    at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
    ... 4 more

If this is specific to the javax persistence-api.jar, it's already in there!!!

like image 404
Clay Banks Avatar asked Oct 31 '22 17:10

Clay Banks


1 Answers

Java APIs change over time. You need to find the correct version of your dependency (namely the one which contains the version of the API which you want/need to use). Since you told Maven to use version 1.0.2 of persistance-api, that's what Maven will do - you might know better.

If the error doesn't go away, then your next step should be the Maven central repo, specifically the "find class for me" search dialog: http://search.maven.org/#search%7Cga%7C1%7Cfc%3Ajavax.persistence.NamedStoredProcedureQuery

Next, you need to understand which dependencies you want in your project and select the correct one from the list. Since Maven doesn't know about your constraints, that is something you have to figure out yourself.

A word of wisdom: A computer doesn't have a brain, bring your own.

like image 187
Aaron Digulla Avatar answered Nov 08 '22 04:11

Aaron Digulla