Maven Java project in eclipse and mongodb libraries - java

I have a Maven project in Java. I am new to all of these concepts. I created a Restful project which works well with a file repository. But I want to change that to a mongo repository.
So I added my repository class, then I need to add the mongo libraries. I right click on the project and select Maven --> Update, but the libraries are not being downloaded. So I add them myself via Project Build path and this makes my project to compile.
However at runtime I get the exception of classNotFound for mongo classes.
I read some posts and added these line to pom.xml:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>1.3</version>
</dependency>
Still not compiling. How should I add the libraries in a way that it compiles and also at runtime my program can find those classes?

Where did you get 1.3 for a version? The latest is 2.12.1.

Related

How to connect Java Applocation to JIRA?

I want my java application to communicate with JIRA how can i achieve this functinality. I mean what configuratons are need to add, what are jar files etc ?
You actually don't need Jar files if your java project is using Maven. Just add maven dependency
<dependency>
<groupId>com.atlassian.jira</groupId>
<artifactId>jira-api</artifactId>
<version>${atlassian.product.version}</version>
<scope>provided</scope>
</dependency>
If you are not using maven as build system to your project. Download jar from maven directly and add it to your project.
Follow the documentation https://developer.atlassian.com/server/jira/platform/java-apis/ and start development

Want to use MongoDB in servlets

I currently have knowledge of JSP and Servlets and want to use MongoDB, but I can find only ways to use Mongo with maven. Just want to ask if i can use Mongo without maven?
Yes you can. Maven is a build and dependency management tool. MongoDB is a Database. They are completly unrelated. With Maven it is just simpler to gather MongoDB java driver dependency. You just need to declare it in your maven pom.xml file:
<dependency>
<groupId>org.mongodb</groupId>
<artifactId>mongo-java-driver</artifactId>
<version>2.10.1</version>
</dependency>
Without maven, you need to manually download the required jar file and manually add it to your classpath. Use this location to get the required jar file:
https://oss.sonatype.org/content/repositories/releases/org/mongodb/mongo-java-driver/
Then you can just continue according to any MongoDB tutorial, such as:
http://www.mkyong.com/mongodb/java-mongodb-hello-world-example/

Maven dependencies for IBM Websphere packages

