Maven cannot find dependency from imported jar file - spring

I have a service library that contains the Spring Starter Web dependency, e.g.
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
I name this service library "spring-boot-starter-service" and intend to use it in another API project, and this API project does not contain Spring Starter Web.
After making changes to this service library, I use maven install to create a jar file (and I can see that the code changes were reflected) in classes under /target directory
I use the following dependency in the API project, hoping to import the service library and its Spring Starter Web
<dependency>
<groupId>com.example.spring</groupId>
<artifactId>spring-boot-starter-service</artifactId>
<scope>system</scope>
<version>1.0.40</version>
<systemPath>
/Users/xxxxxx/IdeaProjects/spring-boot-starter-service/target/spring-boot-starter-services-1.0.40-SNAPSHOT.jar
</systemPath>
</dependency>
Unfortunately, I was not able to successfully import the Spring Starter Web (as well as other dependencies in the service library) using the above dependency in pom.xml
Anyone knows what I missed? Thanks

Related

Which maven dependency to use for google contact V3 in spring boot java project?

I am trying to integrate google contact API for my project but I cannot find the google contact V3 maven dependency for accessing the ContactsService class.
I tried the gdata-core dependency through which the build gets failed as my project also contains the calendar dependency and the Gmail dependancy so I don't know which dependency to use? Below down I have mentioned the gdata core dependency I tried to use and the gdata contact dependency both dont get compiled
<dependency>
<groupId>com.google.gdata</groupId>
<artifactId>gdata-contacts-3.0</artifactId>
<version>1.41.5</version>
</dependency>
<dependency>
<groupId>com.google.gdata</groupId>
<artifactId>gdata-core</artifactId>
<version>1.47.1</version>
</dependency>
You need to use the following dependency:
<dependency>
<groupId>com.google.gdata</groupId>
<artifactId>core</artifactId>
<version>1.47.1</version>
</dependency>

Using different JBoss BOM in profiles

I have a general question about the usage of the BOM from JBoss and WildFly.
Is the a way to build a project for both JBoss 7 and WildFly 10 using a different profile?
I tried to copy the BOM definition from WildFly into a profile like this:
<profile>
<id>WildFly10</id>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-javaee7-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
<!-- JSON -->
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>${version.json}</version>
</dependency>
</dependencies>
</dependencyManagement>
</profile>
Of course accourdingly with a JBoss7 profile.
But this way it won't add important libraries to the lib folder, i.e. this definition is in an ear pom and a subproject (war) adds the json dependency. Without a profile maven adds the json jar inside the lib folder, but not if I put it inside a profile.
After I read that changing dependencies in a profile is an anti-pattern [1] I would like to know how I can build my project for both JBoss7 and WildFly 10.
Update
Ok sorry for this quick shot of a question. Here are more details.
project structure:
|-parent (pom)
|- myapp (war)
|- core (jar)
|- deployment (ear)
So deployment is the project building the whole ear containing myapp as a web apllication and core as a library. myapp has a dependency to core and core to json.
In order to have all needed depenedencies with the correct version I included wildfly-javaee7-with-tools in the dependencyManagment. Also is the version of json defined in there. The core project has the json library as a normal dependency.
At this point this should be quite standard. But the thing is I want to be able to build for JBoss 7 and WildFly 10, for what I have to change
<dependency>
<groupId>org.wildfly.bom</groupId>
<artifactId>wildfly-javaee7-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
to
<dependency>
<groupId>org.jboss.bom</groupId>
<artifactId>jboss-javaee-6.0-with-tools</artifactId>
<version>${version.jboss.bom}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Of course ${version.jboss.bom} will be changed from 10.1.0.Final for WildFly to 1.0.7.Final for JBoss.
In order to do so I tried to move wildfly-javaee7-with-tools into a profile. My first guess was to only move this dependency to a profile. But then the json jar doesn't get included. After that I also tried to move jsonlike above.
Without seeing the original not-profiled nor profiled pom in whole cannot say anything accurate but educated guess.
You have json in profiles dependency management.
Is it also in poms main dependencies without version? If not it will not be copied to lib nor packed. It is only managed by profiles <dependencyManagement>.
Does json need managing per profile? It seems to have ${version.json} which then anyway would be same for each profile if copied as it is in the example.
For me it seems that fix might be that you remove the json from profiles dependencyManagement and add it to main dependencies as normal dependency - this just to make profiling more simple - it can be managed but if not needed set the version of json directly to dependency.

