Changing maven build output directory for .jar (has dependencies) - eclipse

I'm setting up eclipse again to make plugins for bukkit, which is an API that i depend on. Also i want to move the .jar the build process creates to a directory of my choice.
http://wiki.bukkit.org/Plugin_Tutorial#Commands (makes the pom.xml below)
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MY_PACKAGE_NAME</groupId>
<artifactId>MY_PLUGIN_NAME</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>bukkit-repo</id>
<url>http://repo.bukkit.org/content/groups/public/</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.bukkit</groupId>
<artifactId>bukkit</artifactId>
<version>1.7.9-R0.2</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
</dependencies>
</project>
Current output:
$project_root/target/MY_PLUGIN_NAME-0.0.1-SNAPSHOT.jar
Desired output:
C:/my/output/directory/MY_PLUGIN_NAME-0.0.1-SNAPSHOT.jar

You can use following configuration under <build> tag:
<outputDirectory>C:/my/output/directory</outputDirectory>
tip / warning : Although this will work but keeping your packaging outside target is discouraged. Its not maven standard. Rethink before doing it.

Related

Problems building effective model for com.MyProject:jar:1.0-SNAPSHOT

My project already runs correctly inside netbeans, but when I want to do "clean and compile" to create the .jar file, it doesn't create the "dist" folder but a "target" folder and doesn't even execute the file, in Console I get It shows some meven errors and the pom file that I still don't know how to fix. I hope someone can guide me in this final step of my project. I leave the capture and the code of the pom file.
error 1
error 2
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mycompany</groupId>
<artifactId>Compugar1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<showDeprecation>false</showDeprecation>
</configuration>
</plugin>
</plugins>
</build>
<repositories>
<repository>
<id>unknown-jars-temp-repo</id>
<name>A temporary repository created by NetBeans for libraries and jars it could not identify. Please replace the dependencies in this repository with correct ones and delete this repository.</name>
<url>file:${project.basedir}/lib</url>
</repository>
</repositories>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>com.formdev</groupId>
<artifactId>flatlaf-intellij-themes</artifactId>
<version>2.4</version>
</dependency>
<dependency>
<groupId>unknown.binary</groupId>
<artifactId>AbsoluteLayout</artifactId>
<version>SNAPSHOT</version>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.22</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-text</artifactId>
<version>1.0</version>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-checkstyle-plugin</artifactId>
<configuration>
<configLocation>config/sun_checks.xml</configLocation>
</configuration>
</plugin>
</plugins>
</reporting>
<name>Compugar</name>
<description>Base de datos de clientes, antenas, reportes y pagos</description>
</project>
I tried to delete the dependencies and download them again, but it didn't work...

Multi module Maven Project dependency issue?

I have a multi module project where common-project is depend on another 3rdparty project and below is the pom.xml of common-project
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.tri.iss.pet.common</groupId>
<version>0.0.1-SNAPSHOT</version>
<artifactId>common-um-entities</artifactId>
<name>common-um-entities</name>
<description>Common UM Entities</description>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<fork>true</fork>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.tri.iss.pet.common</groupId>
<artifactId>3rdparty</artifactId>
<version>0.0.1-SNAPSHOT</version>
<type>jar</type>
</dependency>
</dependencies>
</project>
As you clearly check i have added dependency in pom.xml file but check below image its saying jar missing
Can someone tell me why only project dependency not able to load while other dependency which coming from Artifactory working fine ?
Note:- Dont be confuse from project name .

JFXtras ClassNotFoundException on maven build

