In my GoogleAppEngine project I currently installed a lot of node-modules that are now placed in my project at the location src/main/webapp/node_modules. Now when I try to test that project locally with the appengine-maven-plugin (mvn appengine:run), it takes up to 10 Minutes to create that project. I figured out, that it takes so much time to copy all files from the node_modules folder to the target folder.
Since I only need these files for developing, I tried to skip this folder when building the project. But I'm not that sure where to configure that behavior. In my appengine-web.xml I already excludes that folder from static-files and resource-files:
<static-files>
<include path="/build/build/favicon.ico" />
<include path="/build/build/node_modules/**" />
<include path="/build/build/images/**" />
<include path="/build/build/src/**" />
<include path="/build/build/robots.txt" />
<include path="/build/build/sitemap.xml" />
<exclude path="/node_modules/**/*" />
</static-files>
<resource-files>
<include path="/build/build/index.html" />
<exclude path="/node_modules/**/*" />
</resource-files>
Where may I exclude that folder from beeing copied to target/backend-1.0-snapshot?
I'm using the appengine standard environment (1.9.63) with the appengine-maven-plugin (1.3.2)
Here is my pom.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<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>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<groupId>com.xxx.xxx</groupId>
<artifactId>backend</artifactId>
<properties>
<endpoints.framework.version>2.0.14</endpoints.framework.version>
<endpoints.management.version>1.0.4</endpoints.management.version>
<endpoints.project.id>XXX PROJECT XXX</endpoints.project.id>
<appengine.maven.plugin.version>1.3.2</appengine.maven.plugin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<maven.compiler.showDeprecation>true</maven.compiler.showDeprecation>
</properties>
<prerequisites>
<maven>3.5.0</maven>
</prerequisites>
<dependencies>
<!-- Compile/runtime dependencies -->
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-framework</artifactId>
<version>${endpoints.framework.version}</version>
</dependency>
<dependency>
<groupId>com.google.endpoints</groupId>
<artifactId>endpoints-management-control-appengine-all</artifactId>
<version>1.0.7</version>
</dependency>
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>javax.servlet-api</artifactId>
<version>3.1.0</version>
<type>jar</type>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>javax.inject</groupId>
<artifactId>javax.inject</artifactId>
<version>1</version>
</dependency>
<dependency>
<groupId>com.google.appengine</groupId>
<artifactId>appengine-api-1.0-sdk</artifactId>
<version>1.9.63</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>
<build>
<!-- for hot reload of the web application -->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>appengine-maven-plugin</artifactId>
<version>${appengine.maven.plugin.version}</version>
<configuration>
<deploy.project>XXX PROJECT XXX</deploy.project>
<deploy.version>XXX VERSION XXX</deploy.version>
<deploy.stopPreviousVersion>false</deploy.stopPreviousVersion>
<deploy.promote>false</deploy.promote>
</configuration>
</plugin>
<plugin>
<groupId>com.google.cloud.tools</groupId>
<artifactId>endpoints-framework-maven-plugin</artifactId>
<version>1.0.3</version>
<configuration>
<!-- plugin configuration -->
<hostname>${endpoints.project.id}.appspot.com</hostname>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>versions-maven-plugin</artifactId>
<version>2.5</version>
<executions>
<execution>
<phase>compile</phase>
<goals>
<goal>display-dependency-updates</goal>
<goal>display-plugin-updates</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
I just found out that I have to add the maven-war-plugin with the warSourceExcludes-configuration to the build part of the pom.xml.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<warSourceExcludes>node_modules/**</warSourceExcludes>
</configuration>
</plugin>
That way the folder won't be copied to the exploded war folder.
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.0</version>
<configuration>
<packagingExcludes>assets/node_modules/**</packagingExcludes>
</configuration>
</plugin>
Where assets is a folder inside of src/main/webapp directory. When you run mvn install , it will create a war and source directory in your target folder. Although node_modules will be visible in source directory inside of target but when you extract war file, these will be excluded. You can see this by extracting war file.
Related
I'm trying to auto generate the jOOQ java code for my MySql database, but it's not working. I'm using jOOQ for my JSP project from maven.
pom.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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>MyHomeProject</groupId>
<artifactId>MyHomeProject</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>13</release>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.3</version>
<configuration>
<warSourceDirectory>WebContent</warSourceDirectory>
</configuration>
</plugin>
<plugin>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen-maven</artifactId>
<executions>
<execution>
<id>generate-mysql</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<jdbc>
<driver>com.mysql.jdbc.Driver</driver>
<url>jdbc:mysql://localhost:3306/myprojectdb?useSSL=false&serverTimezone=UTC</url>
<user>webuser</user>
<password>webuserP#$$*oR6</password>
</jdbc>
<generator>
<database>
<name>org.jooq.meta.mysql.MySQLDatabase</name>
<includes>.*</includes>
<excludes></excludes>
<inputSchema>public</inputSchema>
</database>
<target>
<packageName>com.myproject.home.jooq</packageName>
<directory>${basedir}\src</directory>
</target>
</generator>
</configuration>
</execution>
</executions>
<dependencies>
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<dependencies>
<!-- MySQL -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>8.0.13</version>
</dependency>
<!-- jOOQ -->
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq</artifactId>
<version>3.13.2</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-meta</artifactId>
<version>3.13.2</version>
</dependency>
<dependency>
<groupId>org.jooq</groupId>
<artifactId>jooq-codegen</artifactId>
<version>3.13.2</version>
</dependency>
<!-- Other dependencies here -->
<!-- ... -->
<!-- ... -->
<!-- ... -->
</dependencies>
</project>
I'm running this project on eclipse with Tomcat. When I want to run the web application, I clean the project, then Project>properties>Deployment Assembly>Add>Java Build Path Entries>Maven Dependencies.
When I run the project, no java code for database is generated.
As it says in the documentation, since I'm using maven with jOOQ, I can auto generate the JAVA code without need to use cli. And without the need to create a library.xml file.
My issue is that jOOQ doesn't auto generate JAVA files with this pom.xml file. What am I doing wrong? Is there another configurations I need to make?
You specified:
<inputSchema>public</inputSchema>
MySQL doesn't have such a schema by default. Please use the schema of your actual database instead (case sensitive), or omit the inputSchema to generate code for all schemas.
Let me just start off by saying, I am new to Maven / Spring and am having a hard time figuring out what to do when my directory does not follow the preferred Maven structure.
I followed instructions for setting up a project with Angular 2 and Spring Boot via this tutorial. This tutorial creates two modules, frontend and backend, with corresponding pom.xml's and one parent pom.xml. I can run the application just fine using my IDE, IntelliJ, or by running "mvn spring-boot:run" from the backend directory. However, for deployment, I wish to package the application into a WAR file to drop into a Tomcat server. I am unsure how to do this using the pom.xml's that I currently have. I am quite sure that it has to do with my directory structure, however I am not sure if I should restructure my application or of there is a way to configure Maven to place the two modules into resulting WAR file that works as intended.
I have found a similar answer here but the last part is what throws me off. I do not have a /src/main/webapp/WEB-INF folder and am unsure where to make it.
My application structure is as follows:
AppRoot
-backend
--src
---main
----java
--pom.xml
-frontend
--src
---main
----frontend
--pom.xml
-pom.xml
My root pom.xml is:
<groupId>com.trinityinnovations</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>pom</packaging>
<name>c-cop</name>
<description>C-COP Project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.2.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<modules>
<module>frontend</module>
<module>backend</module>
<module>web</module>
Frontend pom.xml:
<artifactId>frontend</artifactId>
<name>frontend</name>
<description>C-COP Project frontend</description>
<parent>
<groupId>com.trinityinnovations</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<build>
<plugins>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.3</version>
<configuration>
<nodeVersion>v6.9.1</nodeVersion>
<npmVersion>4.0.3</npmVersion>
<workingDirectory>src/main/frontend</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>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>target/frontend</directory>
<targetPath>static</targetPath>
</resource>
</resources>
</build>
Backend pom.xml:
<artifactId>backend</artifactId>
<name>backend</name>
<description>C-COP Project backend</description>
<parent>
<groupId>com.trinityinnovations</groupId>
<artifactId>parent</artifactId>
<version>0.0.1-SNAPSHOT</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.restdocs</groupId>
<artifactId>spring-restdocs-mockmvc</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>com.trinityinnovations</groupId>
<artifactId>frontend</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
<!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
<dependency>
<groupId>commons-httpclient</groupId>
<artifactId>commons-httpclient</artifactId>
<version>3.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-csv -->
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-csv</artifactId>
<version>1.1</version>
</dependency>
<!-- https://mvnrepository.com/artifact/mysql/mysql-connector-java -->
<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<version>6.0.6</version>
</dependency>
<dependency>
<groupId>commons-dbcp</groupId>
<artifactId>commons-dbcp</artifactId>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hibernate/hibernate-core -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-hibernate5</artifactId>
</dependency>
<dependency>
<groupId>com.javaetmoi.core</groupId>
<artifactId>javaetmoi-hibernate5-hydrate</artifactId>
<version>2.3</version>
</dependency>
<dependency>
<groupId>com.google.maps</groupId>
<artifactId>google-maps-services</artifactId>
<version>0.1.20</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
Please let me know if there is any more information that is needed.
After doing a lot of searching, I came across the Maven War Plugin. This allowed me to pull in the necessary frontend files to the backend for the successful creation of my WAR file. The changes that need to be made are as follows:
Backend pom.xml -
after the description tags add:
<packaging>war</packaging>
Then, inside the build tags, inside plugins add this plugin:
<plugin>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>../frontend/target/frontend</directory>
</resource>
</webResources>
</configuration>
</plugin>
Other than that, you can keep the existing pom.xml's the same as only the backend pom.xml needs include war packaging. It ended up being a rather simple answer.
Also need to set the base-href in the package.json. Note "build":
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e",
"build": "ng build --base-href=\"./\""
},
Hello i use Angular 4 and Spring boot to deploy war. It's work fine and i share it.
Here 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.0http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>Spring_Angular</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging><name>Spring_Angular</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.0.2.RELEASE</version>
<relativePath /> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<directory>${basedir}/target/angular4Client</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>com.github.eirslett</groupId>
<artifactId>frontend-maven-plugin</artifactId>
<version>1.6</version>
<configuration>
<nodeVersion>v8.9.2</nodeVersion>
<npmVersion>5.6.0</npmVersion>
<installDirectory>target</installDirectory>
<workingDirectory>${basedir}/src/main/angular4client</workingDirectory>
</configuration>
<executions>
<!-- It will install nodejs and npm -->
<execution>
<id>install node and npm</id>
<goals>
<goal>install-node-and-npm</goal>
</goals>
<configuration>
<nodeVersion>v8.9.2</nodeVersion>
<npmVersion>5.6.0</npmVersion>
</configuration>
</execution>
<!-- It will execute command "npm install" inside "/e2e-angular2" directory -->
<execution>
<id>npm install</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>install</arguments>
</configuration>
</execution>
<!-- It will execute command "npm build" inside "/e2e-angular2" directory
to clean and create "/dist" directory -->
<execution>
<id>npm build</id>
<goals>
<goal>npm</goal>
</goals>
<configuration>
<arguments>run build</arguments>
</configuration>
</execution>
</executions>
</plugin>
<!-- Plugin to copy the content of /angular/dist/ directory to output
directory (ie/ /target/transactionManager-1.0/) -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-resources-plugin</artifactId>
<executions>
<execution>
<id>copy-resources</id>
<phase>validate</phase>
<goals>
<goal>copy-resources</goal>
</goals>
<configuration>
<outputDirectory>${basedir}/target/classes/static/</outputDirectory>
<resources>
<resource>
<directory>${basedir}/src/main/angular4Client/dist/angular4Client</directory>
</resource>
</resources>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<resources>
<resource>
<directory>target/angular4Client</directory>
<targetPath>static</targetPath>
</resource>
</resources>
</build>
</project>
Then in your angular package.json change like this:
"scripts": {
"ng": "ng",
"start": "ng serve --proxy-config proxy.conf.json",
"build": "ng build --prod",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
}
Create a proxy.conf.json file in angular project root :
{
"/api": {
"target": "http://localhost:8080",
"secure": false
}
}
And last things to do, move your angular 4 project into : "src/main/" on SpringBoot project.
Good luck according to this demo : http://javasampleapproach.com/java-integration/integrate-angular-4-springboot-web-app-springtoolsuite
The reference doc contains a detailed description of this. You need <packaging>war</packaging> in both your frontend and backed module pom and some Java code. All described here
With that said, I try to avoid war deploys if not totally necessary. You could just run the built jar file with java -jar your.jar and it will start in an embedded Tomcat.
I'm trying to build a fat jar witht he maven shader plugin. I am going a bit in circles fixing maven and breaking IntelliJ build, and viceversa.
My project is as follows (I left out the plugin section, which contains the shader plugin):
module-a - main project module, contains main class
module-b - module, used by A
module-c - module, used by A
module A pom:
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.my</groupId>
<artifactId>module-a</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<modules>
<module>../module-b</module>
<module>../module-c</module>
</modules>
<dependencies>
<dependency>
<groupId>com.my</groupId>
<artifactId>module-b</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.my</groupId>
<artifactId>module-c</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>org.clapper</groupId>
<artifactId>grizzled-slf4j_2.11</artifactId>
<version>1.0.2</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.7</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-experimental_2.11</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-http-core-experimental_2.11</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-stream-experimental_2.11</artifactId>
<version>2.0.3</version>
</dependency>
<dependency>
<groupId>net.ceedubs</groupId>
<artifactId>ficus_2.11</artifactId>
<version>1.1.2</version>
</dependency>
<dependency>
<groupId>com.typesafe</groupId>
<artifactId>config</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
<version>1.1.3</version>
</dependency>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>2.4.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>1.5</version>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<shadedArtifactAttached>true</shadedArtifactAttached>
<shadedClassifierName>allinone</shadedClassifierName>
<artifactSet>
<includes>
<include>*:*</include>
</includes>
</artifactSet>
<transformers>
<transformer
implementation="org.apache.maven.plugins.shade.resource.AppendingTransformer">
<resource>reference.conf</resource>
</transformer>
<transformer
implementation="org.apache.maven.plugins.shade.resource.ManifestResourceTransformer">
<manifestEntries>
<Main-Class>com.my.Service</Main-Class>
</manifestEntries>
</transformer>
</transformers>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
module B and C poms are similar(except for the module names)
<?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.my</groupId>
<artifactId>module-b</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>pom</packaging>
<dependencies>
<dependency>
<groupId>com.typesafe.akka</groupId>
<artifactId>akka-actor_2.11</artifactId>
<version>2.4.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3.2</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
All modules are in the same directory at the same level. Although I can build via IntelliJ just fine, I cannot build module-a via maven, because it cannot find modules -b and -c. So in general, I can't build anything that references a local project, since Maven won't find them. Doesn't matter if I try it inside the IDE or from the command line.
Building module-a I get:
[ERROR] Failed to execute goal on project module-a: Could not resolve
dependencies for project com.my:module-a:pom:1.0-SNAPSHOT: The
following artifacts could not be resolved:
com.my:module-b:jar:1.0-SNAPSHOT, com.my:module-c:jar:1.0-SNAPSHOT:
Could not find artifact com.my:module-c:jar:1.0-SNAPSHOT -> [Help 1]
I realize I probably screwed up these poms, trying to play with dependencies vs. module references, but what is the proper way to reference a local module in a pom file, without having to install the module in a repository?
I read that I should be creating a fourth parent project which has module-a as parent, and use that project to create the shaded jar, but even with that approach, I'm failing to get it to locate modules in the same project, it only resolves repo modules.
<packaging>pom</packaging>
<modules>
<module>../module-b</module>
<module>../module-c</module>
</modules>
this part of your module-a's pom reflects that it is the parent of module-b and module-c but contrarily your module-b and c are missing the
<parent>
<groupId>com.my</groupId>
<artifactId>module-a</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
Just an understanding, your module's pom shall include those dependencies which you might want to use as a library for the same. So I hope you want to use some code from module-b/c on your module-a to include them in your pom dependencies.
Or you may want to remove these lines from your module-a
<modules>
<module>../module-b</module>
<module>../module-c</module>
</modules>
considering all the modules are independent of each other in terms of hierarchy.
I am trying to build my pom.xml so that I can automatically create my database schema when running 'mvn install'. I'm using the "maven-cayenne-plugin" to do this. This is plugin is being called (at the integration-test phase), as I can see the output. But the mojo fails with the exception: (I used the -e and -X flag to see this).
java.lang.ClassNotFoundException: org.apache.derby.jdbc.ClientDriver
(I get the same if I try and use the EmbeddedDriver and whether or not I include 'derbyclient' or simply 'derby' as my dependency).
Here's a pom.xml that should replicate the issue.
I'm using MVN 3 on Windows.
[ Apache Maven 3.0.4 (r1232337; 2012-01-17 08:44:56+0000) ]
<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>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-modeler-plugin</artifactId>
<version>3.2M1</version>
</plugin>
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-plugin</artifactId>
<version>3.2M1</version>
<executions>
<execution>
<id>cgen</id>
<configuration>
<superPkg>com.mycompany.model.generated</superPkg>
<map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
<destDir>${project.build.sourceDirectory}</destDir>
</configuration>
<goals>
<goal>cgen</goal>
</goals>
</execution>
<execution>
<id>cdbgen</id>
<configuration>
<map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
<driver>org.apache.derby.jdbc.ClientDriver</driver>
<url>jdbc:derby:memory:tracedb;create=true</url>
<username>test</username>
</configuration>
<goals>
<goal>cdbgen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.10.1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
This also requires a valid cayenne "datamap.map.xml" file (in src/main/resources), here's one I made earlier:
<?xml version="1.0" encoding="utf-8"?>
<data-map xmlns="http://cayenne.apache.org/schema/3.0/modelMap"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://cayenne.apache.org/schema/3.0/modelMap http://cayenne.apache.org/schema/3.0/modelMap.xsd"
project-version="6">
<db-entity name="TEST">
<db-attribute name="ID" type="INTEGER" isPrimaryKey="true" isMandatory="true"/>
</db-entity>
</data-map>
EDIT:
Adding more information.
The derbyclient-10.10.1.1.jar does contain the class 'org.apache.derby.jdbc.ClientDriver' (just expanded the JAR from Netbeans).
The -X flag seems to show that the CLASSPATH is correctly referencing the JAR:
[DEBUG] (f) classpathElements = [<PROJECT-PATH>\mvn\target\classes, <HOME-DIR>\.m2\repository\org\apache\derby\derbyclient\10.10.1.1\derbyclient-10.10.1.1.jar]
SOLUTION:working pom.xml (see answer and my comment):
<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>myproject</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>jar</packaging>
<build>
<plugins>
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-modeler-plugin</artifactId>
<version>3.2M1</version>
</plugin>
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-plugin</artifactId>
<version>3.2M1</version>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<version>10.10.1.1</version>
</dependency>
</dependencies>
<executions>
<execution>
<id>cgen</id>
<configuration>
<superPkg>com.mycompany.model.generated</superPkg>
<map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
<destDir>${project.build.sourceDirectory}</destDir>
</configuration>
<goals>
<goal>cgen</goal>
</goals>
</execution>
<execution>
<id>cdbgen</id>
<configuration>
<map>${project.build.sourceDirectory}/../resources/datamap.map.xml</map>
<driver>org.apache.derby.jdbc.EmbeddedDriver</driver>
<url>jdbc:derby:memory:tracedb;create=true</url>
<username>test</username>
</configuration>
<goals>
<goal>cdbgen</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.10.1.1</version>
<scope>compile</scope>
</dependency>
</dependencies>
</project>
To ensure that the Derby driver is available during plugin execution (vs during your code compilation), you need to add it as a dependency of the plugin itself:
<plugin>
<groupId>org.apache.cayenne.plugins</groupId>
<artifactId>maven-cayenne-plugin</artifactId>
<version>3.2M1</version>
<dependencies>
<dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derbyclient</artifactId>
<version>10.10.1.1</version>
</dependency>
</dependencies>
....
</plugin>
I have a Maven project using a war overlay. As outlined in this answer, one problem with WAR overlays is that they seem to effectively sidestep Maven's dependency resolution. This results in build and/or runtime verification errors.
Fortunately, there is a solution - using the overlay/excludes configuration directives. This ensures that the resultant WAR will only have what you want.
However, it seems that the jetty:run uses the war plugin's work directory for library resolution (which does contain the "bad" JAR).
The problem is avoided by using either jetty:run-war or jetty:run-exploded.
However,
as most of our projects run fine using jetty:run,
and jetty-run with scanInterval is very convenient during development,
I'd like to know whether it's possible to add some configuration changes to the POM that would force the run goal to use the target lib folder?
For illustration purposes, here's the specific example:
the project uses the org.apache.solr:solr:3.6.2 overlay,
the overlay includes an old version of Guava, r05, while our code uses a more recent one, 14.0.1,
as stated before, while the target artifact war is fine, jetty:run includes the r05 version into the classpath, which causes verification errors in our code.
Here's the example 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>com.example</groupId>
<artifactId>solr.archetype.examination</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>war</packaging>
<name>A Solr project</name>
<properties>
<solr.version>3.6.2</solr.version>
<solr.port>8983</solr.port>
</properties>
<dependencies>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-core</artifactId>
<version>${solr.version}</version>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr</artifactId>
<version>${solr.version}</version>
<type>war</type>
</dependency>
<dependency>
<groupId>org.apache.solr</groupId>
<artifactId>solr-solrj</artifactId>
<version>${solr.version}</version>
</dependency>
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>14.0.1</version>
</dependency>
</dependencies>
<build>
<resources>
<resource>
<directory>src/main/resources</directory>
<filtering>true</filtering>
</resource>
</resources>
<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-war-plugin</artifactId>
<version>2.3</version>
<configuration>
<overlays>
<overlay>
<groupId>org.apache.solr</groupId>
<artifactId>solr</artifactId>
<excludes>
<exclude>**/guava-r05.jar</exclude>
</excludes>
</overlay>
</overlays>
</configuration>
</plugin>
<plugin>
<groupId>org.mortbay.jetty</groupId>
<artifactId>maven-jetty-plugin</artifactId>
<version>6.1.25</version>
<configuration>
<scanIntervalSeconds>10</scanIntervalSeconds>
<stopKey>foo</stopKey>
<stopPort>9999</stopPort>
<contextPath>/solr</contextPath>
<connectors>
<connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">
<port>${solr.port}</port>
<maxIdleTime>60000</maxIdleTime>
</connector>
</connectors>
<systemProperties>
<systemProperty>
<name>solr.data.dir</name>
<value>target/data</value>
</systemProperty>
</systemProperties>
</configuration>
</plugin>
</plugins>
</build>
</project>