SpringBoot does not find my dependency in BOOT-INF/lib/ folder - java

I can run a springBoot APP using the IDE or mvn spring-boot:run perfectly, but I cannot when I do:
java -jar myapp-0.1.jar
PS.: I'm Embedding myproject-0.1 into digitalizacao-sender-0.0.1.jar
Cause I got an error saying
Caused by: java.lang.IllegalArgumentException: File [/home/myuser/workspace/digitalizacao-sender/target/digitalizacao-sender-0.0.1.jar!/BOOT-INF/lib/myproject-0.1.jar] referenced by given URL [file:/home/myuser/workspace/digitalizacao-sender/target/digitalizacao-sender-0.0.1.jar!/BOOT-INF/lib/myproject-0.1.jar] does not exist
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:73) ~[myproject-0.1.jar!/:na]
at org.hibernate.jpa.boot.archive.internal.StandardArchiveDescriptorFactory.buildArchiveDescriptor(StandardArchiveDescriptorFactory.java:48) ~[myproject-0.1.jar!/:na]
at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.buildArchiveDescriptor(AbstractScannerImpl.java:95) ~[myproject-0.1.jar!/:na]
at org.hibernate.jpa.boot.scan.spi.AbstractScannerImpl.scan(AbstractScannerImpl.java:70) ~[myproject-0.1.jar!/:na]
... 20 common frames omitted . But I can see my dependency (another jar project) inside `BOOT-INF/lib/`
Follow a piece of my pom.xml:
<project>
...
<artifactId>digitalizacao-sender</artifactId>
...
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
<version>1.5.9.RELEASE</version>
</dependency>
<dependency>
<groupId>com.my.organization</groupId>
<artifactId>myproject</artifactId> <--- my dependency
<version>1.0</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Anyone have an idea, why I cannot run java -jar.

Related

Java giving NoClassDefFoundError when importing maven package

I have a simple java code, App.java. I am trying to import the apache commons Fraction class from the apache commons math3 library. So, as a sample code, I put this in my App.java:
package myApp;
import org.apache.commons.math3.fraction.Fraction;
public class App
{
public static void main( String[] args )
{
Fraction f = new Fraction(2, 3);
System.out.println( "Hello World!" );
System.out.println( f );
}
}
Using the following POM:
<?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>myApp</groupId>
<artifactId>Proj1</artifactId>
<version>1.0-SNAPSHOT</version>
<name>Proj1</name>
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-math3</artifactId>
<version>3.6.1</version>
</dependency>
</dependencies>
<build>
<pluginManagement><!-- lock down plugins versions to avoid using Maven defaults (may be moved to parent pom) -->
<plugins>
<!-- clean lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#clean_Lifecycle -->
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.1.0</version>
</plugin>
<!-- default lifecycle, jar packaging: see https://maven.apache.org/ref/current/maven-core/default-bindings.html#Plugin_bindings_for_jar_packaging -->
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.22.1</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
</plugin>
<plugin>
<artifactId>maven-deploy-plugin</artifactId>
<version>2.8.2</version>
</plugin>
<!-- site lifecycle, see https://maven.apache.org/ref/current/maven-core/lifecycles.html#site_Lifecycle -->
<plugin>
<artifactId>maven-site-plugin</artifactId>
<version>3.7.1</version>
</plugin>
<plugin>
<artifactId>maven-project-info-reports-plugin</artifactId>
<version>3.0.0</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>3.2.4</version>
<configuration>
<!-- put your configurations here -->
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
I have tried to put the plugin suggested by utdemir in his answer to a similar question, but in my case, when I run:
mvn package
java -cp target/Proj1-1.0-SNAPSHOT.jar myApp.App
While it apparently compiles properly, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/math3/fraction/Fraction
at myApp.App.main(App.java:8)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.math3.fraction.Fraction
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:636)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:182)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:519)
... 1 more
What should I do?
Its much easier to run your app using mvn, rathen than by calling java directly. This is because in the later case you need to manually set the classpath to the correct value using the -cp flag. This can lead to errors, like in your case.
Here's how you can run your app using mvn
mvn exec:java -Dexec.mainClass="myApp.App"
More details can be found here

Maven Wrapper Lifecycle failing