I'm trying to convert a "classic" JAVA EE project, using IBM websphere 8.0.0.5, into a maven multi module project and facing issues with the IBM dependecies.
We use IBM classes from the following packages:
com.ibm.websphere.asynchbeans
com.ibm.websphere.scheduler
com.ibm.websphere.ce.cm
com.ibm.ws.asynchbeans
com.ibm.ws.util.ThreadPool
To get my local project to be compiled I downloaded the was.installer-8.0.0.pm from IBM and installed it to my maven using
mvn install -f "was.installer-8.0.0.pom" -D serverInstallationFolder="C:\Program Files (x86)\IBM\WebSphere\AppServer"
This step was successfull according to command line output.
I then added the following dependencies to my project as described from IBM:
In parent:
<dependency>
<groupId>com.ibm.tools.target</groupId>
<artifactId>was</artifactId>
<version>8.0.0</version>
<type>pom</type>
<scope>provided</scope>
</dependency>
In module:
<dependency>
<groupId>com.ibm.tools.target</groupId>
<artifactId>was</artifactId>
</dependency>
But I still can't compile my project as the IBM packages are not found.
Can anyone help me to find and correct a mistake I made?
Edit
After following BevynQ tip from the comments I copied the "was_public.jar" to "was_public-8.0.0.jar" (described at IBM here) and added it to my repository:
mvn install:install-file -Dfile="C:\Program Files (x86)\IBM\WebSphere\AppServer\dev\was_public-8.0.0.jar" -DpomFile="C:\Program Files (x86)\IBM\WebSphere\AppServer\dev\was_public-8.0.0.pom"
I then changed the dependencies to:
<dependency>
<groupId>com.ibm.websphere.appserver</groupId>
<artifactId>was_public</artifactId>
<version>8.0.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.ibm.websphere.appserver</groupId>
<artifactId>was</artifactId>
</dependency>
This helped to get the compiling errors for the imports to com.ibm.websphere done.
What I now have still open is the packages com.ibm.ws.* package. Anyone have an idea?
Edit 2
I added the following dependency and then I was rid of the com.ibm.ws.* import errors.
<dependency>
<groupId>com.ibm.websphere.ws</groupId>
<artifactId>com.ibm.ws.runtime</artifactId>
<version>1.0.0</version>
</dependency>
But it still does not compile as now indirectly references can not be found (in my case commonj.work.WorkManager). It seems I need to add further .jars for every single thing. Isn't there an easier way to provide all websphere jars at once as descirbe in the above linked tutorial with the com.ibm.toolsdependency (which do not work)?
In general, com.ibm.websphere are public API for use by applications (this is true of the packages you listed above) which is consistent with these being in was_public.jar
However, com.ibm.ws package is generally product internals. May I ask what interface methods you are using from the com.ibm.ws.asynchbeans package? Maybe there is a public API alternative.
Regarding commonj.work, the only place I can find this in the WebSphere Application Server product image is WAS/plugins/com.ibm.ws.prereq.commonj-twm.jar so it looks like you will need to use that to compile against.
Here's the solution so I solved my dependency problems:
I configured the company repository manager (nexus) as a mirror. In this nexus all ibm packages are present. As you can think that solved the main problem.
I then added the following dependencies according to common maven style:
Dependencies in pom.xml (version numbers extracted to properties):
<dependency>
<groupId>com.ibm.websphere.ws</groupId>
<artifactId>com.ibm.ws.runtime</artifactId>
<version>${ibm.ws.runtime.version}</version>
</dependency>
<dependency>
<groupId>com.ibm.ws.prereq</groupId>
<artifactId>commonj-twm</artifactId>
<version>${ibm.ws.prereq.commonj-twm.version}</version>
</dependency>
Sorry I can't provide a "nice" solution that's useable by all people but the answer from njr and the comment from BevynQ helped at lot to get clearer with the problem and helped to solve the problem in a "more manual" way by copying the needed jars by hand.
I was facing this issue as I tried to build a project using Maven version 3.3.9, running on Java version 1.8.0_101, as depicted in the screenshot:
This is how I resolved it: Step 1. Download the commonj.jar from here.
Step 2. Determine which JDK your Maven is using by typing mvn -version in the command prompt.
Step 3. Go to that directory and place the commonj.jar file there in the jre/lib/ext directory, as shown below. Now your project should build in maven without any issues.

how to determine dependencies

I'm currently learning java and want to create a project, using maven, hibernate and MySQL. I know that in order to use any of the artifacts with maven, I should find it on mvnrepository and add it to pom.xml. The question is where can I get the list of mandatory dependencies for each artifact I use, f.ex if I need hibernate, I found hibernate-core 4.3.8.Final, proceed to this link and can see it's dependencies in section "depends on". Should I add all of them into pom.xml also?
Well, I think you know about maven.
And yes, You should include all the dependencies with version on your pom.xml files (Which is the main file for all your dependencies ).
First, you need to identify all required dependencies and add on pom file.
While executing code, It primarily tries to get that dependency from local repository (.m2) And if it doesn't exists then it downloads from it's web repository.
Link: maven setup
How it works??
Suppose, You are using log4j for loggin.
You need to know the log4j Maven coordinates,
for example
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
It will download the log4j version 1.2.14 library automatically. If the “version” tag is ignored, it will upgrade the library automatically when there is a newer version.
Declares Maven coordinates into pom.xml file.
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.14</version>
</dependency>
</dependencies>
When Maven is compiling or building, the log4j jar will be downloaded automatically and put it into your Maven local repository.
All manages by Maven.
How to find the Maven coordinates?
Visit this Maven center repository, search the jar you want to download.
Hope, It will help.
Thanks.

How to use this library with Eclipse

I'm trying to use this library https://github.com/axet/vget
I can't seem to figure out how to get a .jar file out of that so I can use it.
Well, you can put the below dependency in your pom.xml if you use Maven.
<dependency>
<groupId>com.github.axet</groupId>
<artifactId>vget</artifactId>
<version>1.1.5</version>
</dependency>
Otherwise, you could download the archive from https://github.com/axet/vget/releases and build it yourself.
If you want the latest (unreleased) version, you'll have to clone the repository on your machine and build it yourself.

Categories

Resources