Javadoc for a New java maven project in eclipse - java

I created a new Maven project and generated Javadocs through eclipse. It created a lot of html files in the project directory inside a folder called "doc".
Now I want to distribute this project as a dependency to my colleague and he does not have the source of the project I created. He is only adding my project as a dependency. He says he cannot see the javadoc when he hovers on a method that I created in my project.
What am I missing here?

Add the maven-javadoc-plugin to the project (plugins section of your pom.xml), instead of generating the Javadocs through Eclipse. Please have a look at the jar goal. If done correctly, the Maven build will package a javadoc jar beside the normal jar file. The build will result in following jars:
${artifactId}-${version}.jar
${artifactId}-${version}-javadoc.jar
If you want to provide the sources additionally, the maven-source-plugin (goal jar) will do the job for you.
The installation of the jar file, the javadoc file and in case the source file into your colleague's local Maven repository can be done with the maven-install-plugin.

Related

How to see source code of jar attached through maven dependency

I am working on maven project in eclipse and I have some 7-10 jar files. I have added dependency of those jar files in my POM file. But when I click any function which is part of libraries, my eclipse complains that no source code found. All jar files are successfully downloaded in my local maven repository. I am struggling to attach source code. I have already tried downloading sources and Javadoc under maven but it is still not working.
You can use a tool to decompile .jar files, for example this.
Other option is use the Jetbrains IntelliJ IDE that includes a potent decompiler right out of the box.
Please check if you have Maven Dependencies on your build path
I suggest you use more popular IntelliJ IDEA IDE rather than eclipse, you can view jar source code easily.

Maven dependency for self placed jars in project level

I created the java class and converted into jar files. So, I want to use those jar files which I have placed in project level in some folder like "External Jar".
So I need to write a dependency in maven that when someone imports my project they should be able to run the program.
Basically you created your own jar and you want to publish this jar, so that when somebody else clone/use your project, this jar comes with (assuming that you have a maven project and dependency of your jar is included in pom.xml).
To achieve this, you need to publish your jar to maven , you can follow many of the online docs like http://kirang89.github.io/blog/2013/01/20/uploading-your-jar-to-maven-central/ on how to publish jar to maven central.
Edit:- As suggested by khmarbaise, please use official reference http://central.sonatype.org/ for central repository.

Add library into jar of project

My problem is with a project where I use the POI library. It's from apache and allows you to work with excel,word, ... .
I had to add some jar files to my library and it runs perfect.
The problem is when I put my JAR file somewhere else.
It gives me the errors it can't find the librarys.
Is there a way I can put my librarys into the 1 jar?
I already tried to add my lib folder as source package but that didn't help.
there is a Maven plugin for Eclipse called M2Eclipse, which will read a POM and construct a classpath out of jars it finds in the local repository and any remote repositories you've configured. It behaves largely like Maven does in terms of finding the latest version for a given jar (if you've specified a version range in your POM).
You can also have a look on this
http://fredpuls.com/site/softwaredevelopment/java/deploy/five_strategies_for_managing_j.htm
You want to make a 'shaded' or 'uber' jar, which has all of its dependencies included
There is a maven plugin for building a shaded jar.
https://maven.apache.org/plugins/maven-shade-plugin/
For me the fastest/ easiest solution was to just open my project in eclips and export is a runable JAR then it adds the librarys to the JAR.
NetBeans builds your application into the project's dist folder. There is also a readme file in it, that tells you, you should distribute the contents of that folder...
Edit
Remove the lib folder, that is shown on the second image, from your sources.

Convert Java/Dynamic web project to maven project using Maven Command line

I want to convert a Java/Dynamic web project to a Maven project. I use Eclipse IDE to develop Java applications.
One of the straight forward options available to me is to use 'Convert to Maven project' in Eclipse. But there are situations where I cannot use that option since the Maven plugin doesn't work in some networks like my Work environment.
So I want to know a Maven command (on Command Line) that would help me convert my Eclipse-built Java Web App to a Maven project.
Thank you in advance, Happy learning.
The Eclipse feature "Convert to Maven Project" works on projects that already have an appropriate POM. A project that was initially created by Eclipse doesn't have that POM.
So what you must do, is simply create a POM with packaging type WAR, then put it into the root of the project.
You also have to take care of the source directories. The Maven standard way is to have all sources under these four directories:
src/main/java
src/main/resources
src/test/java
src/test/resources
Eclipse simply stores everything under src. So you either change your file and directory structure, or you change the appropriate <build> parameters in the POM. I suggest the former.
The "Convert to Maven Project" feature does more than adding the Maven nature to the Eclipse build settings. It also creates and configures the Eclipse project meta files (the files .project and .classpath and the folder .settings). Therefore I suggest to delete them first in your project directory, so Eclipse can start on a clean project.
Afterwards you simply can convert your project with the above mentioned feature. It should create the meta files, and - as it is a web project (packaging type WAR) - it also should add the appropriate natures that let Eclipse show the project as a web project.

How to build project from maven pom file

I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir. Cd into that dir and ran mvn command without any arguments but I got bunch of errors. I am absolutely new to maven so I think I am missing something. I tried also from Eclipse ( Import project -- exisitng maven project) but that also does not work except eclipse creates a project that has just that file pom.xml. I expect something that first it will download the jar for the project and then download all dependent jars and config files but nothing there.
So given a pom file how do I build the project from it?
mvn install should get you going
I have a maven pom file for an open source project. This pom file has all the info like what other jars it depends on etc. I installed maven. Created a dir samprj and copied the pom file into that dir ...
It sounds like you only have the project's POM file. This is not sufficient. You need to checkout the complete source tree for the project. Having done that, change directory to the directory containing the POM file and run mvn install.
Also, don't copy the POM to a different directory. Maven expects to find all of the source files relative to the POM file location.
FOLLOW UP
Thanks for advice. I was not able to use the command mvn install as it gave errors.
Probably because you hadn't checked out the source.
I don't know how to check the source tree of the project ...
Use a subversion client (the svn command for example), or one of the Eclipse subversion plugins.
If this was a properly documented project, there would be clear instructions on what version control and build tools you needed, how to checkout the source code and how to build it.
... as I thought POM itself should have this information to automatically checkout if the source is not check out.
It doesn't necessarily, though in this particular case it does.
Anyway I was able use Eclipse to build the project without errors.
(Other readers can read #icyrock.com's answer for links to the m2eclipse plugin and documentation.)
The only problem is the dependent jars were downloaded but hidden deep paths in .m2 repository folder on my linux box.
But I would like these dependent jars to be relative to dir where POM file is.
Sorry, but that is not the way Maven works.
The ~/.m2/repository directory is a fundamental part of Maven. It is not a problem. It is a feature. (Don't fight it!)
If you want to open this within Eclipse, you need to install m2eclipse:
http://www.eclipse.org/m2e/
and then import the project as a Maven project as described here:
http://books.sonatype.com/m2eclipse-book/reference/creating-sect-importing-projects.html
Try out their getting started guide. It has a lot of good examples:
http://maven.apache.org/guides/getting-started/

Categories

Resources