I'm working on a Java Web-related project. At this moment, I try to combine some frameworks all together (Hibernate ORM, Apache Shiro). Of course, in the nearest future, I might need some add-ons via maven dependencies. Is it possible to pack it all together, thus for an emergency case also to pack maven? Due to policy restrictions, there is no chance to install the necessary development tools to make it work.
Is it possible to import maven into WEB - project as JAR?
It seems like you want to just keep your entire project directory if I'm understanding you correctly.
Are you sure that they cannot install Maven? If so then you'd want to package maven with the project.
Could you give me more details about the environment you'd be using?
You could easily import the jar into the maven web project. Under the modules section the web projects pom.xml just specify the directory if it is in the same project. If not, you'll have to add it as a dependency. You'll need the group and artifact ID of the jar you want to add. You can find some pointers here.
An example for the project directory structure:
<modules>
<module>the web part</module>
<module>the backed part</module>
</modules>
Each different module would be a sub module of a master project.
This should help you with setting up the classpath. Also take a look # this:
http://stackoverflow.com/questions/364114/can-i-add-jars-to-maven-2-build-classpath-without-installing-them
Related
I have just started working with Maven in Eclipse.
I tried running a sample program in it, and I encountered some problems. The errors were in my pom.xml file. What is the significance of the pom.xml file in Maven?
In short the pom.xml will have all information to build your project.
For example you want to build a project and you have only the pom.xml sent to you via mail. If there are enough entries in the pom.xml then that is all you need! You can import it to Eclipse, Maven will download your source code from CVS, download various dependency jars (like Spring, Apache Commons), run your test cases, build the jar/war, deploy to your jboss/app server, generate a report of your code quality (using Sonar, maybe). Each task you want to do will be mentioned as a goal.
The links already provided are good enough for reference.
POM is an XML file that contains the project configuration details used by Maven. It provides all the configurations required for a project.
POM means Project Object Model, and, as the name suggests, it defines the model of the project as well.
In the normal project development you will add JAR files and libraries as required. In Maven-based development, those JAR files, libraries are added to the project using this pom.xml. In the pom context we call those JAR files, libraries as dependencies.
Maven is a build tool and pom.xml is the main file for the project.
The POM
The pom.xml file is the core of a project's configuration in Maven. It is a single configuration file that contains the majority of the information required to build a project in just the way you want. The POM is huge and can be daunting in its complexity, but it is not necessary to understand all of the intricacies just yet to use it effectively.
For more reference, check Maven in 5 Minutes.
POM stands for project object model. It's the fundamental unit of work in Maven. It is an XML file that contains information about the project and configuration details used to build the project. It downloads required libraries easily using POM XML tags.
When there is no Maven, it needs to add all the library JAR files one by one to the project. But when there is Pom.xml there is no need to add library JAR files one by one.
Simply add the dependency to the Pom.xml, and it will automatically add the library JAR files to the project.
pom.xml is a file which describes the project, configures plugins, and declares dependencies. The POM names the project, provides a set of unique identifiers (called coordinates) for a project, and defines the relationships between this project and others through dependencies, parents, and prerequisites.
A POM file can include a modules section, which tells Maven which directories have POM files which need to be built.
In the build section you can define plugins for which you need to build the artifacts in your project.
Pom.xml is part of your maven project, using pom.xml, maven life cycle you can achieve it.
The pom.xml is a project object model which tells everything 3rd party tool dependencies and library's and required plugins it will give everything to your project like project means any java based web content like itself. once you create the maven project you will get the pom.xml blog which is everything to handle your project
If you want to test your project, you need to add testing dependencies which is the maven community it will provide you once added it will have everything tested.
I'm writing a lot of plugins for minecraft bukkit server's and I've grown tired of copy+pasting the same utility classes in my projects all over again. I decided to just put them all in a separate project and add them to my plugins via maven. I'm using IntelliJ Ultimate.
I want to have a maven project that contains all my utitily classes called e.g. UtilityAPI. Then I want to be able to create another project, which will be my bukkit plugin. In this second project I want to be able to use all the code from the first one. Also, I'd like it very much, that if I choose to build a plugin jar, maven automatically takes into account the most recent code from my API-Project.
I started working on this and started reading about maven modules and how you can use them to forge different projects together. I initially thought, that this was just what I needed, and tried to just add
<modules>
<module>UtilityAPI</module>
</modules>
However this results in my bukkit plugin project being considered a parent project, and refuses to build in a jar, but just in a (at least for me) rather useless .pom file. I'm not sure how to proceed. Do I have to create a "parent" project for my bukkit plugin project which contains the api and the plugin project as modules? And if yes, how do I generate a .jar, and not a .pom?
The dream solution would be to have the UtilityAPI project, and being able to include it in any new plugins that I might write in the future. I'd also be a fan of having a simple way to create a jar with the newest sources of my plugin in it. Is this possible, and if yes, how?
In your Maven multi-module project your plugin would have to be another module (and not the parent, which has packaging type pom). This module would then have a dependency on the API module (dependencies between modules are possible).
However, multi-module projects are usually intended for projects which are tightly coupled. That does not appear to be the case for your scenario. It sounds like the plugins have (potentially) nothing in common except for the dependency on the API project. Maybe it would be better to have the API project as separate standalone Maven project and then deploy snapshot versions of it (or install them only to your local Maven repository) and use these in your plugin projects.
What is the best way to add project in Maven Central repository if it uses jar-file and web-resources (js, css, images)?
I can't find any good way to do it so users could add dependency in pom.xml and get all required files (not only jar-file).
I found WebJars project, but it looks a little compicated and requires additional steps (adding and configuring webjars maven plugin before getting my project).
It would be useful to have another project with similar structure.
Thanks for your help!
OK - if you want to distrubute a webapp as a complete package the most common thing to do is package your application as a WAR.
To do this you just need to add the following to your pom:
<packaging>war</packaging>
Don't forget to ensure that your project conforms to the layout specified by the Maven WAR Plugin.
Once you have your WAR deployed, other WAR projects can depend on it which produce a single WAR that is a combination of the two.
If you need something a little more complicated look at using the Maven Assembly Plugin that allows you to create custom archives. As with the WAR, other assembly projects can depend on it, though as the unpacking is in your hands there is again an increase level of complexity.
I'm a Java developer using Eclipse and Maven. There are some modules I created in a project that I'd like to reuse in my future projects. Is there any standard way to accomplish this using Maven?
I don't like the idea of including classpath in other project. I'm looking for a way to publish and share some specific packages using Maven and over the time I should have a consistent Java library for myself.
You can publish those already existing jars in your repo
using mvn clean package install
and then add those as a dependency to your pom file in the new projects, whereever you chose to use them
This is a very common usecase and nicely covered as maven multimodule project. Check the link for a simple example http://docs.codehaus.org/display/MAVENUSER/Multi-modules+projects. For local development it's enough to run mvn install. In a bigger project or shared environment you will need a maven repository.
Update:
Alternative link: Multi-module project builds with Maven and Gradle
If you want to reuse some code, then you would have to make a new artifact and add this one as a dependency to your over deliverables.
As mentioned by tigran this could be nicely done by using maven multi modules architecture but you can just create a new deliverable used other several projects.
If you can build a jar for the classes you want to reuse, you can deploy them to a Maven repository for future reuse by other projects. However, based on the comments I read so far, you want something like source code level sharing. I assume you use Windows platform for your development. You can use junction or symbolic link to link at the source code level between different projects. Also most of modern version control system like Accurev/Clearcase have support for symbolic link.
My project requires some external libraries to build in in Eclipse. They live in /trunk/lib whereas my project is in /trunk/projectA. To get Eclipse to find the libraries on all machines we set a variable PROJECT_A_HOME.
Now I'm trying to get some builds going with maven and I can not figure out how to add that path (be it environmental variable or relative to $(basedir)) to the build. I really do not want to set up a repository for these dependencies, as I keep them in source control and want builds to continue to work in Eclipse.
I've seen talk about but that hasn't worked for me.
Ideas ?
You should put your static configuration files in resources/ dir. If you have your own or proprietary jars you should set a your own repository so you can download them from the repository or better yet just install them manually , here is how
http://maven.apache.org/guides/mini/guide-3rd-party-jars-local.html
Setting up a file-based repository as suggested in this previous question would allow to keep the libs in your version control system and work seamlessly at the Eclipse level (the libs would be treated like any other dependency). The only problem I can think of could be at the continuous integration level: a build of projectA would require a checkout of trunk/lib. Many CI tools would allow to implement this though. And if not, moving the libs under projectA (or another mavenized project project if you need to share them between modules) would do the trick.