I have multiple modules in a single project. I have packaged a module as jar and included it as a dependency in another module. I want this jar to be generated and installed in a specific folder.
Dependency of module A included in B
Specifying the folder to copy the jar
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>package</phase>
<configuration>
<includeArtifactIds>
<artifactId>rpgenerator</artifactId>
</includeArtifactIds>
<includeGroupIds>
<groupId>a.b.c</groupId>
</includeGroupIds>
<outputDirectory>${project.basedir}/reports/</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
But I do not see the jar in the folder B.reports.
Any help would be appreciated.
Related
I want to add JARs to a plugin. Previously, I added them by hand but thought it would be a good idea to add them via dependency definitions.
I created a pom.xml in the bundle and added an execution:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>3.4.0</version>
<executions>
<execution>
<id>copy-dependencies</id>
<phase>process-sources</phase>
<goals>
<goal>copy-dependencies</goal>
</goals>
<configuration>
<outputDirectory>${project.basedir}/lib</outputDirectory>
<overWriteIfNewer>true</overWriteIfNewer>
</configuration>
</execution>
</executions>
</plugin>
As soon as I save the file the dependency JARs are all copied to the lib folder. So far so good...
When I start a tycho build, such as mvn install, the build succeeds but the lib folder now contains a new folder lib/myplugin-1.0.0.qualifier-lib and this folder contains copies of all the JARs in lib but they all have the extension .jar.jar.
If I remove the copy-dependencies execution before starting the tycho build then this folder is not created.
Can anyone explain why this is happening and what I should do to avoid this behaviour?
I have Spring boot project. Everything is built OK in /target folder but I'd like to change destination folder.
I tried to use maven-jar-plugin as described below but it copies only jar with compiled classes of project (small jar).
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<outputDirectory>${maven.multiModuleProjectDirectory}/output/bin</outputDirectory>
</configuration>
</plugin>
Instead I want to make Maven to copy FAT jar.
Maven builds FAT jar and puts the Jar to /target folder. How to change destination?
UPDATE 1
this is needed by project requirements - need to build folder structure with properties, bash scripts(as entry point) and fat jar:
Try to add this plugin:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>jar-with-dependencies</shadedClassifierName>
<outputDirectory>${maven.multiModuleProjectDirectory}/output/bin</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
I am working in Java maven environment, in my application I am generating some java classes using a SomeFileName.wsdl file. For this I have added maven plugin to pom.xml, following are the plugins,
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<executions>
<execution>
<id>add-source</id>
<phase>generate-sources</phase>
<goals>
<goal>add-source</goal>
</goals>
<configuration>
<sources>
<source>${project.build.directory}/generated-sources/folder-name</source>
</sources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>some-id</id>
<phase>generate-sources</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>src/main/webapp/WEB-INF/wsdl</folder-name>
<wsdlFiles>
<wsdlFile>SomeFileName.wsdl</wsdlFile>
</wsdlFiles>
<wsdlLocation>/WEB-INF/wsdl/*</wsdlLocation>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
My question around this is, whenever this plugin generates java classes under target/generated-sources/folder-name, is there any maven plugin or maven goal or some other way available so that I can bundle this classes into a jar and can be able to add that jar to my class-path(build-path). So that, I can be able to access those generated classes from newly generated jar.
In simple words, currently using wsdl plugin classes are getting generated into target folder where I have specified my location. I just want to bundle those generated classes into a jar and add that jar to a buildpath, is there anyway to achieve this?
I have used jax-ws in some maven projects, and the class files from the generated stubs will simply be generated in the target folder, just like other class files. The generated sources config only affects the generated sources. The .class files will end up in your package structure. My suggestion is to add the packageName config, so your generated classes will be in a more convenient package. Once you build your project and the wsdl is imported successfully, you should see your .class files in the targer folder. After that, the jar packaging will go as any other project. Here is an example configuration (very similar to yours):
<plugin>
<groupId>org.jvnet.jax-ws-commons</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<version>1.12</version>
<executions>
<execution>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<packageName>com.your.package</packageName>
<sourceDestDir>target/generated-sources/jaxws</sourceDestDir>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
I have a web application with spring and maven. The application is divided into maven modules. I have an "application-web" module that generates war. Another "application-ear" module that generates an ear. And another "application-static" with css, js and images that generates a zip file.
This would be the outline of my application:
application
application-web (java code)
application-ear
application-static (css, js and images)
application-resources (language properties)
I want to deploy the eclipse use files of "static" module, instead of using the files in the "application/src/main/webapp" directory. How can I do this? It is possible?
Don't waste your time with unpacking resources, everything works out of the box:
Resource bundles: the are always loaded from the classpath, regardlessly it is exploded (WEB-INF/classes) or compressed (WEB-INF/lib)
Serving static resources: bundle them up in a JAR and use either Tomcat (Servlet 3.0) feature to serve from META-INF/resources, see here or use Spring's built in mvc:resources element.
Simply add the dependency snippets in your WAR POM and your are done.
You can use the maven dependency plugin to unpack your static resources included in the zip file using the following:
In your application-web.pom
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-resources</id>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<phase>generate-sources</phase>
<configuration>
<outputDirectory>resources</outputDirectory>
<includeArtifactIds>application-static</includeArtifactIds>
<includeGroupIds>your group id</includeGroupIds>
<includes>**/*.js,**/*.css</includes>
</configuration>
</execution>
</executions>
</plugin
This work:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>2.10</version>
<executions>
<execution>
<id>unpack-dependencies</id>
<phase>package</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<excludeTypes>pom</excludeTypes>
<includeArtifactIds>application-static</includeArtifactIds>
<includeGroupIds>com.foo.foo.application</includeGroupIds>
<outputDirectory>src/main/webapp</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<finalName>${project.artifactId}-${project.version}</finalName>
</build>
But I have another problem, with this solution only copy the static files when I execute clean package. If I run the application-web with eclipse and I do changes in a js file in application-static, the changes have no effect until I execute clean package. Any solution for this?
I have been trying to create a test-jar from a war project using the maven-jar-plugin. I have custom src folder which I want as a jar. The plugin does not compile the files in the folder and creates a jar with .java files. How do I compile the java files before they are packaged in a jar as .class files ?
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>2.4</version>
<executions>
<execution>
<goals>
<goal>test-jar</goal>
</goals>
</execution>
</executions>
<configuration>
<testClassesDirectory>${project.basedir}/src/test/selenium</testClassesDirectory>
</configuration>
</plugin>
Did you try using maven-compiler-plugin