Problem running project with maven in Netbeans java.lang.ClassNotFoundException: - java

I'm having issues trying to run a project in Netbeans, I also try install the .jar by CLI and still having this error.
Outputs in Netbeans:
Clean and Build:
cd /home/danillo/Desktop/TCC/collector; JAVA_HOME=/usr/lib/jvm/java-1.8.0-openjdk-amd64 /home/danillo/netbeans-8.2/java/maven/bin/mvn clean install
--- maven-install-plugin:2.3.1:install (default-install) # collector ---
Installing /home/danillo/Desktop/TCC/collector/target/collector-1.0-SNAPSHOT.jar to /home/danillo/.m2/repository/edu/utfpr/collector/1.0-SNAPSHOT/collector-1.0-SNAPSHOT.jar
Installing /home/danillo/Desktop/TCC/collector/pom.xml to /home/danillo/.m2/repository/edu/utfpr/collector/1.0-SNAPSHOT/collector-1.0-SNAPSHOT.pom
------------------------------------------------------------------------
BUILD SUCCESS
------------------------------------------------------------------------
Running:
Exception in thread "main" java.lang.NoClassDefFoundError: com/pragone/jphash/jpHash
at edu.utfpr.xbi.merger.image.PHashCompartor.compare(PHashCompartor.java:14)
at edu.utfpr.xbi.merger.BrowserMerger._merge(BrowserMerger.java:82)
at edu.utfpr.xbi.merger.BrowserMerger.merge(BrowserMerger.java:63)
at edu.utfpr.xbi.merger.Merger.main(Merger.java:55)
at CollectorPipeline.main(CollectorPipeline.java:22)
Caused by: java.lang.ClassNotFoundException: com.pragone.jphash.jpHash
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:349)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 5 more
------------------------------------------------------------------------
BUILD FAILURE
------------------------------------------------------------------------
Total time: 6.520s
Finished at: Sun Oct 07 01:44:20 BRT 2018
Final Memory: 9M/97M
I check all classes and .jar are just in the place, maybe in the wrong.
My pom.xml:
<repositories>
<repository>
<id>dependencies</id>
<url>file:///${project.basedir}/dependencies</url>
</repository>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.seleniumhq.selenium</groupId>
<artifactId>selenium-java</artifactId>
<version>3.7.1</version>
</dependency>
<dependency>
<groupId>io.appium</groupId>
<artifactId>java-client</artifactId>
<version>4.1.2</version>
</dependency>
<dependency>
<groupId>ru.yandex.qatools.ashot</groupId>
<artifactId>ashot</artifactId>
<version>1.5.5-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>2.10.0</version>
</dependency>
<dependency>
<groupId>nu.pattern</groupId>
<artifactId>opencv</artifactId>
<version>2.4.9-7</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.6</version>
</dependency>
<dependency>
<groupId>com.pragone</groupId>
<artifactId>jpHash</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/dependencies/jpHash-1.0-SNAPSHOT.jar</systemPath>
</dependency>
<dependency>
<groupId>sun.jvm.hotspot</groupId>
<artifactId>sa-jdi</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/dependencies/sa-jdi.jar</systemPath>
</dependency>
</dependencies>
</project>
I saw many topics and none work, this is really anoying me.

Related

MVN running from Console is not working, from Eclipse is working