I am getting below error when I try to do a maven build using terminal from Intellij.
Just not sure what is to be done or what is the issue. The same configuration worked for earlier springboot projects.
ERROR MESSAGE:
D:\springboot\api\streetapiservice>mvnw clean install
The system cannot find the path specified.
'B' is not recognized as an internal or external command,
operable program or batch file.
The directory name is invalid.
Exception calling "DownloadFile" with "2" argument(s): "An exception occurred during a WebClient request."
At line:1 char:282
+ ... pe]::Tls12; $webclient.DownloadFile('https://repo.maven.apache.org/ma ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (:) [], MethodInvocationException
+ FullyQualifiedErrorId : WebException
Error: Could not find or load main class org.apache.maven.wrapper.MavenWrapperMain
POM File
Below is the pom file -- I have removed some dependencies. This was created using spring starter.
<?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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.5.2</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.api</groupId>
<artifactId>streetapiservice</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>streetapiservice</name>
<description>Api for handling calls street api</description>
<properties>
<java.version>1.8</java.version>
<sonar-maven-plugin.version>3.7.0.1746</sonar-maven-plugin.version>
<mock-sever-netty-version>3.10.8</mock-sever-netty-version>
<apache-http-version>4.4.1</apache-http-version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<includeSystemScope>true</includeSystemScope>
</configuration>
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<dependencies>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>1.0.1</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.7.9</version>
<executions>
<execution>
<id>default-prepare-agent</id>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>default-report</id>
<phase>prepare-package</phase>
<goals>
<goal>report</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
when i tried to run the same code via git bash, it ran fine.
issue looks to be with the IDE
reimporting the project fixed the issue

How to run my maven project (angular+springboot) on tomcat?

I have created a web application based on angular 8 and spring boot. I implemented the codebase locally and it is working fine.
My Angular code(client) is running on localhost:4200 and spring boot(server) is running on localhost:8080.
Till here everything is working as expected.
Now I want to deploy this whole web application as a single bundle so that I can deploy it as a single war on tomcat.
I am creating the war file using maven.
But when I deploy this war file on tomcat and start the tomcat I am not able to see the expected login page on the browser.
Basically, I don't have much understanding of maven and was following resource available in below link on the internet to generate the war file.
https://dzone.com/articles/building-a-web-app-using-spring-boot-angular-6-and
So I am not able to figure out whether the issue is with my build or the URL through which I am trying to access the resources.
if I deploy only the UI build, then if I hit localhost:8080, I am able to see the login page.
I am having three pom files as mentioned in the tutorial.
1. parent-pom
2. server-pom
3. ui-pom
Below are my pom files
parent-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>com.dzs.licenseGenerator</groupId>
<artifactId>lg-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.6.RELEASE</version>
<relativePath />
</parent>
<modules>
<module>LicenseGenerator_Backend</module>
<module>LicenseGenerator_UI</module>
</modules>
</project>
server-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>
<parent>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>lg-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- lookup parent from repository -->
</parent>
<artifactId>LicenseGenerator_Backend</artifactId>
<packaging>war</packaging>
<properties>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>LicenseGenerator_UI</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals><goal>copy-resources</goal></goals>
<configuration>
<tasks>
<echo>Displaying value of pom.xml element</echo>
<echo>[project.build.directory] ${project.build.directory}</echo>
<echo>[project.parent.basedir] ${project.parent.basedir}</echo>
</tasks>
<outputDirectory>${project.build.directory}/classes/resources/</outputDirectory >
<resources>
<resource>
<directory>${project.parent.basedir}/LicenseGenerator_UI/dist/lg-app/</directory >
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<packagingExcludes>WEB-INF/lib/tomcat-*.jar</packagingExcludes>
<warName>lg-app</warName>
</configuration>
</plugin>
</plugins>
</build>
</project>
UI-pom.xml
<?xml version="1.0"?>
<project
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>com.dzs.licenseGenerator</groupId>
<artifactId>lg-parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<artifactId>LicenseGenerator_UI</artifactId>
<name>LicenseGenerator_UI</name>
<url>http://maven.apache.org</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.4</version>
<configuration>
<nodeVersion>v10.16.0</nodeVersion>
<npmVersion>6.9.0</npmVersion>
<workingDirectory>src/main/web/</workingDirectory>
</configuration>
<executions>
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
</execution>
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
</execution>
<execution>
<id>npm run build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
<execution>
<id>prod</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run-script build</arguments>
</configuration>
<phase>generate-resources</phase>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Just to ensure whether my code structure is correct or not I am posting a screenshot of my Project Explorer in Eclipse.
Use ng build –prod command for generating production build artifacts.
Run this command in your UI project folder.
Post generation of production build you should see new folder named ‘dist’.
You have to use Maven resource plugin to package as single jar. As i can see you already have the plugin in you pom, just verify the directory folder to pint to dist folder.
After this just run maven clean install . After running this you should see jar with both Angular 6 & Spring Boot application on the target folder.
Execute with Java –jar command to launch the application, you should see the Angular application served from static folder.
You can use frontend-maven-plugin for kicking off your frontend build. Once the frontend build is completed, it will generate the resource files in dist directory.
After that you can use the maven-resources-plugin to copy the files from dist to the required location in the target directory.

Running maven project in cmd

I'm have to run maven project in cmd. This is my pom.xml file:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>
<name>my-app</name>
<!-- FIXME change it to the project's website -->
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<maven.compiler.release>11</maven.compiler.release>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.16</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.4.2.Final</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
</plugin>
</plugins>
</pluginManagement>
</build>
The project is running perfectly fine in IDE (Eclipse), but when I try to run it run it from command line I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/hibernate/cfg/Configuration
at com.mycompany.app.App.main(App.java:15)
Caused by: java.lang.ClassNotFoundException: org.hibernate.cfg.Configuration
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:583)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:178)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:521)
... 1 more
The problem in your case is that you dont have the dependencies in the classpath. You can use a maven pluging to obtain such.
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<archive>
<manifest>
<mainClass>fully.qualified.MainClass</mainClass>
</manifest>
</archive>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id> <!-- this is used for inheritance merges -->
<phase>package</phase> <!-- bind to the packaging phase -->
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Source How can I create an executable JAR with dependencies using Maven?
It really depends on how you setup your project, but what your stack trace is saying literally that JVM could not locate mentioned class. Now, you can imagine (this is just only one of many possible issues) - you have your code referencing 'Configuration' class somewhere, but when the project runs from a command line - JVM can not find it.
I would recommend taking a look at this topic to understand received error. Many thoughts were given and it was explained well.
Essentially once you get all your dependencies in place, that error will goaway and if you're using TestNG or JUnit, you won't need a main class. You will run your tests with just mvn clean test Or even shorter mvn if you add <defaultGoal>clean test</defaultGoal> to POM.

