I am setting up a Maven repository with the goal of automating much of my build and deploy process. My current workflow begins with bringing up a server, doing a git clone, and running a bunch of mvn install commands to complete the top level application.
To my understanding, Maven is not a tool for deploying applications, and at this point I do not see a need for a continuous integration or continuous deployment server or formal process.
However, thus far I have not been able to find a canonical way to put together the complete, runnable program together with Maven.
This script goes so far as to get the top level jar and install it into the local maven repo:
mvn -DgroupId=me.company -DartifactId=Top-Level-Application -Dversion=1.0-SNAPSHOT -DrepoUrl='http://theserver:8081/nexus/' dependency:get
If I installed everything manually, this application would find all of its dependent jars in a lib/ directory, as Maven ought to do. However this jar as pulled is not deployable - while the dependent jars are installed to a local repo they are not compiled where the classpath expects it.
I imagine if I could rig the above script to pull the pom.xml instead of just the jar and run a mvn install on that, everything would go smoothly (although weirdly that seems to be duplicating the last step of the build process). Another option is for applications to contain all dependent jars rolled up into one giant jar and have no external dependencies.
Which of these (or other) options is the proper way to complete the Maven build process?
Here is our top-level pom narrowed down to as much as I can think would be relevant:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>me.company</groupId>
<artifactId>Top-Level-Application</artifactId>
<packaging>jar</packaging>
<version>1.0-SNAPSHOT</version>
<name>Top Level Application</name>
<url>http://company.me</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<distributionManagement>
<repository>
<id>releases</id>
<url>http://host:8081/nexus/content/repositories/releases</url>
</repository>
<snapshotRepository>
<id>snapshots</id>
<name>Internal Snapshots</name>
<url>http://host:8081/nexus/content/repositories/snapshots</url>
</snapshotRepository>
</distributionManagement>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.5.1</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<configuration>
<archive>
<manifest>
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>me.company.application.MainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<id>copy</id>
<phase>compile</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>
${project.build.directory}/lib
</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>me.company</groupId>
<artifactId>First-Library</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<!-- more in-house libraries -->
<!-- third party libraries - Apache Commons, javamail, etc. -->
</dependencies>
</project>
Correct me if I'm wrong -- you want to transform your source code into a compiled JAR, with appropriately-set classpath for its dependencies? That's not what dependency:get is for at all. You should look into the Maven JAR plugin and/or the Maven AppAssembler plugin.
Related
I have a local jar that I need to add it as a dependency to my maven project to be included in the published jar of the project.
It is placed in the project at "my_project/lib/external1.jar" , at first I added it to dependencies as follow:
<dependency>
<groupId>installExternalJars11</groupId>
<artifactId>externalJar11</artifactId>
<version>3.1.14</version>
<systemPath>${project.basedir}//lib/external1.jar</systemPath>
<scope>system</scope>
</dependency>
It compiled successfully, but the jar content is not included in the resulting project jar, hence, when I use the project jar I get NoClassDefFoundError for these classes, although I am using the following plugins which shall package all the dependencies in the output jar
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
I found several posts recommending to use the maven install plugin to install it, then add it as a dependency, so I followed this approach as follow:
<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</groupId>
<artifactId>waheed</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>waheed</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.maven-install-plugin>2.5.2</version.maven-install-plugin>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>${version.maven-install-plugin}</version>
<configuration>
<repositoryLayout>default</repositoryLayout>
<groupId>installExternalJars</groupId>
<artifactId>externalJar1</artifactId>
<version>3.1.14</version>
<file>${project.basedir}/lib/external1.jar</file>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<executions>
<execution>
<id>install-ibm-foundation</id>
<phase>validates</phase>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>installExternalJars11</groupId>
<artifactId>externalJar11</artifactId>
<version>3.1.14</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
</project>
In eclipse I get the dependency highlighted with following error:
Missing artifact installExternalJars11:externalJar11:jar:3.1.14
and when I run maven build (from eclipse: right click pom.xml > run as > maven build) I get the following error (apparently maven is looking for the jar in my nexus repository although it is referred as local file in the install section):
Failure to find installExternalJars11:externalJar11:jar:3.1.14
in http://ur_to_nexus/nexus/content/repositories/central/ was cached in
the local repository, resolution will not be reattempted until the
update interval of ubknexus has elapsed or updates are forced
Tried the fixes proposed here https://stackoverflow.com/a/6112344/458999 but did not work
P.S : When I add the Jars to the build path in eclipse (Java build Path > Libraries > Add Jars) and run the project from eclipse (or export from eclipse and run the exported jar) it works
The system scope subtly makes Maven behave different which bites you now.
Install the artifact in your local Maven repository server (Nexus or Artifactory) or identify an equivalent artifact on Maven Central. If commercial software, ask your vendor for access to their repository.
If you cannot do that you can install locally as part of your build. See how it can be done at Multiple install:install-file in a single pom.xml. This should be considered a short term solution though.
I'm using IntelliJ IDEA's GUI designer and Maven as build system. When I build the executable JAR file via this answer, the build succeeds. However, it throws an exception when launched via the command java -jar MyApplication.jar:
Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
at javax.swing.JRootPane.setContentPane(JRootPane.java:621)
at javax.swing.JFrame.setContentPane(JFrame.java:698)
...
The affected code line is the following:
setContentPane(panel);
When ran from source in IntelliJ, it works fine however Maven doesn't seem to properly build the JAR file. After all, IntelliJ does "magic" by linking to a .form file for keeping .java source code files clean from GUI code.
I also found a possible solution which involves adding a special plugin to the pom.xml file that seems to enable build support for IntelliJ's GUI designer here. So I ran mvn clean compile assembly:single again, it didn't have any errors however nothing changed.
If I do a mvn deploy, the plugin throws the following error:
[ERROR] Failed to execute goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 (default) on project MyApplication: Execution default of goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 failed: 16257 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Here is my pom.xml:
<?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>groupId</groupId>
<artifactId>MyApplication</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- Apache Commons Lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- Jsoup HTML parser -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<!-- Apache Commons IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- Apache Commons Validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.MyApplication
</mainClass>
</manifest>
<manifestEntries>
<Built-By>BullyWiiPlaza</Built-By>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- IDEA Gui Designer Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>
What is wrong? How do I properly export an executable JAR file using Maven in combination with IntelliJ's GUI designer?
That happens because Maven doesn't really know how to compile GUI created with IntelliJ GUI Designer. That's why you have to explicitly instruct IntelliJ to generate all the code it understands and Maven doesn't.
To do this go to GUI Designer settings and change the Generate GUI into value to Java Source files. From now on IntelliJ will include all the code responsible for setting UI up in the class itself and all the external tools, like Maven, Eclipse will work properly.
I had the same problem using IntelliJ IDEA 2017.1.5 but I was able to get it working with Maven. I created a GitHub repository with the updated plugin source code here.
First, clone the project.
In the ideauidesigner-maven-plugin-master folder, run the install-intellij-libs.sh script to install the IntelliJ libraries into your local maven repository:
./install-intellij-libs.sh <path to your IntelliJ directory>
Here is also a batch file (install-intellij-libs.bat) for Windows:
SET INTELLIJ_HOME=C:\Program Files\JetBrains\IntelliJ IDEA 173.3188.16 REM Edit this to match your path!
CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%\lib\javac2.jar" -DgroupId=com.intellij -DartifactId=javac2 -Dversion=17.1.5 -Dpackaging=jar
CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%\lib\asm-all.jar" -DgroupId=com.intellij -DartifactId=asm-all -Dversion=17.1.5 -Dpackaging=jar
CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%\lib\forms_rt.jar" -DgroupId=com.intellij -DartifactId=forms_rt -Dversion=17.1.5 -Dpackaging=jar
Then install your new plugin by running the following:
mvn install
Now you're done with setting up your environment.
In your actual project, edit the plugin's version in your pom.xml to this:
<version>1.0-beta-2-17.1.5</version>
Also add the following dependencies:
<dependency>
<groupId>com.intellij</groupId>
<artifactId>javac2</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>asm-all</artifactId>
<version>LATEST</version>
</dependency>
Now building should work correctly with UI designer forms.
I had the same problem but I think I found a much easier solution:
In IntelliJ go into File -> Settings -> Editor -> GUI Designer and do the following setting:
Generate UI into: Java source code
Enable Automatically copy form runtime classes...
Add the following dependncy into yout maven pom.xml:
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>7.0.3</version>
</dependency>
Additionally add to your pom.xml an assembly plugin snippet which could look like this example:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>testUiClient</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>
my.personal.MainClass
</mainClass>
</manifest>
<manifestEntries>
<Multi-Release>true</Multi-Release>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
That should do it - it works at least for me.
Just let me know if it works also for you :-)
The answer by #jorichard may be simplifed and made CI friendly - so no local installation of any IDE is required and all configuration and dependency management is done by Maven.
The plugin org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1 has 2 dependencies on the code provided by Jetbrains via com.intellij:javac2:7.0.3 and com.intellij:forms_rt:7.0.3 (both last updated in 2008). These have not been directly updated since, but have modern equivalents hosted by Jetbrains in their own repositories.
All there is to be done is to overwrite the plugin dependencies. In this configuration (which is working for me) I updated to jetbrains libraries in version 212.5284.40, or latest at the time of writing, corresponding to Intellij IDEA 2021.2.2.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<dependencies>
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-compiler-ant-tasks</artifactId>
<version>212.5284.40</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-gui-forms-rt</artifactId>
<version>212.5284.40</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>intellij-repository</id>
<url>https://www.jetbrains.com/intellij-repository/releases</url>
</pluginRepository>
<pluginRepository>
<id>intellij-third-party</id>
<url>https://cache-redirector.jetbrains.com/intellij-dependencies</url>
</pluginRepository>
</pluginRepositories>
I'm using IntelliJ IDEA's GUI designer and Maven as build system. When I build the executable JAR file via this answer, the build succeeds. However, it throws an exception when launched via the command java -jar MyApplication.jar:
Exception in thread "main" java.awt.IllegalComponentStateException: contentPane cannot be set to null.
at javax.swing.JRootPane.setContentPane(JRootPane.java:621)
at javax.swing.JFrame.setContentPane(JFrame.java:698)
...
The affected code line is the following:
setContentPane(panel);
When ran from source in IntelliJ, it works fine however Maven doesn't seem to properly build the JAR file. After all, IntelliJ does "magic" by linking to a .form file for keeping .java source code files clean from GUI code.
I also found a possible solution which involves adding a special plugin to the pom.xml file that seems to enable build support for IntelliJ's GUI designer here. So I ran mvn clean compile assembly:single again, it didn't have any errors however nothing changed.
If I do a mvn deploy, the plugin throws the following error:
[ERROR] Failed to execute goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 (default) on project MyApplication: Execution default of goal org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1:javac2 failed: 16257 -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/PluginExecutionException
Here is my pom.xml:
<?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>groupId</groupId>
<artifactId>MyApplication</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<!-- Apache Commons Lang -->
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.6</version>
</dependency>
<!-- Jsoup HTML parser -->
<dependency>
<groupId>org.jsoup</groupId>
<artifactId>jsoup</artifactId>
<version>1.8.3</version>
</dependency>
<!-- Apache Commons IO -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.4</version>
</dependency>
<!-- Apache Commons Validator -->
<dependency>
<groupId>commons-validator</groupId>
<artifactId>commons-validator</artifactId>
<version>1.4.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.example.MyApplication
</mainClass>
</manifest>
<manifestEntries>
<Built-By>BullyWiiPlaza</Built-By>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.3</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<!-- IDEA Gui Designer Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
</project>
What is wrong? How do I properly export an executable JAR file using Maven in combination with IntelliJ's GUI designer?
That happens because Maven doesn't really know how to compile GUI created with IntelliJ GUI Designer. That's why you have to explicitly instruct IntelliJ to generate all the code it understands and Maven doesn't.
To do this go to GUI Designer settings and change the Generate GUI into value to Java Source files. From now on IntelliJ will include all the code responsible for setting UI up in the class itself and all the external tools, like Maven, Eclipse will work properly.
I had the same problem using IntelliJ IDEA 2017.1.5 but I was able to get it working with Maven. I created a GitHub repository with the updated plugin source code here.
First, clone the project.
In the ideauidesigner-maven-plugin-master folder, run the install-intellij-libs.sh script to install the IntelliJ libraries into your local maven repository:
./install-intellij-libs.sh <path to your IntelliJ directory>
Here is also a batch file (install-intellij-libs.bat) for Windows:
SET INTELLIJ_HOME=C:\Program Files\JetBrains\IntelliJ IDEA 173.3188.16 REM Edit this to match your path!
CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%\lib\javac2.jar" -DgroupId=com.intellij -DartifactId=javac2 -Dversion=17.1.5 -Dpackaging=jar
CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%\lib\asm-all.jar" -DgroupId=com.intellij -DartifactId=asm-all -Dversion=17.1.5 -Dpackaging=jar
CALL mvn install:install-file -Dfile="%INTELLIJ_HOME%\lib\forms_rt.jar" -DgroupId=com.intellij -DartifactId=forms_rt -Dversion=17.1.5 -Dpackaging=jar
Then install your new plugin by running the following:
mvn install
Now you're done with setting up your environment.
In your actual project, edit the plugin's version in your pom.xml to this:
<version>1.0-beta-2-17.1.5</version>
Also add the following dependencies:
<dependency>
<groupId>com.intellij</groupId>
<artifactId>javac2</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>LATEST</version>
</dependency>
<dependency>
<groupId>com.intellij</groupId>
<artifactId>asm-all</artifactId>
<version>LATEST</version>
</dependency>
Now building should work correctly with UI designer forms.
I had the same problem but I think I found a much easier solution:
In IntelliJ go into File -> Settings -> Editor -> GUI Designer and do the following setting:
Generate UI into: Java source code
Enable Automatically copy form runtime classes...
Add the following dependncy into yout maven pom.xml:
<dependency>
<groupId>com.intellij</groupId>
<artifactId>forms_rt</artifactId>
<version>7.0.3</version>
</dependency>
Additionally add to your pom.xml an assembly plugin snippet which could look like this example:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
<configuration>
<finalName>testUiClient</finalName>
<appendAssemblyId>false</appendAssemblyId>
<archive>
<manifest>
<mainClass>
my.personal.MainClass
</mainClass>
</manifest>
<manifestEntries>
<Multi-Release>true</Multi-Release>
<Class-Path>.</Class-Path>
</manifestEntries>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
That should do it - it works at least for me.
Just let me know if it works also for you :-)
The answer by #jorichard may be simplifed and made CI friendly - so no local installation of any IDE is required and all configuration and dependency management is done by Maven.
The plugin org.codehaus.mojo:ideauidesigner-maven-plugin:1.0-beta-1 has 2 dependencies on the code provided by Jetbrains via com.intellij:javac2:7.0.3 and com.intellij:forms_rt:7.0.3 (both last updated in 2008). These have not been directly updated since, but have modern equivalents hosted by Jetbrains in their own repositories.
All there is to be done is to overwrite the plugin dependencies. In this configuration (which is working for me) I updated to jetbrains libraries in version 212.5284.40, or latest at the time of writing, corresponding to Intellij IDEA 2021.2.2.
<build>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>ideauidesigner-maven-plugin</artifactId>
<version>1.0-beta-1</version>
<dependencies>
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-compiler-ant-tasks</artifactId>
<version>212.5284.40</version>
</dependency>
<dependency>
<groupId>com.jetbrains.intellij.java</groupId>
<artifactId>java-gui-forms-rt</artifactId>
<version>212.5284.40</version>
</dependency>
</dependencies>
<executions>
<execution>
<goals>
<goal>javac2</goal>
</goals>
</execution>
</executions>
<configuration>
<fork>true</fork>
<debug>true</debug>
<failOnError>true</failOnError>
</configuration>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>intellij-repository</id>
<url>https://www.jetbrains.com/intellij-repository/releases</url>
</pluginRepository>
<pluginRepository>
<id>intellij-third-party</id>
<url>https://cache-redirector.jetbrains.com/intellij-dependencies</url>
</pluginRepository>
</pluginRepositories>
I'm currently working with a Legacy app, whose process for building plugins requires adding dependencies on about 150 non-maven (ant I believe?) jar files. Ideally, I'd like to package these 150-jars into a single JAR, place it on Artifactory, and use that as a maven-dependency so that my team can more easily setup their development environment.
I've been experimenting with one-jar, maven-assembly-plugin, and maven-shade-plugin, which appears to just create one jar that contains several other jars (i.e. unzip the contents). However when adding that jar as a maven dependency, maven appears unable to resolve the contents/dependencies within these "sub-jars."
The code below is only an example of something I've tried; so feel free to suggest other approaches.
<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.company</groupId>
<artifactId>some-jars</artifactId>
<packaging>jar</packaging>
<version>1.0.0</version>
<name>someName</name>
<properties>
<jdk.version>1.8</jdk.version>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>com.mycompany.mypackage.MyMainClass</mainClass>
</manifest>
</archive>
</configuration>
</plugin>
<plugin>
<groupId>org.dstovall</groupId>
<artifactId>onejar-maven-plugin</artifactId>
<version>1.4.4</version>
<executions>
<execution>
<configuration>
<binlibs>
<fileSet>
<directory>${basedir}/jars</directory>
<includes>
<include>*</include>
</includes>
</fileSet>
</binlibs>
<!-- Optional, default is false -->
<attachToBuild>true</attachToBuild>
<!-- Optional, default is "onejar" -->
<classifier>onejar</classifier>
</configuration>
<goals>
<goal>one-jar</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<pluginRepositories>
<pluginRepository>
<id>onejar-maven-plugin.googlecode.com</id>
<url>http://onejar-maven-plugin.googlecode.com/svn/mavenrepo</url>
</pluginRepository>
</pluginRepositories>
</project>
Perhaps you may want to consider the BOM approach adopted by Spring IO Platform (http://platform.spring.io/platform/#quick-start), JBoss Java EE 6 spec dependency in Maven (http://www.andygibson.net/blog/quickbyte/jboss-java-ee-6-spec-dependency-in-maven/)
By using BOM approach, there is no need to bundle all the libraries to one single jar.
I had the same problem a while ago
For this reason i implemented maven-bulk-deploy that make easier to implement the BOM approach
Just you have put your jars in one folder choose a common-group-id/version (eg. the same of your main project) run the plugin and it will create a BOM file (ie pom ) and will deploy all jars in your asset repo
Feel free to checkout/fork the project to try it for solve your issue
There's a precompiled jar file. My sources depend on it. I need:
This file should be added to classpath
When I do mvn deploy without parameters, the file should be uploaded to remote repo
When others use my project as a dependency, the file should be automatically downloaded from the remote repo and added to classpath
I want this jar to have its own artifact id and pom file
If possible, I'd like to keep the original jar name
I tried to put this in my pom:
<repositories>
<repository>
<id>pom-local</id>
<url>file://${basedir}/repo</url>
</repository>
</repositories>
Then wrote another pom.xml and put it and the jar file to ${basedir}/repo/.
Strangely, according to google, nobody uses this. I didn't figure out how to keep the original jar name. And I can't make maven deploy it.
There's attach-artifact goal, but it requires a file name, not artifactId as the parameter and it puts the jar to the same folder.
Possible solution:
<dependency>
<groupId>org.foo</groupId>
<version>1.0</version>
<artifactId>eeerrr</artifactId>
</dependency>
</dependencies>
<repositories>
<repository>
<id>pom-local</id>
<url>file://${basedir}/repo</url>
</repository>
</repositories>
<properties>
<!-- Will use this instead of <distributionManagement>, because it's easier to extract url from one place -->
<altDeploymentRepository>todo::default::http://0.0.0.0</altDeploymentRepository>
</properties>
<build>
<plugins>
<!-- Extract url -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>extract-url</id>
<phase>verify</phase>
<goals>
<goal>regex-property</goal>
</goals>
<configuration>
<name>deploymentRepository.url</name>
<value>${altDeploymentRepository}</value>
<regex>.*::(.*)</regex>
<replacement>$1</replacement>
<failIfNoMatch>true</failIfNoMatch>
</configuration>
</execution>
</executions>
</plugin>
<!-- Upload additional artifact -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-deploy-plugin</artifactId>
<executions>
<execution>
<id>deploy-3rd-party-jar</id>
<phase>deploy</phase>
<goals>
<goal>deploy-file</goal>
</goals>
<configuration>
<groupId>org.foo</groupId>
<artifactId>eeerrr</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<file>${basedir}/repo/org/foo/eeerrr/1.0/eeerrr-1.0.jar</file>
<url>${deploymentRepository.url}</url>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Assuming that this precompiled jar doesnt change that often.
You can just do a one time deploy to your local cached repo and remote repo using mvn install:install-file and mvn deploy:deploy-file.
Have a look at How to deploy jars to nexus with cmd, this is a similar question.