I can not find the answer, that's why I'am asking.
I have maven project: Spring + hibernate and Solr in version 3.6.1.
Project is working as expected when I build it from Eclipse Luna (using maven M2 plugin for Eclipse Luna, Java 8).
But, when I run it from system console (on Ubuntu 14.04, maven ver.3, Java 8) build is failed because of:
[ERROR] COMPILATION ERROR :
[INFO] -------------------------------------------------------------
[ERROR] /home/dstachyra/git/bip/bip-persist/src/main/java/eu/arrow/bip/persist/indexing/SolrServerFactory.java:[244,90] error: cannot access ResourceLoader
[INFO] 1 error
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 5.049 s
[INFO] Finished at: 2016-02-15T11:20:59+01:00
[INFO] Final Memory: 24M/361M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.5.1:compile (default-compile) on project bip-persist: Compilation failure
[ERROR] /home/dstachyra/git/bip/bip-persist/src/main/java/eu/arrow/bip/persist/indexing/SolrServerFactory.java:[244,90] error: cannot access ResourceLoader
I found the reason here: I'm trying to index files in a document through SOLR and lucene..
Part of class causing the error looks like:
CoreContainer container = new CoreContainer( new SolrResourceLoader(SolrResourceLoader.locateInstanceDir()));
My pom.xml (work from eclipse, doesn't worj from system console):
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>eu.arrow</groupId>
<artifactId>bip-modular-registry</artifactId>
<version>1.0.0-FINAL</version>
</parent>
<artifactId>blue-persist</artifactId>
<packaging>jar</packaging>
<name>Persistence API</name>
<description>This module contains some Data Access Objects (DAO) which are configured
to store business objects in an relational database</description>
<properties>
<version.springdatajpa>1.3.4.RELEASE</version.springdatajpa>
<version.solr>3.6.1</version.solr>
</properties>
<dependencies>
<dependency>
<groupId>eu.arrow</groupId>
<artifactId>bip-model</artifactId>
<version>1.0.0-FINAL</version>
</dependency>
<!-- Import the JPA API using the provided scope It is included in JBoss AS 7 / EAP 6 -->
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.0.Final</version>
<!-- <scope>provided</scope> -->
</dependency>
<!-- Annotation processor that raising compilation errors whenever constraint annotations are incorrectly used. -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator-annotation-processor</artifactId>
<version>4.1.0.Final</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>${version.hibernate}</version>
<!-- <scope>provided</scope> -->
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
<version>2.2.8</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.21</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>c3p0</groupId>
<artifactId>c3p0</artifactId>
<version>0.9.1.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>${org.slf4j-version}</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<exclusions>
<exclusion>
<groupId>javax.mail</groupId>
<artifactId>mail</artifactId>
</exclusion>
<exclusion>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jdmk</groupId>
<artifactId>jmxtools</artifactId>
</exclusion>
<exclusion>
<groupId>com.sun.jmx</groupId>
<artifactId>jmxri</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- Spring Data JPA -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-jpa</artifactId>
<version>${version.springdatajpa}</version>
</dependency>
<!-- Spring Data Solr -->
<dependency>
<groupId>org.springframework.data</groupId>
<artifactId>spring-data-solr</artifactId>
<version>1.0.0.RC1</version>
</dependency>
<!-- Required by embedded solr server -->
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>${version.solr}</version>
<exclusions>
<exclusion>
<artifactId>slf4j-jdk14</artifactId>
<groupId>org.slf4j</groupId>
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.1.3</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
<version>2.5</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
</build>
<repositories>
<repository>
<id>spring-milestone</id>
<name>Spring Milestone Maven Repository</name>
<url>http://repo.springsource.org/libs-milestone</url>
</repository>
</repositories>
</project>
I understand that it can fail because of solr version, however it is working in Eclipse. The question is why?
--- EDIT ---
I looked into Maven Dependencies in Eclipse in I see there:
solr-solrj-4.1.0.jar
solr-core-3.6.1.jar
a lot of lucene jars in ver.
3.6.1
I tried to search ResourceLoader class in Eclipse (CTRL+T) and it does't exists. There is other class: org.apache.solr.util.plugin.ResourceLoaderAware from solr-core.3.6.1 library.

java.lang.NoClassDefFoundError

Here what i got when compile the project
by this command
mvn compile exec:java -Dexec.classPathScope=compile -Dexec.mainClass=trident.myproject
got this
java.lang.NoClassDefFoundError: storm/trident/state/StateFactory
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2427)
at java.lang.Class.getMethod0(Class.java:2670)
at java.lang.Class.getMethod(Class.java:1603)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:285)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.ClassNotFoundException: storm.trident.state.StateFactory
at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
... 6 more
INFO] ------------------------------------------------------------------------
[ERROR] BUILD ERROR
[INFO] ------------------------------------------------------------------------
[INFO] An exception occured while executing the Java class. storm/trident /state/StateFactory
storm.trident.state.StateFactory
i reviewed the folder and can't find this class ! although i ran it before successfully
i wrote pom file as parts
<dependencies>
<dependency>
<groupId>storm</groupId>
<artifactId>storm</artifactId>
<version>0.8.2</version>
<scope>provided</scope>
</dependency>
part 2 of pom.xml
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>colt</groupId>
<artifactId>colt</artifactId>
<version>1.2.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.0.0</version>
</dependency>
part 3 of pom.xml
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-stream</artifactId>
<version>4.0.2</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
You might have changed the scope of the dependency in your pom.xml file. If your container is providing the dependency change scope to provided.
<scope>provided</scope>
If container is not providing the dependency change scope to compile.
<scope>compile</scope>

Missing artifact com.oracle:ojdbc14:jar:10.2.0.1.0

