I have a Maven project that I can successfully compile and run through the command line. When I manually deploy a jar with dependencies in Tomee it works. However when I run the same project through IDEA I get
java.lang.ClassNotFoundException: org.firebirdsql.jdbc.FBDriver
I think this is because my jar with dependencies has the jdbc driver included, but the IDEA run configuration deploys my classes and not the jar, so the driver is missing.
It seems to me that I need to somehow configure IDEA additionally even though I already have this in my pom:
<dependencies>
<dependency>
<groupId>org.firebirdsql.jdbc</groupId>
<artifactId>jaybird-jdk18</artifactId>
<version>3.0.0</version>
<scope>runtime</scope>
</dependency>
...
</dependencies>
Am I indeed supposed to configure something else beside the pom?
I created the project without any IDE at first, because I was afraid it wouldn't work outside the IDE.
Related
I have a java project setup in eclipse to build with maven. Project itself is a multi-module maven project (but I am not using m2e plugin rather maven-eclipse plugin, and eclipse project does not have maven nature)
When running mvn install within eclipse, everything compiles fine, but when I run the same command in command prompt, I get compile errors due to a missing dependency.
I see that the jar it's looking for is neither listed explicitly as dependency in pom.xml or is a transitive dependency. I tried running mvn dependency:tree but also couldn't see this jar.
How can this jar be available in eclipse?
Update: two missing jars are
<dependency>
<groupId>org.springframework.integration</groupId>
<artifactId>spring-integration-jms</artifactId>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
</dependency>
I solved the issue. Problem had to do with my invalid global mirror settings that redirected traffic to wrong remote repository so it could not find and install dependencies, later causing compile error.
In eclipse, I was using embedded maven referencing user settings only with no global settings therefore it worked fine.
I have created a console application in IntelliJ that utilizes Maven. From within IntelliJ I can compile and run the app with no issues ...
From terminal however i execute the following commands (in the same dir with pom.xml)
mvn Install -U
java -classpath target/myApp-2.0-SNAPSHOT.jar MainClass
The install command seems to build the jar file without any issue. The second command gives me the following error
Exception in thread "main" java.lang.NoClassDefFoundError: org/codehaus/jackson/JsonParseException
In my pom.xml my dependencies are as follows
<dependencies>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-mapper-asl</artifactId>
<version>1.5.0</version>
</dependency>
</dependencies>
It seems to me that its not pulling in the Jackson Dependencies but im not sure what im missing here.
As said, the problem you have is that your jar needs the other jars to execute.
I see 3 solutions :
1- As stated above, when you run the program, add the -classpath argument
2- Use the maven-jar-plugin to add the dependencies in the manifest, then you'll only have to have the dependencies at the requested place to have all execute.
See http://maven.apache.org/shared/maven-archiver/examples/classpath.html#aAdd
3- Package the dependencies inside your jar with a plugin like jarjar : http://sonatype.github.io/jarjar-maven-plugin/
This will create you a standalone jar
Hope it can help.
Maven has no impact on your runtime classpath (only your compile-time classpath). You need to add your dependencies to the classpath.
I am very new to eclipse and maven repository. I got a project to config the errors of POM.xml. I fixed many of it, but I am unable to fix some. Following are that errors.
<dependency>
<groupId>jlibs</groupId>
<artifactId>jlibs-jdbc</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.jgodies.form</groupId>
<artifactId>forms</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc6</artifactId>
<version>11.2.0</version>
<scope>runtime</scope>
In Maven repository folder there are not all the files which are in the other folders, so I put them manually, but still no results.
All the Oracle realted jars are not the part of the Central Maven Repository.
May be the case with the other oracle related jars. That is the reason why its not able to resolve the dependencies.
You should create a separate custom repository on your company server where you can put all these jar and configure that in POM.xml. Maven will first check the Central reposiroty and if it does not find the files will later check the custom repositry.
For locally running Maven you will have to do a MVN Install manually. you should never manuallly copy any jars to the m2 repositiry
Getting the JDBC drivers is a bit tricky. Please check this article for directions.
Due to Oracle license restriction, there is NO public Maven repository provides Oracle JDBC driver. To use Oracle jdbc drive with Maven, you have to install it manually into your Maven local repository.
I've made a small library, lets call it lib. It dependends on another library, sublib which is available in Maven central:
lib/pom.xml:
<dependencies>
<dependency>
<groupId>3rdparty</groupId>
<artifactId>sublib</artifactId>
<version>x</version>
</dependency>
</dependencies>
Now I'm trying to use lib in my project proj. I've set it as a dependency:
proj/pom.xml:
<dependencies>
<dependency>
<groupId>mynamespace</groupId>
<artifactId>lib</artifactId>
<version>y</version>
</dependency>
</dependencies>
When I run mvn exec:java -D exec.mainClass=mynamespace.proj.Main the program runs fine.
However if I run it from IntelliJ, I get the following error:
java.lang.NoClassDefFoundError: 3rdparty/SomeSubLibClass
at mynamespace.SomeLibClass.method(SomeLibClass.java:100)
This seems to indicate that IntelliJ does not load the transitive sublib dependency. How can I fix this?
You can manually right click on the pom.xml file in the file tree and select maven > reimport.
Sometimes you'll see a popup saying "Maven projects need to be imported"; you should select Enable Auto-Import.
This option can be found in Preferences > Maven > Importing > [x] Import Maven projects automatically (and is unchecked by default):
What worked for me was changing from using maven (Intellij) version and using my latest version that was installed on my machine previously.
I had a similar problem. The below command resolved the problem. It downloaded all the dependency jars into my IDEA project.
mvn -U idea:idea
To do some Surface-Tests I start an embedded Jetty for JUnit-Tests. My tests call some pages from the server. When doing this tests from eclipse everything works fine, the classpath is created by "mvn eclipse:eclipse".
When running those tests with "mvn test" the jsp-Compiler raises a lot of ClassNotFoundExceptions: javax.servlet., javax.servlet.jsp and evene some of my self generated classes. All requests directly answered by servlet work fine.
Doing in my testcases something like System.out.println(HttpServlet.class) works fine, too. So the Jetty-JSP compiler seems to habe some "specials" when compiling.
Anybody knows how to persuade Jetty to compile my JSPs?
There is a maven plugin for that:
http://wiki.eclipse.org/Jetty/Feature/Jetty_Jspc_Maven_Plugin
If you look pom of one jetty module you'll see:
<dependency>
<groupId>org.eclipse.jetty.orbit</groupId>
<artifactId>javax.servlet</artifactId>
<scope>provided</scope>
</dependency>
It dependes on own servlet-api classes.
So maybe if you specify dependencies on real servlet-api in your project pom it will work:
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.0.1</version>
</dependency>
After all the problem seems to have been in mavens dependency-management (or what I allowed maven to do).
I had a real mess of javax-artifacts in my classpath (jsp-2.1, 2.2.3, 2.2.1, servlet 2.5, 3.0, 3.0.glassfish-style). So after I cleaned up dependencies everything works fine. Now I understand why jetty from maven-.build didnn't start. Finally I dont understand why at all jetty came up in eclipse ;)