simple scenario:
I have a maven project, containing some maven dependencies (activiti framework) and added the Widlfly 8.1.0 runtime as library in eclipse.
naturally now, if i clean and build with MAVEN, maven won't consider the runtime while compiling and complain that it cannot find eg. the #Webservlet Annotation, HttpRequest classes etc.
so in order to build my Project, i have to run any maven goal and see it fail, just to have maven download all dependencies, then build the project with eclipses' build process which then uses all downloaded maven dependencies AND the wildfly 8.1.0 runtime, succeeding in building the project.
THEN only can I run maven install/deploy to create the .war, which works, because maven finds a compiled target folder, created by eclipse.
How can i, without instlalling all runtime jars to my local repository or adding the wildfly installation as antoher local repo, tell maven or the m2e plugin to include manually added libraries to mavens compile step?
what you probably want is a "provided"*-scope dependency on org.wildfly:wildfly-spec-api:8.1.0 (which is a pom artifact containing all the apis/specifications provided to you by wildfly).
assumming you intend to deploy your app inside wildfly (as opposed to embedding wildfly in your own main() somehow...) you dont need a dependency on the wildfly container.
* - note that since wildfly-apec-api is a pom artifact (and not a jar) you need to use the import scope and not provided. see this article for a complete guide. the gist is you put an import scope dependency on the pom in dependency management, and then you can put a provided-scope dependency on any specific member api/spec that you use (say ejb3, jsf, bean validation or jpa) and the versions will be taken from the spec-api pom.
Related
I currently have the following setup:
parent-pom:
has our common as dependency
service-pom:
is child of parent-pom
contains purge for common, so its always the newest
If I now import the modules in Intellij, the common dependency is used from .m2 folder. The problem is that I cant do refactoring across modules or add something inside a class, I don't have autocomplete.
I tried then changing the project structure. First I've added my local common module as dependency for the service and placed it over the .m2/repository dependency. That worked for autocompletion and refactoring, but can get confusing if I want to use the .m2/repository version.
But compiling and starting spring-boot with it don't works. I added a field to a class from common and referenced it in the service. And when I compiled it, it failed due to this field.
Then I read that I need to configure an artifact (containing common) and added a run configuration and enabled "resolve workspace artifacts". But that also did not work as expected.
Then I've added my local common module to the parent-pom module and added the parent-pom module to the service. In addition I've configured an artifact for the parent-pom.
But that didn't work either.
How can I compile and start my service with the local version of my common (and also be able to use the .m2 if needed)
How do you declare the dependencies between these modules in maven?
Do you have these modules imported into the same IDE project as Maven projects?
For IDE to resolve dependencies to the Maven modules with sources instead of the jars from the local repository, these requirements should be met:
Those Maven modules with sources which you have on your local machine must be added to the same IDE project;
The Maven coordinates (groupId, artifactId, versionId) of these dependencies must match to coordinates of maven modules with sources.
To be able to switch to a local .m2 dependency instead of modules, I think a Maven profile may be used indeed.
I have a Maven project, imported from Eclipse, where the dependencies are set to scope provided. When the project is deployed, the jars are deployed as well so that works fine.
While developing, however, I use a "debugging project" that calls the Maven project, and when it runs I get a bunch of Class Not Found errors when the Maven dependencies are set to provided.
If I change the scope of the Maven dependencies to Compile then the project works fine.
If I change the scope of the dependencies to compile, would that change the output of the project? i.e. add a bunch of jars? That would be undesirable.
I also tried to change the Debug Configuration settings and specified the Maven project in "Use classpath of module", but then the files of the debugging project are not found.
How can I specify the classpath to be of both the Maven project and the debugging project, so that classes from both projects including the dependencies will be on the classpath?
Thanks!
There are 3 types of dependency scope: compile, test, and provided,
compile: the dependency library will be used in all steps: compile , test and run,
test: the dependency library will only be used in the test
provided: the dependency library will only be used in compile and test, but in the run time, the dependency library must be provided by the container otherwise it will throw class no find issues.
Your issues is that you did not provide the dependency library in the run environment ( container) when running your project.
hope this can help you
How did you import the project to Idea? If the project is opened as a Maven projects, it should work out of box.
Can you try to open the project by selecting pom.xml?
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.
I have checked out a Maven project from Subversion. It has Java with Spring framework and Groovy.
We are using Groovy Eclipse compiler plugin. On Maven install, code compiles perfectly with Groovy Eclipse compiler and a jar is created in target.
But there is no directory structure which is usually created in Maven. No classpath too.
I tried many things nothing worked. Finally I converted project to faceted form and then src/java was created as it was faceted to Java project. Still no Maven dependencies.
As there was no Maven dependencies, many jars were missing, so I added jars to build path manually. I also added src/groovy to build path and then it was not able to compile Groovy classes, so I configured project as Groovy project and DDSL was generated. Now after so many manual settings, it is not working fine when it has to create object using spring for Maven class.
I tried a project without Spring framework, and it worked fine.
For pom.xml: I have referred: http://docs.groovy-lang.org/latest/html/documentation/tools-groovyeclipse.html.
I'm converting an existing Eclipse-based web project to a Maven-managed one.
Since the project has lots of dependencies, many of which are custom (they're either internally made or they've been taken from sources that have no public repository), is there some 'magic' Maven POM setting that will let me load every jar from WebContent/WEB-INF/lib and make the project work as before right now, so that I can configure each dependency and do the necessary refactoring to turn it to a proper Maven project with a little more time and care?
I have already seen this question, but the project must continue to compile inside Eclipse, so - or at least I guess - it is not just a matter of using the Maven war plugin
What you want to do is called "installing" your non-mavenized JARs into your maven repository. This can be a local or remote repo that you host.
The command to install to your local repo is something like this: mvn install:install-file -Dfile=My-lib.jar -DgroupId=com.mycompany -DartifactId=My-lib -Dversion=1.2.3 -Dpackaging=jar
You'll want to review the various options for install to suit your project.
Once the non-mavenized dependencies are installed to your repo you can add them to your pom like any other maven dependency. They will be fetched from your local repo.
You will have to set up your own remote repo (like Artifactory) or install each plugin for every developer and CI server in your environment for others on your team to build the project. I strongly reccomend Artifactory, it makes it easy on your and your team to use maven and get dependencies.