I would like to use the Fluido skin for my Maven-based project.
If I add it only in src/site/site.xml the mvn site fails because the artifact is missing. It ask to manually install the artifact, but I would like to avoid that step for my colleagues.
I've added the following dependency to my pom.xml:
<dependency>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.2.2</version>
</dependency>
And it seems to work: the skin is automatically downloaded by maven when I do mvn site. However I do not want that my project be marked as a dependency of that artifact ; I don't want that package to be in the classpath during compile, test, etc.
I don't see any dependency scope that would restrict the dependency just for site:site.
Did I miss something about dependency scope? Is using dependency for that relationship the right thing?
I do not have time to try this myself, but I think the following should work:
<project>
...
<build>
<plugins>
...
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-site-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.apache.maven.skins</groupId>
<artifactId>maven-fluido-skin</artifactId>
<version>1.2.2</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
...
</project>
Related
I have an external .jar that cannot be imported from public repositories using pom.xml, it's sqljdbc41.jar.
I can run the project locally from my IDE, and everything will work. I referenced the library after downloading it like so:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${basedir}/lib/sqljdbc41.jar</systemPath>
</dependency>
When I run mvn clean package to create my .jar file and try to run the created .jar, a mistake will pop up, which mentions the SQL Server references are not valid. I then extracted my .jar file and true enough, everything that is referenced in the pom.xml file properly gets downloaded and added, however, my SQL Server does not.
I can, in a very hacky way* just manually add the sqljdbc41.jar to my /lib folder after it's been compiled as a .jar, and it'll work, however that seems highly unoptimal. What would be a better approach?
*Opening the .jar file with Winrar, going to the /lib folder, manually selecting my sqljdbc41.jar file, then make sure to select the No Compression option bottom left where Winrar gives you compression options, in case you find this by Google and no one answered.
you can set 'includeSystemScope' to true.
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
You could install the sqljdbc41.jar in your local repository :
mvn install:install-file -Dfile=path/to/sqljdbc41.jar -DgroupId=com.microsoft.sqlserver -DartifactId=sqljdbc41 -Dversion=4.1 -Dpackaging=jar
And then declare the dependency as a standard dependency :
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
</dependency>
If you use a remote artifact repository (nexus, archiva...) you also need to deploy the artifact on this repository. You can find more here : https://maven.apache.org/guides/mini/guide-3rd-party-jars-remote.html
Another way, you can put it into the resources folder, such as resources/lib/xxx.jar, then config the pom.xml like this:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>sqljdbc41</artifactId>
<version>4.1</version>
<scope>system</scope>
<systemPath>${basedir}/src/main/resources/lib/sqljdbc41.jar</systemPath>
</dependency>
In Spring Boot: I also faced similar issue and below code helped me.
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<version>1.5.7.RELEASE</version>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
</plugins>
</build>
It works for me:
project {root folder}/libs/ojdbc-11.2.0.3.jar
pom.xml:
<dependency>
<groupId>com.oracle</groupId>
<artifactId>ojdbc</artifactId>
<version>11.2.0.3</version>
<scope>system</scope>
<systemPath>${basedir}/libs/ojdbc-11.2.0.3.jar</systemPath>
</dependency>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
In my case, the fault was providing a version number without "dot" in tag:
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<version>1</version>
<systemPath>${basedir}/src/main/resources/lib/tools.jar</systemPath>
</dependency>
This one works:
<dependency>
<groupId>jdk.tools</groupId>
<artifactId>jdk.tools</artifactId>
<scope>system</scope>
<version>1.8</version>
<systemPath>${basedir}/src/main/resources/lib/tools.jar</systemPath>
</dependency>
When Spring-Boot projects are used with maven or gradle plugins they packaged the applicaiton by default as executable jars.
These executable jars cannot be used as dependency in any another Spring-Boot project because the executable jar add classes in BOOT-INF/classes folder. This means that they cannot be found when the executable jar is used as a dependency because the dependency jar will also have the same class path structure as shown below.
If we want to use project-A as a maven dependency in project-B then we must have two artifacts. To produce the two artifacts, one that can be used as a dependency and one that is executable, a classifier must be specified. This classifier is applied to the name of the executable archive, leaving the default archive for use as a dependency.
To configure a classifier of exec in Maven, you can use the following configuration:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<classifier>exec</classifier>
</configuration>
</plugin>
</plugins>
</build>
So the MAJIC WORD here is <classifier>exec</classifier> this will create a jar structure as below and then it could easily be conusmed by spring-boot project as maven dependency jar on class path.
The above plugin need to be add in project-A pom that is going to be used as dependency in project-B. Same is explained in spring documentation section 16.5. as well.
In order to work through the local repository, the target .jar file that we will work with must be in the s2 folder. Several methods can be used for this:
The file can be taken manually and put in the relevant place (not
preferred). The same process can be done by installing it via the
console.
Relevant Remote URL is written in the .pom file dependencies and
automatically places it in the s2 folder when Intellij is refreshed
(validate) in the IDE used.
The same process can be done by addressing the .pom file dependencies via the centeral repository.
Attention: ComponentScan should not be forgotten for the related jar work on SpringBot.
I'm new to Spark so am trying to setup a project from the book Learning Spark: Lightning-Fast Big Data Analysis. The book uses version 1.3 but I've only got 2.1.1 so am trying to work around a few differences.
All the Spark related jars that I'm importing into my Java project have a "import org.apache cannot be resolved". I know it's because the project cannot find the jar files specified.
I can manually add each by going to Build Path > Configure Build path and adding them to the Libraries section but I think I shouldn't need to do this. The project uses Maven so I believe if I have the Spark dependencies configured correctly in my pom.xml it should work. Is this correct?
I also set the following environment variables:
export SPARK_HOME=/Users/mymac/spark-2.1.1-bin-hadoop2.7/
export PATH="$SPARK_HOME/bin/:$PATH"
Are there any others I should be aware of?
Here's the contents of my pom.xml:
<project>
<groupId>com.oreilly.learningsparkexamples.mini</groupId>
<artifactId>learning-spark-mini-example</artifactId>
<modelVersion>4.0.0</modelVersion>
<name>example</name>
<packaging>jar</packaging>
<version>0.0.1</version>
<dependencies>
<dependency> <!-- Spark dependency -->
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>2.1.1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.scala-lang</groupId>
<artifactId>scala-library</artifactId>
<version>2.11.8</version>
</dependency>
</dependencies>
<properties>
<java.version>1.8</java.version>
</properties>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
This should be setup as a Maven project, not a Java project. In my case to resolve deleted the project from my workspace, re-created it in the workspace as a general project, then converted it to a Maven project. I probably should have just set it up as a Maven project at the start.
I am trying to start with Spring Loaded with my Spring Boot project, but don't know why it does not want to work.
My pom.xml looks like that:
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>springloaded</artifactId>
<version>1.2.6.RELEASE</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
In IntelliJ Idea it shows springloaded and version on red as NOT FOUND.
I did not change anything else in the pom.xml. Should I add it somehow differently ?
I tried it. IntelliJ IDEA 2017.1.5 doesn't install to local repository dependencies declared in plugins. So you can do it from built-in Maven tool (View->Tool Windows->Maven Projects) or from a command line, run:
mvn install
then re-import dependencies using built-in maven tool.
I am new to maven.
I have created a maven project , in this i have twosession beans and i have added all dependencies in pom.xml. I want to conver this project to EARso that I can deploy it on jboss EAP 6.0 .
I have used
<plugin>
<artifactId>maven-ejb-plugin</artifactId>
<version>2.3</version>
<configuration>
<ejbVersion>3.1</ejbVersion>
</configuration>
</plugin>
but it doen't provide the runtime dependencies.
How do i convert maven project to EAR file. How do get all dependencies including project dependencies at runtime.
I would suggest using maven-ear-plugin. The pom.xml would have the following item inside <build><plugins>..</plugins>..</build> listing:
(taken from the documentation)
<build>
<plugins>
<plugin>
<artifactId>maven-ear-plugin</artifactId>
<version>2.8</version>
<configuration>
<!-- configuration elements go here -->
</configuration>
</plugin>
</plugins>
</build>
Please also refer to the documentation here: http://maven.apache.org/plugins/maven-ear-plugin/usage.html.
Maven handles all the dependencies that you list in the <dependencies>...</dependencies> section that follows the above block. For example:
<dependencies>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
</dependencies>
You can get the dependency details, like the above for log4j, from various maven repositories online. (http://search.maven.org/, http://mvnrepository.com/ etc.)
Recently, I came accross the following problem :
As I set up dependency management for my project, I had child-pom using plugin with dependencies, that I want to be synchronized with dependencies declared in my dependency management.
In a root pom, I declared in my dependency management:
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.4.0</version>
</dependency>
...
<dependencies>
<dependencyManagement>
And in the child pom, I have a plugin which needs gwt-user :
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>2.4.0</version>
</dependency>
...
</dependencies>
...
</plugin>
However, if I remove the dependency version used in gwt-maven-plugin, the compilation fails.
Is there another way to achieve it ?
PS: There is a related post Choosing dependency version in maven and maven plugin which does not answer my question
According to the following links, it seems not to be possible:
http://maven.40175.n5.nabble.com/dependency-management-within-plugin-dependencies-td78367.html
https://issues.apache.org/jira/browse/MNG-2496
Here is a workaround I found, and I wanted to share with everyone, in case other people had the same problem:
In my root pom, I have defined a property, a dependency management and a plugin management:
<properties>
<gwtVersion>2.4.0</gwtVersion>
<gwtMavenPluginVersion>2.4.0</gwtMavenPluginVersion>
</properties>
<dependencyManagement>
<dependencies>
...
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency>
...
</dependencies>
</dependencyManagement>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>${gwtMavenPluginVersion}</version>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<version>${gwtVersion}</version>
</dependency>
...
</dependencies>
...
</plugins>
...
</pluginManagement>
</build>
And in my child pom, using the relationship provided by plugin management (see Maven2 - problem with pluginManagement and parent-child relationship), I just declare the plugin dependency:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
</plugin>
Now if I change the version in the properties, it is automatically impacting all direct dependencies and plugin dependencies.
For a parent POM to control which plugin versions the child uses, you should declare the <plugin> in a <pluginManagement> section of the parent POM.
You defined com.google.gwt:gwt-user as a <dependency> in the <dependencyManagement> section.
I'm not sure if you are intending to use gwt-user as a plugin or as a dependency, but it should be listed as the same entity in both for inheritance to work.
The other possibility is to import all the dependencies of the parent POM:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.4.0</version>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</dependency>
...
</dependencies>
...
</plugin>
Not the most beautiful solution, but working :-)
In my case I was using the jetty maven plugin, with a dependency on hsqldb. I copied some sample lines from the sonatype book (I think that's where I got the lines from) for using the jetty plugin, which specified the groupId as hsqldb. I am using version 2.3.2 of hsqldb. In my parent pom in the dependencyManagement section and my persistence module the groupId is org.hsqldb. Having mismatched groupIds was what was causing me to get an error, because under that old groupId there isn't a version 2.3.2. Once I changed the groupId from hsqldb to org.hsqldb everything started working.