I am trying to add dependency for ojdbc14 in pom.xml.
Steps I followed for adding ojdbc14.jar in local repository of maven:
Create a new project
move to that particular folder where is pom.xml file was located in command prompt.
execute the command mvn clean.
execute the command:
mvn install:install-file -Dfile=ojdbc14.jar -DgroupId=com.oracle -DartifactId=oracle -Dversion=10.2.0.1.0 -Dpackaging=jar -DgeneratePom=true
after this I got a build success message
I have updated the global and local repository in Eclipse > Maven Repositories
C:\> mvn install:install-file -Dfile="C:\Users\Dhia\Desktop\Nouveau dossier\ojdb
c14.jar" -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.0.1.0 -Dpackag
ing=jar
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Maven Stub Project (No POM) 1
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- maven-install-plugin:2.4:install-file (default-cli) # standalone-pom
---
[INFO] Installing C:\Users\Dhia\Desktop\Nouveau dossier\ojdbc14.jar to C:\Users\
Dhia\.m2\repository\com\oracle\ojdbc14\10.2.0.1.0\ojdbc14-10.2.0.1.0.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 0.460s
[INFO] Finished at: Sat Feb 28 22:44:13 CET 2015
[INFO] Final Memory: 4M/15M
[INFO] ------------------------------------------------------------------------
C:\>
my local repoitory is C:\Users\Dhia\Desktop\eclipse jee
and when opening .com in eclipse oracle repository doesn't appear
when adding
com.oracle
ojdbc14
10.2.0.1.0
my pom.txt
<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>b</groupId>
<artifactId>b</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>b</name>
<repositories>
<repository>
<id>prime-repo</id>
<name>PrimeFaces Maven Repository</name>
<url>http://repository.primefaces.org</url>
</repository>
<!--
<repository>
<id>central</id>
<url>http://repo1.maven.org/maven2/</url>
</repository>
-->
</repositories>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>4.1.8.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>4.2.0.Final</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-webflow</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.webflow</groupId>
<artifactId>spring-faces</artifactId>
<version>2.3.1.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-orm</artifactId>
<version>3.1.1.RELEASE</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.1.0</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.16</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.10</version>
</dependency>
<dependency>
<groupId>com.sun.facelets</groupId>
<artifactId>jsf-facelets</artifactId>
<version>1.1.14</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1.10</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
<version>20030825.184428</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-log4j12</artifactId>
<version>1.6.4</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-tx</artifactId>
<version>3.0.5.RELEASE</version>
</dependency>
<dependency>
<groupId>xml-apis</groupId>
<artifactId>xml-apis</artifactId>
<version>1.3.02</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-web</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework.security</groupId>
<artifactId>spring-security-config</artifactId>
<version>3.1.3.RELEASE</version>
</dependency>
<dependency>
<groupId>org.primefaces</groupId>
<artifactId>primefaces</artifactId>
<version>3.4</version>
</dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib</artifactId>
<version>2.2.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>4.1.8.Final</version>
</dependency>
</dependencies>
</project>
I got error in my pom.xml file :Missing artifact com.oracle:ojdbc14:jar:10.2.0.1.0, and I am not able to see the ojdbc14.jar file in my local repository. Is there any thing wrong in the steps I followed. Please help me out.
Thanks
This can't be directly install because Oracle has put some license and agreements. So we have to download it manually and install it to the project. Use this link to choose the version you need and download the ojdbc14.jar file. You must have an Oracle account to download it.
Then open the command prompt. Go to the file download location. Then enter below code.
mvn install:install-file -DgroupId=com.oracle -DartifactId=ojdbc14 -Dversion=10.2.x.x.x -Dpackaging=jar -Dfile=ojdbc14.jar -DgeneratePom=true
Fill the x using your needed version. Then right click on your project >Maven>Update Project.
This will solve the problem.
The XML for version com.oracle:ojdbc14:jar:10.2.0.1.0 is missing from the central repository.
So i think this version will create problem for many more people
https://repo1.maven.org/maven2/com/oracle/ojdbc14/
Based on the output of mvn install:install-file, the jar was correctly installed in your local maven repository. If you add this to your pom.xml (inside the <dependencies> section), your project should find the jar:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc14</artifactId>
<version>10.2.0.1.0</version>
</dependency>
If you're still experiencing problems,
please share your pom.xml and the error output.
There is no such artifact in maven central repository: http://repo1.maven.org/maven2/com/oracle/ojdbc14/10.2.0.4.0 (only pom).
Please refer Is there an issue with the oracle dependency?
Manually downloading the ojdbc14 jar worked for me :)
This might be because of your maven settings.xml file. If you don't configure your local repo in settings.xml maven default repo will be Default: ${user.home}/.m2/repository. And you need to configure same maven settings in your IDE.
See more details here.