Maven - deploy:deploy-file over series of files within ${project.build.directory} (target/)

Quick briefing on my situation - I'm working on a code base that has JAX-WS annotated interfaces/classes that we generate code-first wsdls from. We are using CXF's cxf-java2ws-plugin to generate wsdls at build time within maven for inclusion within the .jar produced for each module.
What we'd like to do is deploy these wsdl files to a maven repository since the maven repository can act as
a makeshift service repository (such as described here)
give clients an easy way to use the cxf codegen plugin by pointing to the maven coordinates for a wsdl instead of managing the wsdl files themselves
What I've got so far is a pom file that uses dependency:unpack-dependencies to get all of the wsdl files in the project in to one directory within this modules ${project.build.directory} (commonly known as target/ to everyone out there).
What I don't know how to do is to loop through each of these files and invoke deploy:deploy-file mojo on each wsdl. What are my options here since I really want to automate the process of deploying these wsdl files and not have anyone ever deploy them manually?
For completeness sake, here is the pom file:
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>rice</artifactId>
<groupId>org.kuali.rice</groupId>
<version>2.0.0-m7-SNAPSHOT</version>
</parent>
<artifactId>rice-dist-wsdl</artifactId>
<name>Rice WSDL Distributions</name>
<packaging>pom</packaging>
<properties>
<wsdl.location>${project.build.directory}/wsdl</wsdl.location>
</properties>
<!-- Depends on all API modules and modules that generate or contain wsdls -->
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-core-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-kew-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-kim-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-krms-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-ksb-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-shareddata-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-wsdls</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includes>**\/*.wsdl</includes>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Which shoves the wsdls in target/wsdl (they are contained within wsdl/ inside each .jar being depended upon):
[whaley#sunspot ~/Repositories/Kuali/rice/dist-wsdl]
> find . -iname '*.wsdl' | head -3
./target/wsdl/CampusService.wsdl
./target/wsdl/CountryService.wsdl
./target/wsdl/CountyService.wsdl
Solution
Thought what I implemented was different than the accepted answer provided by Ryan Steward, I accepted his answer since it led me to write my own.
Basically, here is a maven pom that's a submodule in the multi-module project described above. I'm using dependency:unpack-dependencies and then using an in-line groovy script to call deploy:deploy-file on each of those wsdl files. It's a bit of a hackjob, but I couldn't think of a better way to do this without hardcoding paths to the wsdl files in the module and calling several executions of the deploy:deploy-file mojo on them, leading to a very verbose pom.
<?xml version="1.0"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>rice</artifactId>
<groupId>org.kuali.rice</groupId>
<version>2.0.0-m7-SNAPSHOT</version>
</parent>
<artifactId>rice-dist-wsdl</artifactId>
<name>Rice WSDL Distributions</name>
<packaging>pom</packaging>
<properties>
<wsdl.location>${project.build.directory}/wsdl</wsdl.location>
</properties>
<!-- Depends on all API modules and modules that generate or contain wsdls -->
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-core-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-kew-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-kim-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-krms-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-ksb-api</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>rice-shareddata-api</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>unpack-wsdls</id>
<phase>generate-resources</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includes>**\/*.wsdl</includes>
<outputDirectory>${project.build.directory}</outputDirectory>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<executions>
<execution>
<phase>deploy</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def repo_url
def repo_id
if ("${project.version}".endsWith("SNAPSHOT")) {
repo_url = "${kuali.repository.snapshot.url}"
repo_id = "${kuali.repository.snapshot.id}"
} else {
repo_url = "${kuali.repository.release.url}"
repo_id = "${kuali.repository.release.id}"
}
def wsdlGroupId = "${project.groupId}.wsdl"
new File("${wsdl.location}").eachFile() { file ->
serviceName = file.name.split("\\.")[0]
log.info("Deploying ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}")
execString = "mvn deploy:deploy-file -Dfile=${file} -Durl=${repo_url} -DrepositoryId=${repo_id} "
execString += "-DgroupId=${wsdlGroupId} -DartifactId=${serviceName} "
execString += "-Dversion=${project.version} -Dpackaging=wsdl -Dclassifier=wsdl"
def proc = execString.execute()
proc.waitFor()
err = proc.err.text
if (err != null && err.length() > 0) {
log.error(err)
fail("Deployment failed for ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}. \n Run in verbose mode for full error.")
} else {
log.info("Successfully deployed ${wsdlGroupId}:${serviceName}:wsdl:${project.version} to ${repo_id}")
}
}
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Another possibility: the Maven Ant tasks can deploy files. I've never used it, but I'll bet you could use an antrun configuration and some ant pattern matching to pick up and deploy all the WSDLs.
The Build Helper plugin might help you out. You can make it publish the WSDLs, but you'll have to list each one out explicitly, and they'll all have the artifactId of your pom in their names. Only the classifier can change. For example:
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>build-helper-maven-plugin</artifactId>
<version>1.7</version>
<executions>
<execution>
<id>attach-WSDLs</id>
<phase>package</phase>
<goals>
<goal>attach-artifact</goal>
</goals>
<configuration>
<artifacts>
<artifact>
<file>${project.build.directory}/foo.wsdl</file>
<classifier>foo</classifier>
<type>wsdl</type>
</artifact>
<artifact>
<file>${project.build.directory}/bar.wsdl</file>
<classifier>bar</classifier>
<type>wsdl</type>
</artifact>
</artifacts>
</configuration>
</execution>
</executions>
</plugin>
If your pom's coordinate is myGroupId:myArtifactId:1.1.1, then the artifacts installed and deployed using this config would be named myArtifactId-1.1.1-foo.wsdl and myArtifactId-1.1.1-bar.wsdl. That's the best I know of.

Categories

Resources