I am using Eclipse with the Maven integration and included JFXtras in my project. When I do the maven build, it successfully creates the jar, but when I try to run it, I get a
java.lang.ClassNotFoundException: jfxtras.scene.control.ListSpinner
I integrated jfxtras like described here:
http://mvnrepository.com/artifact/org.jfxtras/jfxtras-labs/8.0-r3
Edit:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>propgr</groupId>
<artifactId>Project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-labs</artifactId>
<version>8.0-r1</version>
</dependency>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-controls</artifactId>
<version>8.0-r1</version>
</dependency>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-common</artifactId>
<version>8.0-r1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>main.Main</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Any ideas / help?
JFXtras consist of a number of artifact; labs, controls, common, ..., with some dependencies between them. The dependency for labs is missing. The pom below works for me.
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>propgr</groupId>
<artifactId>Project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-labs</artifactId>
<version>8.0-r3</version>
</dependency>
</dependencies>
<build>
...
</build>
</project>
That is for a release, if you want to use a snapshot, you need to add the Sonatype snapshot repository in the pom or .m2/settings.xml
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>propgr</groupId>
<artifactId>Project</artifactId>
<version>0.0.1-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>org.jfxtras</groupId>
<artifactId>jfxtras-labs</artifactId>
<version>8.0-r4-SNAPSHOT</version>
</dependency>
</dependencies>
<repositories>
<repository>
<id>oss-sonatype</id>
<name>oss-sonatype</name>
<url>https://oss.sonatype.org/content/repositories/snapshots/</url>
<snapshots>
<enabled>true</enabled>
</snapshots>
</repository>
</repositories>
<build>
...
</build>
</project>

Maven local repo not updated with latest dependency

My project has a pom.xml which I did deploy to a remote repository inside my company
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>ProjectMav</groupId>
<artifactId>ProjectMav</artifactId>
<version>1.0</version>
<distributionManagement>
<repository>
<id>man-release</id>
<name>mav release repo</name>
<url>http://xxxxxx.net/repositories/mav-release/</url>
</repository>
<snapshotRepository>
<id>mav-snapshots</id>
<name>mav snapshots repo</name>
<url>http://xxxxxx.net/repositories/mav-snapshots/</url>
</snapshotRepository>
</distributionManagement>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
After I do a 'mvn deploy' I did browse the remote repository and I see the project there
I have another project that is dependent on the above mentioned 'ProjectMav' and it's POM.xml is as follows
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>mavtest</groupId>
<artifactId>mavtest-suite</artifactId>
<version>1.0</version>
<dependencies>
<dependency>
<groupId>ProjectMav</groupId>
<artifactId>ProjectMav</artifactId>
<version>1.0</version>
<scope>compile</scope>
</dependency>
</dependencies>
<repositories>
<repository>
<id>mav-release</id>
<name>mav release repo</name>
<url>http://xxxxxx.net/repositories/mav-release/</url>
</repository>
</repositories>
<build>
<testSourceDirectory>src/com/mav/</testSourceDirectory>
<resources>
<resource>
<directory>/resources</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
</resource>
</resources>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
Now from eclipse if I do a Maven>update project it does not get the latest version of my 'ProjectMav' to my local repository.
But if I clear all the files in my local repo and do a maven update it gets my project
Any idea what's going on?
I believe the issue is that the maven eclipse plugin's update doesn't actually do a mvn install which is what you need if you want to override the 1.0 deployed version. The way the mvn eclipse plugin orders classpath dependencies (which you can clearly see in the package explorer is to put the dependency jars first and then the resolved upstream projects after the jars). This seems to work fine for SNAPSHOT projects as the plugin knows to use your project and not the jars but for release jars it gets confused (or at least I have noticed it to).
That being said you should avoid this issue altogether by changing the version of your local one to:
<version>1.1-SNAPSHOT</version>
Then in your downstream projects that depend on ProjectMav you update their dependencies to 1.1-SNAPSHOT. The management of versions can be tricky so you might want to look into the maven release plugin and have it deal with version-ing of your project when you deploy.

How to add Spark to Maven project in Eclipse?