Absent Code attribute in method that is not native or abstract in class file javax/faces/webapp/FacesServlet

I am building a PoC for using JSF and am using Tomcat 7.0.59 as my server. My pom.xml looks like :
<repositories>
<repository>
<id>Java.Net</id>
<url>http://download.java.net/maven/2/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
</dependencies>
I looked up for the error and found out that it is caused due to the javaee-api but looks like even after adding that particular dependency the issue isn't resolving. There is a different thread but it is on different servers like glassfish, jboss and doesn't seem to be working on my case.
EDIT : After suggestions from Samuel and Tiny, I have reached to this pom.xml :
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>javax.faces</groupId>
<artifactId>jsf-api</artifactId>
<version>2.1</version>
</dependency>
<dependency>
<groupId>com.sun.faces</groupId>
<artifactId>jsf-impl</artifactId>
<version>2.1.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0</version>
<scope>provided</scope>
</dependency>
</dependencies>
And maven dependency tree looks like :
com.Sourabh:SourabhTest:war:0.1
[INFO] +- junit:junit:jar:3.8.1:test
[INFO] +- javax.faces:jsf-api:jar:2.1:compile
[INFO] \- com.sun.faces:jsf-impl:jar:2.1.7:compile
Servlet-api must be flagged with <scope>provided</scope>, as the jar in provided by tomcat. If you don't you might encounter class loader issues.
To ensure that you don't have several time the same dependency (through transitive dep.) you can run mvn dependency:tree or go in the dependency hierarchy plugin in eclipse

Maven Hibernate

Hi I am following this tutorial: http://www.mastertheboss.com/hibernate/182-hibernate-tutorial.html
I have done all the code so I add this run configuration:
package -e -DgroupId=it.michelepierri -DartifactId=FirstExampleHibernate
This is my 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>it.michele</groupId>
<artifactId>FirstExampleHibernate</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>FirstExampleHibernate</name>
<description>Primo esempio di utilizzo Hibernate</description>
<dependencies>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core<!--or hibernate-core--></artifactId>
<version>3.3.2.GA</version>
<type>pom</type>
<!--hibernate-dependencies is a pom, not needed for hibernate-core -->
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-annotations</artifactId>
<version>3.4.0.GA</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>3.1.0.GA</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.5.8</version>
</dependency>
<dependency>
<groupId>antlr</groupId>
<artifactId>antlr</artifactId>
<version>2.7.6</version>
</dependency>
<dependency>
<groupId>commons-collections</groupId>
<artifactId>commons-collections</artifactId>
<version>3.1</version>
</dependency>
<dependency>
<groupId>dom4j</groupId>
<artifactId>dom4j</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>javassist</groupId>
<artifactId>javassist</artifactId>
<version>3.4.GA</version>
</dependency>
<dependency>
<groupId>javax.transaction</groupId>
<artifactId>jta</artifactId>
<version>1.1</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>5.1.18</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-jdk14</artifactId>
<version>1.6.4</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>it.michele.TestPerson</mainClass>
<packageName>it.michele</packageName>
</manifest>
</archive>
</configuration>
</plugin>
</plugins>
</build>
So I run it and console says me:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
There are no tests to run.
Results :
Tests run: 0, Failures: 0, Errors: 0, Skipped: 0
[INFO]
[INFO] --- maven-jar-plugin:2.3.1:jar (default-jar) # FirstExampleHibernate ---
[INFO] Building jar: C:\Users\Michele\workspace\FirstExampleHibernate\target\FirstExampleHibernate-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.707s
[INFO] Finished at: Sun Mar 11 14:59:50 CET 2012
[INFO] Final Memory: 5M/77M
[INFO] ------------------------------------------------------------------------
When I try to launch the jar I have returned:
C:\Users\Michele\workspace\FirstExampleHibernate\target>java -jar
FirstExampleHibernate-0.0.1-SNAPSH
OT.jar
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/Session
Caused by: java.lang.ClassNotFoundException: org.hibernate.Session
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
Could not find the main class: it.michelepierri.TestPerson. Program will exit.
What I am doing wrong??????
In TestPerson.java class there is public static void main(String[] args) method.
Thanks.
You are encountering the problem because all the supporting jars (hibernate etc) are not specified in the classpath.
Try
mvn exec:java -Dexec.mainClass=it.michelepierri.TestPerson
This is a maven command that will internally invoke java with all the dependent jars added to the classpath.
You can also try
mvn assembly:single
which will combine all the jars into one which you then use the run it the way you are doing now.

Categories