I have a project based on Spring which is running successfully. Now I have created another project based on Jersey which I want to integrate with spring project in Jersey.
I have gone through internet and I added spring project in the build-path of the Jersey project.
Here the problem is whenever I run my Jersey project, it has to execute the Spring project first.
How to configure spring project in Jersey?
You should consider using a dependency management/build tool such as Maven or Gradle.
This way each of your projects will be a module, which can be referenced from the other project as a dependency. You can still use the first project alone and the two-dependent projects alone as wall. Then the tool lets you just simply package the resulting project in a artifact such as WAR with all the dependencies.
Here is a quick maven tutorial - Maven in 5 Minutes
It is a good idea to use such a tool in any case as it has many additional advantages:
Lets you manage also your third party dependencies without needing to manually download the libraries and add them to the classpath
It is much easier to use such a project in cases like continuous integration.
You can run all your tests automatically during the build process to make sure everything works
It resolves transitive dependencies (dependencies of your dependencies)
It builds resulting archive file for you
You can have multiple profiles for different environments
...
Make both of your projects modules of one Maven parent pom project. This way you can build them both at the same time.
Related
I have a project that devided into three pieces, PCommon, PWebapp and PAdminConsole. PWebapp and PAdminConsole are dynamic web project in eclipse, PCommon is java project, and both two web project will use the api in PCommon as a jar file in lib folder.
In the past,I added import project in build path, I used Ant to compile and build PWebapp and PAdminConsole and in both build.xml file there is
<ant antfile="${common}/../build.xml" inheritAll="false"></ant>
to make PCommon into a jar file.
Now I will change all my projects to Maven Project. But I don't know how to make two web projects contain one public module, and how to package my PCommon into a jar file automaticlly when I run package maven command to package one web project.
Now I always deploy my PCommon.jar on nexus server. and then add dependcy in pom.xml in web projects. But I think there is no sense to deploy the jar on the public server, so I think it isn't the right way to archieve this goal. Is there any way that is more convenient?
I know I can make a parent project with a parent pom.xml. But I have two web project need the module, the pom.xml in PCommon can only extends one parent, can't it?
The common way to resolve dependencies in Maven is using a repository. The first time a dependency is needed, it is downloaded from your repository and installed in the repository on your local machine. If a dependency is not available in the remote repository it has to be installed to your local one in some other way. There are a few other ways to resolve depenencies without using the repositories but I wouldn't suggest to use the.
To make this a little more convenient, you can use a proper IDE. I use Eclipse with the m2e plugin. It supports something called "workspace resolution", which should be enabled by default. It scans your workspace for other Maven projects before falling back to the repository lookup. This has the advantage that every change you make in your common project is immediatly available in the other projects. I think it also gets installed to your local repository in the background but I'm not sure. Anyway you don't have to worry about it yourself.
Something similar works with IntelliJ IDEA but I don't have that much experience with it. I'm sure Netbeans has some kind of Maven support too.
I've been asked to apply Maven to a project. After browsing a dozen sites it appears that it's quite vast and I'm not familiar as I'd like with similar tools like Ant. Why is it used/preferred and what does it offer over a standard Eclipse project? Also, how could it be added to an existing project?
Why is it used/preferred and what does
it offer over a standard Eclipse
project?
It is a build tool which can build your project without the need for an IDE like Eclipse. It can create a jar or war or other artifacts from the source, performing a bunch of steps like compilation, running unit tests, etc.
Where maven scores over ant is in managing third-party dependencies and in convention over configuration (which mean less lines of build script if you follow convention).
Also, how could it be added to an
existing project?
You start by creating a new maven project, following the step here.
Place it in the root folder of your project
If your source and resource files do not follow maven folder convention, update maven properties suitably referring to this documentation.
Run mvn package
It will fail if it needs any third party dependencies, which you can add as specified in the doc
With some trial and error, you should have your project running with maven, possibly, much quicker than if you were to set up the same with ant.
Others are already provided sufficient resources to read more about maven.
I suggest to start reading here:
http://www.sonatype.com/books/mvnref-book/reference/public-book.html
Maven is a great tool when you know how to use it. Maven (at core) is a dependency manager.
You include in your pom.xml (similar in function to the build.xml from Ant) all the librairies your project depends on (example : apache commons) along with their version and Maven get them directly from a repository (by default, the central maven repository)
Then you do not have to manually install any jar to make your project work. All is downloaded and cached on your local machine. You can even create an enterprise repository where you put all the jars needed by your company
Maven uses the concept of artifacts which are pre-built library projects with their own dependencies
To mavenize a project, you'll have to write a pom.xml describing your project (examples are numerous), get rid of your libs directory (or whatever classpath you described under Eclipse) and add all your dependencies to your pom.xml
You could also check Mavenizer for a first-start
But Maven is a lot more what i've just said. Read the docs, read poms from librairies and you'll get used to it quickly ;-)
If you use the M2Eclipse plugin from Sonatype, it's just a matter of right clicking the project in the package explorer and choosing Enable Dependency Management in the Maven menu. You are also advised to adjust the directories that contain the sources to the Maven standard directory layout but if you absolutely can't, you can configure that later.
Apart from that: Well, look for tutorials and documentation (for example there is the free book Better builds with Maven. Maven is very complex (yes, I don't think it is simple) and very powerful.
I downloaded Java source code of some project that works with Maven. After checking out
the code to Eclipse, and then building it from the command line, I followed the instructions
and imported it from Eclipse as: File > Import > Maven Projects. Now I have the core source code and many additional sub projects that seem to have the same thing like the core, just separated.
Could anyone please explain me what are these sub projects? why I need them? and on which code I need to work now if I want to make changes, the core or the new imported Maven ones?
I don't know nothing about Maven besides the fact that it's a tool for building code and managing releases.
Thanks!
In Maven land, these are called modules. There a nice way to further divide a project into very distinct pieces.
People handle Maven differently. I've seen projects where there was the actual project module, then 10 or so implementation modules. Most people use them for the above mentioned separation.
Most likely, your going to need all of the modules in order to work correctly.
To modify the project, your going to need Maven. I don't know if Eclipse has an embedded maven, but at least NetBeans does. With this you can modify anything that you want, then build it with Maven, which should be just a simple click.
In addition to what #Quackstar said:
Eclipse has embedded Maven support provided by the m2eclipse plugin. When you import a Maven project consisting of multiple modules, the default behavior is to map each Maven module as a separate Eclipse project. This allows the Eclipse build paths to be constructed in a way that matches the declared Maven module dependencies.
There is also a way to map a multi-module Maven project into a single Eclipse project that entails enabling m2eclipse's "Nested Module" support. This results in an Eclipse project with a build path that is an amalgam of all of the Maven module dependencies ... and not exactly correct. This approach is not recommended by the m2eclipse developers, and I've heard they are intending to remove the nested module feature entirely in a future release.
using IDEA ultimate, how would I start a project and have the following layout:
/src/
/src/main/java/com/example/myapp
/src/main/resources
/src/main/webapp
/src/main/webapp/META-INF
/src/main/webapp/WEB-INF
/src/main/webapp/WEB-INF/jsp
/src/main/webapp/WEB-INF/lib
/src/main/webapp/WEB-INF/myapp-servlet.xml
/src/main/webapp/WEB-INF/web.xml
So from what I understand, once this is setup I have to now somehow wire things using Modules/Artifacts/Facets.
I have JDK and tomcat setup.
I just don't know how to wire things up, so when I hit RUN it will build, deploy the app.
The best way to start creating a web project in Idea is to use either a maven project (any project with valid pom.xml and by your folder structure I guess thats what you are trying to do) Or create a project and add a web module (a module with web facet). Artifacts are like your build artifacts, your wars, jars and such things. Modules are sub projects or logical division of your main projects like common module, services, web module in a main project. Facets gives your some extra features like spring auto completion. It tells the IDE that your module is using so and so technology...
I am trying to use JIBX maven plugin in my Spring Web Service project,
My project has diferent layers (API-DAO-SERVICE vsvs..)
these layers are individual projects and has maven dependency each other.
In my WEB project's POM, I add other project as dependencies, and my mapping
classes are all in API project.
Even in my web project's POM includes dependencies of API project I could
not use that class'es in JIBX
BUT IF I put that class'es in WEB project's src/main/java directory there is
NO PROBLEM,
How can I use mapping classes that are other maven dependent projects.
Any help is really appreciated;
Thanks.
Generated sources are supposed to be compiled and packaged in the artifact at the end. The classes should thus be visible from your webapp.
Did you setup the maven-jixb-plugin as shown in Generate Java Sources from Schemas? If not, then maybe update your setup first and try again.
And if you are still facing problems, please show the relevant parts of your POM(s).