How is a war file created for spring boot with maven?

I'm trying to follow the guide for converting a spring project to a war.
http://spring.io/guides/gs/convert-jar-to-war/
It starts out using maven and gradle and then right after the jar portion it completely forgets about maven and only has gradle updates.
There are two main changes that you need to make in the pom. The first is to change the project's packaging type to war:
<groupId>org.springframework</groupId>
<artifactId>gs-convert-jar-to-war</artifactId>
<version>0.1.0</version>
<packaging>war</packaging>
The second is to add a dependency on spring-boot-starter-tomcat and mark it as provided:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
mvn package will now produce a war file that can be run using java -jar or deployed to a separate servlet container.
There is an official guide at spring:
http://spring.io/guides/gs/convert-jar-to-war-maven/
Pay attention to "Initialize the servlet" section.
It explains an important point of adding a class that substitutes web.xml. Without it (or without proper web.xml) you will get a war file but when deployed nothing will be accessible in browser as nothing will be registered as your request dispatcher.
Also note that it is best to run this example on Tomcat 8 as it supports latest servlet specs. I have spent number of hours trying to figure out why it does not work on my Tomcat 7.

Maven/Spring multi module project logging

I am trying to convert a huge maven/spring webapp to a multi module project.
Logging is implemented with this method (http://docs.spring.io/spring/docs/4.0.2.RELEASE/spring-framework-reference/htmlsingle/#overview-logging-slf4j) in the huge project. What is the correct way to do this in a maven multi module project? Is it necessary to define this in every pom.xml or only in my main pom.xml.
My main pom.xml defines this dependency:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-framework-bom</artifactId>
<version>4.0.2.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
Is it possibly to exclude commons-logging on this dependency?
Update:
The project structure:
Parent Project:
Project A: jar
Project B: jar
Project C: war
Project D: war
All projects using parts of the Spring framework. I am using SLF4J for logging. What is the correct way for including SLF4J in this project setup with maven?
It should only be necessary to exclude commons-logging from "spring-core", but some third-party libraries also include it, so that isn't always enough. You could try using Spring Boot starters to build up your Spring dependencies (even if you aren't using other Boot features), since the default logging system is logback and commons-logging has been carefully excluded.

Eclipse (STS) MVC 3.0.5 + Tiles 2.2.2 project dependency management issue

For some reason I cannot use maven or gradle dependecy management. I am trying to use Tiles with Spring MVC, I get the following Exception on tcserver startup:
java.lang.NoClassDefFoundError: org/apache/tiles/startup/BasicTilesInitializer
Here is my dependencies folder:
Also Eclipse points out this Error in my layout.jsp
The tag handler class for
"tiles:insertAttribute" (org.apache.tiles.jsp.taglib.InsertAttributeTag) was not found on the Java Build
Path
Can anyone point out what am I missing?
You put the SOURCE jars in you project lib folder. But you need to use the normal once with the compiled classes.
tiles-core-2.2.2.jar instead of tiles-core-2.2.2-sources.jar
If you use maven to manage dependency then add below to your pom.
<dependency>
<groupId>org.apache.tiles</groupId>
<artifactId>tiles-core</artifactId>
<version>2.2.2</version>
</dependency>
Else Download following jars and add it to /WEB-INF/lib
tiles-core.2.2.2.jar
tiles-api.2.2.2.jar
and also add this transitive dependency as tiles use on Slf4j
slf4j-jdk14.1.5.8.jar

Resources