I would like to start Spark project in Eclipse using Maven.
I've installed m2eclipse and I have a working HelloWorld Java application in my Maven project.
I would like to use Spark framework and I'm following directions from the official site.
I've added Spark repository to my pom.xml:
<repository>
<id>Spark repository</id>
<url>http://www.sparkjava.com/nexus/content/repositories/spark/</url>
</repository>
And then the dependency:
<dependency>
<groupId>spark</groupId>
<artifactId>spark</artifactId>
<version>0.9.9.4-SNAPSHOT</version>
</dependency>
But I'm getting an error in Eclipse:
Missing artifact spark:spark:jar:0.9.9.4-SNAPSHOT
How can I resolve this issue? I don't want to download Spark's jar file and place in the local repository.
This is my pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.myproject</groupId>
<artifactId>Spark1</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<name>Spark1</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<repository>
<id>Spark repository</id>
<url>http://www.sparkjava.com/nexus/content/repositories/spark/</url>
</repository>
<dependencies>
<!-- (...) -->
<dependency>
<groupId>spark</groupId>
<artifactId>spark</artifactId>
<version>0.9.9.4-SNAPSHOT</version>
</dependency>
</dependencies>
</project>
Currently no repository is required to add for Spark library loading
You just need to add
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.6.0</version>
</dependency>
And that's it.
Useful tutorials to play with is here
The repository block needs to be wrapped in a repositories block:
<repositories>
<repository>
<id>Spark repository</id>
<url>http://www.sparkjava.com/nexus/content/repositories/spark/</url>
</repository>
</repositories>
Reason for failure is 0.9.9.4-SNAPSHOT is not available.Below is the list of the snapshots available. Use one among them based on your requirement.
0.9.8-SNAPSHOT/ Sat May 21 21:54:23 UTC 2011
0.9.9-SNAPSHOT/ Mon May 23 10:57:38 UTC 2011
0.9.9.1-SNAPSHOT/ Thu May 26 09:47:03 UTC 2011
0.9.9.3-SNAPSHOT/ Thu Sep 01 07:53:59 UTC 2011
Thanks,
Sankara Reddy
I had run into same issue because initially I started with different repository url for spark and then to use earlier version I changed the repository url. Some how it didn't seem to come into effect until I changed the repository id. Try changing the repository id.
Could be bug in maven because running maven from console also couldn't resolve the dependency without updating the id.
please add the repository , tag inside the repositories tag like below
<repositories>
<repository>
<id>Spark repository</id>
<url>http://www.sparkjava.com/nexus/content/repositories/spark/</url>
</repository>
</repositories>
The last versions (2.1 and later) of Spark only need the dependency defined inside the pom.xml file
<dependency>
<groupId>com.sparkjava</groupId>
<artifactId>spark-core</artifactId>
<version>2.1</version>
</dependency>
the repository definition is not longer required
use this latest repository.
http://mvnrepository.com/artifact/org.apache.spark/spark-core_2.10/1.6.0
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.10</artifactId>
<version>1.6.0</version>
</dependency>
use this, and also make sure you change spark library to version 2.11.x in eclipse project build path
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.spark-scala</groupId>
<artifactId>spark-scala</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>${project.artifactId}</name>
<description>Spark in Scala</description>
<inceptionYear>2010</inceptionYear>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<encoding>UTF-8</encoding>
<scala.tools.version>2.10</scala.tools.version>
<!-- Put the Scala version of the cluster -->
<scala.version>2.10.4</scala.version>
</properties>
<!-- repository to add org.apache.spark -->
<repositories>
<repository>
<id>cloudera-repo-releases</id>
<url>https://repository.cloudera.com/artifactory/repo/</url>
</repository>
</repositories>
<build>
<sourceDirectory>src/main/scala</sourceDirectory>
<testSourceDirectory>src/test/scala</testSourceDirectory>
<plugins>
<plugin>
<!-- see http://davidb.github.com/scala-maven-plugin -->
<groupId>net.alchim31.maven</groupId>
<artifactId>scala-maven-plugin</artifactId>
<version>3.2.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.13</version>
<configuration>
<useFile>false</useFile>
<disableXmlReport>true</disableXmlReport>
<includes>
<include>**/*Test.*</include>
<include>**/*Suite.*</include>
</includes>
</configuration>
</plugin>
<!-- "package" command plugin -->
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.scala-tools</groupId>
<artifactId>maven-scala-plugin</artifactId>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.spark</groupId>
<artifactId>spark-core_2.11</artifactId>
<version>1.2.1</version>
</dependency>
</dependencies>
</project>