I add my maven dependency as compile, runtime or test but it remains unresolved
This is for Intellij idea verison 2019, Java 8 and Maven 3.6.0
Error -> cannot find symbol
The dependency you are trying to depend on is a runnable Spring Boot archive. These are not intended to be used as dependencies. From the Spring Boot doc (might be an older version):
Like a war file, a Spring Boot application is not intended to be used
as a dependency. If your application contains classes that you want to
share with other projects, the recommended approach is to move that
code into a separate module. The separate module can then be depended
upon by your application and other projects.
Related
I'm working on a project with a library module that has about 10 submodules.
For the application project the developer asked us to find a way so that they can import only one dependency, instead of the requested 10. Let's use as an example the dependency of log4j: I need only to include one not all the sub-dependencies.
How can I achieve this kind of structure for my library?
I believe this can be accomplished by making use of Maven's transitive dependencies. Essentially, you will create a new project which then has dependencies on all the other dependencies you want to group and provide to another application. You can then add the new project as a dependency in the application's POM, bringing in all the transitive dependencies.
This is kind of similar to the Spring Boot Starter dependencies, which package a few Spring dependencies together to make it quick to get started with Spring Boot. See https://github.com/spring-projects/spring-boot/blob/main/spring-boot-project/spring-boot-starters/spring-boot-starter/build.gradle
There are many Maven artifacts named spring-boot-starter-*. As the names imply, they are very useful for an application project to get started with Spring Boot.
However, after the application project become stable, should it keep using these spring-boot-starter-*?
My concern is that doing so uses the Maven mechanism of "transitive dependencies", and it seems to violate the suggestion in Maven documentation:
Although transitive dependencies can implicitly include desired dependencies, it is a good practice to explicitly specify the dependencies you are directly using in your own source code.
For example, suppose an application project directly uses the Spring annotation #EventListener. The annotation is in the Maven artifact spring-context, and spring-context is included in spring-boot-starter. Should the application project directly specify the dependency on spring-context after it become stable?
The Spring Boot starter artifacts are just a shorthand for including several Spring Boot artifacts at once. My company has services in production that use starter artifacts. Of course, you could replace each starter with a list of the artifacts it contains, but I think the Maven suggestion is more about unrelated transitive dependencies, such as if your application inherited Guava from some JSON library as a transitive dependency.
When the transitive dependencies all come from the same source and are designed to work together, I don't think it's a problem. At least, I don't see it as such.
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 am using STS version: 3.8.0.RELEASE; Build Id: 201606301029
When I create a Spring Starter Project, it should by default have Java, Spring and Maven nature. But it only has Maven nature and the folder structure is also not in accordance with Maven nature (src/main/java). Also, the POM shows error message that unable to locate parent POM spring-boot-starter-parent 1.3.6.RELEASE.
I observed that while creation of a Spring Starter project , it should download all the necessary dependencies from starter.zip, but its not downloading from my STS ide.
Is this a setup issue or some network related issue?
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.