I have to use libraries in tools.jar and have therefor added this dependency:
<dependency>
<groupId>com.sun</groupId>
<artifactId>tools</artifactId>
<version>1.6.0</version>
<scope>system</scope>
<systemPath>${java.home}/../lib/tools.jar</systemPath>
</dependency>
Now I would like to attach the sources in Eclipse, so I see what I develop against.
I guess nothing will be available in the standard maven repositories (I can't even find anything in download.java.net/com/sun).
I know there is a source archive available, but it contains everything and I would at least need to know what parts of it need to go in the source jar.
Has someone done this? Is there a tools-sources.jar available somewhere? Or can you tell me what parts of the jdk sources I need?
Here's what I did. I downloaded the source archive from openjdk, extracted it and manually linked the jar source to
External Folder -> [unpacked archive basedir]/langtools/src/share/classes
This is not a maven solution, it's eclipse only, but it works.
Related
I am starting to play around with Maven, to see whether we could use it in the future to handle our dependency management, and IDE environments.
I have looked at some YouTube vids on how to get started with Eclipse (we also use Eclipse), and where you basically start off with creating a new project of type Maven. I have done this, and imported my existing source into the src/main package type.
Now I want to start adding the dependencies. No changes to my pom file yet.
I have two directories with jar files in them, and I need to set those dependencies in the pom file.
How do I do that?
This is not how you usually use Maven. You can add a jar through a path
<dependency>
<groupId>org.javap.web</groupId>
<artifactId>testRunWrapper</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${basedir}/lib/testRunWrapper.jar</systemPath>
</dependency>
but the recommended way is to draw your jars from a Maven repository (like MavenCentral, or your Nexus/Artifactory).
So if you want to use Maven in your company, make sure you have a running Nexus or Artifactory server in your company as well. Then you can either proxy external Maven repositories (which contain most of the available open source components) or upload your own jars through the interface of your Nexus/Artifactory.
I was using eclipse for building my project. Now I am configuring the project to Maven project. All the libs were manually downloaded to lib folder. If I do a Maven build, Maven is unable to map those libs. There are lots of libs, I don't want to manually place them in pom.xml. What is the best way out?
I have read few answers, first declare local repo and then add the respective dependencies. But again I don't want to add all the dependencies manually.
Maven: best way of linking custom external JAR to my project?
1.) Install locally
There are two scopes which are interesting for you. If you declare a scope "runtime" (which is the default scope) and have a local repository configured, maven will try to download the file from your local repository.
2.) System dependency
If you just don't want maven to manage dependencies, you can (although shan't) use the system scope like this:
<dependency>
...
<scope>system</scope>
<systemPath>/path/to/dependency.jar</systemPath>
</dependency>
The downsides are:
the system scope is deprecated and might not work in future versions of maven.
you need to check in a jar file, which is not a good idea.
it may not be portable (e.g. architecture dependent libraries).
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 have two maven projects, the first one is a library and the other one use it to works properly, the both have to elvolve regardless each other, this is why i use two different project.
But breakpoints on my library code doesn't work when i launch my app (the second application).
This is how i include my library in the second project's POM (my IDE is eclipse and projects are in the same workspaces)
<dependency>
<groupId>com.mcamier</groupId>
<artifactId>lazyEngine</artifactId>
<version>0.0.1-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${basedir}/../lazyEngine/target/lazyEngine-0.0.1-SNAPSHOT-jar-with-dependencies.jar</systemPath>
</dependency>
I think the quick fix to this is to right-click on your application project in Eclipse and choose Properties, remove the library jar from the external jars, and add the library Eclipse project to projects (i.e. the list of project dependencies).
So today I downloaded Apache Commons Lang library (binary, zip format). I extracted it to C:\eclipse\commons-lang-2.5 folder. There are a commons-lang-2.5.jar, a commons-lang-2.5-javadoc.jar, and a commons-lang-2.5-sources.jar inside, and a folder for HTML Javadoc. I started Eclipse, added commons-lang-2.5.jar, and set its source and Javadoc respectively as the screenshot below. (http://img43.imageshack.us/img43/9378/eclipsev.png)
My question is, is there a convenient or standard way to add external libraries? Or am I actually doing the right thing?
Recommendation:
Create a "lib" folder and keep all your jars in the folder.
Subsequently, add all the jar files in the lib folder into your build path by using Project => Properties => Java Build Path => Libraries => Add JAR ...
btw, there' no screenshot. Can you give the link for the screen shot so that I may be able to help our better...
You must add jar file on lib folder
and then right click on jar file and click "build path"-->add to build path
and now you can write that jar file code
Use maven
You don't have to download all jar's into a folder by yourself! -
use maven. It's based on a public repository, and you manage your dependencies in an xml file.
Your project will have a pom.xml file that going to look like this:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany.app</groupId>
<artifactId>my-module</artifactId>
<version>1</version>
</project>
and in this file you manage the external library dependencies
for instance, if you wish to add this dependency - http://mvnrepository.com/artifact/org.apache.commons/commons-lang3/3.4
you will need to modify your pom.xml like so:
<project>
...
<dependencies>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.4</version>
</dependency>
</dependencies>
...
</project>
and save it. that's it
Read this getting started tutorial - https://maven.apache.org/guides/getting-started/
eclipse plugin - https://maven.apache.org/plugins/maven-eclipse-plugin
As the question is quite general, maybe following detailed answer could help others:
Right click on your project name
Select and expand the correct (e.g C/C++) compiler
Go to "Includes"
On right hand corner, you would see a small icon to "add path" to include your custom library
Add, build and happy compiling