I'm using an Eclipse project and don't want to use a Maven pom. I want to drop the jars needed for Mockito into a directory and reference them from Eclipse build properties. But Mockito.org doesn't supply a download link nor mention what jars are needed to get Mockito running.
How do I determine what jars I need to download?
Mockito.org is mysteriously evasive about what Jars are needed for specific releases. They really want people using the .pom, but sometimes we don't wanna use Maven. (Developers are capricious and stubborn after all.)
Here's how to derive what jars you'll need if you're willing to read a .pom:
Go to Maven.org and type "mockito" into the search box. Look for the latest version of a "mockito*" in the "artifact ID" column. Decide which .jar "looks right." In this case I used mockito-core. Click on the "jar" link and now you've got your first jar.
But you need to get the dependencies:
Click on the link to the .pom and look at the listed dependencies. You'll see listed artifact-ids such as byte-buddy, byte-buddy-agent, and objenesis.
Using the maven.org search box, enter in the artifact-id and download the jar for each of them. Put them all together in a directory and change your build properties so you can use Mockito in your Eclipse project.
Basically you are looking for
mockito-core.jar
and on top of that, you also want:
mockito-core-sources.jar
mockito-core-javadoc.jar
It often helps to have the source code, or at least the javadoc content at your fingertips within your IDE.
Related
I want to use Choco 3.3.1 in my eclipse project. I added the needed jar file to the java build path. But in the readme file it says that I also need to add the required dependencies. They look like this:
org.javabits.jgrapht:jgrapht-core:jar:0.9.3
dk.brics.automaton:automaton:jar:1.11-8
args4j:args4j:jar:2.32
net.sf.trove4j:trove4j:jar:3.0.3
org.slf4j:slf4j-api:jar:1.7.13
Where can I add those without maven, gradle etc.?
(The project is a scala project, but I don't think that's the problem)
The easiest way is probably to locate and download them from the Maven Central repository. You can search by artifact and/or group ID and locate the exact version(s) you're looking for. For example, here's the search for the jgrapht JAR.
Having said that, why not use Gradle, which has Scala support? Or sbt, the Scala build tool? You should at least give those some consideration.
I have started reading and trying maven since yesterday. But its making me go crazy.
I am java developer but never came across ant or maven before.
I want to know what exactly happens with the dependency tag in POM.xml file?
Lets say, I am using camel framework and want to use camel core jars.
If one of my class file contains following line:
CamelContext context = new DefaultCamelContext();
so what exactly I need to do after that?
Do I need to include the jars myself in the class path or dependency tag will download the jar files over internet for me?
If the case is former, what dependency tag will do? & where should I place my jar files? I mean is there any specific location on my hard drive? and
if the case is lateral then during compile time I get error "cannot be resolved to a type"
And the imports are to be specified or not?
I know the question might sound silly but I am not able to find its answer.
I have tried googling alot, it didn't help me still.
Any help would be greatful, even help on maven topics which I might come across in near future would be appreciated.
Thanks in advance.
Solved. Please check https://stackoverflow.com/a/20094312/1121208 for help
dependency tag will download the jar specified in the dependency tag for you if available. Otherwise will raise a pom.xml error - could not found dependency..
Imports have nothing to do with maven. They will appear when you will you another class in your class/java file. So if you import in build path the jar by yourserf or if you put it there with maven, you will have the import.
Are you using eclipse or any other ide ?
First of all, Maven is a build tool. It doesn't run your app. It builds it. So, at runtime, the classpath needs to be set like for any oter application yo would have built with something else.
When you build an app, you depend on external libraries. The dependencies mechanism of Maven simply lets you declare wwhich libraries your ap needs. When you build your app, Maven downloads these libraries from a central repository (or sevaral ones), and stores them in a local repository on your hard drive. These jars are automatically added to the build classpath by Maven. At runtime though, depending on the kind of ap you're building, you'll have to copy or embed those jars in order to create a runnable application.
The rules of Java don't change just you build them with Maven. Meven uses the stadard Java compiler (javac). And of course, if you want to use a class by its simple name, you'll have to add an import statement for this class.
I think that, before using Maven, you should try to compile and run a simple application depending on an external library without using any IDE. You would then understand better all the steps that are required to build and run an app, the concept of build and runtime classpath, etc.
Finally got what I needed to know
Sharing it for others who may stuck up in same situation
Does dependency tag download the jar specified?
maven dependency tag actually downloads the jar files you specify in the dependency tag. It downloads and save it under .m2/repositories(local repository) folder on your hard drive (along with some information like last updated, etc)
Local repository is shared among all your projects
from where it downloads?
It downloads the jar from the central repositories. There central repositories contain almost all the open source jar files one needs in a project. It downloads based on information you provide in groupid, artifactid, etc.
http://repo1.maven.org/maven/
http://mvnrepository.com/
can be checked for correct groupid, etc
Once these jar files are downloaded, they are automatically added to the classpath and are available in your project for use.
If the jar files you are searching for, are not available in the central repository, maven may throw error, in that case you can download it manually and let maven know about it.
Without maven you need to put jars into lib folder.
With maven you specify as declaration inside <dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
and when you do mvn package, maven will download required jars on your PC.
With Eclipse and m2e (maven eclipse integration) you can do that all not leaving Eclipse,
and even get sources for used libraries automatically.
Read http://maven.apache.org/ It worth it.
I want to create a simple RDF graph and then try simple querying using SPARQL. Since I'm familiar with java and net beans, I want to use Apache Jena on NetBeans. I downloaded the related files from http://www.apache.org/dist/jena/ .
What should I do next to write RDF codes on net beans? i.e Should I install something or add lib files/jar files somewhere?
(Too long for a comment on Ian's reply)
Maven is easy on netbeans, and a good way to get started with everything you need (as Ian says). Here's a quick guide to start a jena project:
File -> New Project. Choose Maven then Java Application.
Pick project name, location, etc., then Finish.
Netbeans will create a new maven project and open it.
Right click on Dependencies, choose Add Dependency....
Use org.apache.jena as the Group ID, jena-core (or jena-arq if you want SPARQL) as the Artifact ID, and 2.10.1 as the Version.
Open the Dependencies folder. It ought to have a number jars present -- these are jena and its required jars. You might need to right-click on Dependencies again and choose Download Declared Dependencies to ensure jena is ready for use.
Under Source Packages you'll find App.java. Try some of the simple jena api tutorials and try running them.
You need to put the .jar files from the Jena distribution where Netbeans will find them. I don't know Netbeans, but in Eclipse I might have a lib directory in my project top-level directory, and then set the Eclipse's project classpath to include each of those .jar files. Netbeans I'm sure has something similar.
Actually what I do in Eclipse is not use downloaded jars at all, but I would use Maven to manage the dependencies for me. So I would create a pom.xml file in my project folder that stated that, among other things, my project depends on Jena, and then Maven takes care of downloading the dependencies for me. Eclipse and Maven work well together; I'd hope the same would be true of Netbeans. Setting up Maven to use Jena is described on the Jena site. However, learning Maven can be a bit of a steep curve, so if you're not ready to take that on just yet then downloading the .jar files to a project lib directory is the way to go.
Question
Given a Classpath Container I've written as a plugin/extension, how do I add it to the classpath, automatically?
Background
Ok so I'm an experienced Java Developer but extremely new to writing Eclipse Plugins. I've been googling, following tutorials and reading source code of other plugins for a couple days. I know exactly what I want to do but not exactly how to do it.
Right now, in Eclipse, when I click a resource and choose "Run as JUnit test" as in:
Behind the scenes, the m2eclipse plugin somehow generates a run configuration that contains the "Maven Dependencies" classpath container, like the following:
My best guess is that the "Maven Dependencies" classpath container is added through some extension point being used by the M2Eclipse plugin. Similarly, I want to add my classpath container, automatically, whenever a user runs a JUnit test--so it shows up under "User Entries." What extension point(s) can I use to make something like that happen? I've been looking at org.eclipse.jdt.core.classpathContainerInitializer but I'm not sure that's going to do what I need.
Ideal Result
Ideally, I'd like to write a plugin that takes every entry in the project's build path and adds it to the classpath of a run configuration (whenever a new launch configuration is created via: Run As > JUnit test). This should be the default behavior of Eclipse but it's not!
My next-best solution would be to simply add my custom classpath container to the run configuration's build path, automatically. At the end of the day, I just want one classpath for any java code our team runs/launches. This shouldn't be so hard!
Any advise on how to achieve any of this would be appreciated! Even basic pointers on where to look to understand how particular Extension Points are intended to be used (the basic JavaDocs APIs are terrible). Thanks,
gMale
Roostergx provides part of the answer (i.e., how to create the classpath container). The second part, as you admit, is how to add it automatically.
I would recommend using an extension point called org.eclipse.ui.startup. This allows you to contribute code that runs (pretty much) as early as possible when Eclipse starts up. On every startup, you can iterate through all projects and see if any existing projects require the classpath container that you created.
The article at http://www.ibm.com/developerworks/opensource/tutorials/os-eclipse-classpath/index.html provides an exellent description and source for a plugin that defines a project specific classpath container that includes all the jar files in a specified directory.
I am trying to convert a Java project which uses Ant into a Maven project, but am having difficulties finding out which dependencies to include.
How do I find out dependency settings for a particular import?
Provided you currently have the jars on your build-path, at least in Eclipse, when you CTRL + click an imported class, and you have selected "link with editor" on the package explorer, the bytecode outline is opened and the file is selected within the jar it is located.
Then, having the m2eclipse plugin, you right-click your pom -> Maven -> Add dependency, and type the name of the jar there. In most cases that would do.
Another vote for jarvana. There are also (that I know of) mvnrepository.com and www.mvnsearch.org
You need to be careful and figure out the correct version of the jar you need. Also, the repos often have many duplicates; different names for what appears to be the same thing, so you need to figure out which one is the "real" one.
How do I find out dependency settings for a particular import?
The easiest way to do that (in a generic way) is to use something like Jarvana, a "Maven-Focused Java Class and Archive Search Engine".
UPDATE: You'll find more search engines in the Frequently Asked Technical Questions that I'm quoting below. I like Jarvana but I don't have any particular recommendation:
How to find dependencies on public Maven repositories?
You could use the following search engines:
http://repository.apache.org
http://www.artifact-repository.org
http://mvnrepository.com
http://www.mvnbrowser.com
http://www.jarvana.com
http://mavensearch.net