I need to set the classpath for the maven xmlbean plugin since the xsd are depends upon my 2 java program which I don't wish to pack it as jar and added it to the dependencies.
Note : I dont wish to use maven ant plugin to do the above task.
Actual Error thrown by maven-xml plugin :
error: cvc-complex-type.2.4a: Expected elements 'namespace#http://xml.apache.org/xmlbeans/2004/02/xbean/config qname#http://xml.apache.org/xmlbeans/2004/02/xbean/config extension#http://xml.apache.org/xmlbeans/2004/02/xbean/config' instead of 'usertype#http://xml.apache.org/xmlbeans/2004/02/xbean/config' here in element config #http://xml.apache.org/xmlbeans/2004/02/xbean/config
Since I have used 2 usertype in the xmlconfig and I am bit user maven-xmlplugin is unable to locates the classes. I even tried to package those classes and added in the dependencies though failed.
pom.xml
<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>
<groupId>mygroup</groupId>
<artifactId>myartifacts</artifactId>
<version>V1</version>
<packaging>jar</packaging>
<name>myartifacts</name>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>xmlbeans-maven-plugin</artifactId>
<version>2.3.3</version>
<executions>
<execution>
<id>generateEbpacObjectMapJar</id>
<phase>generate-sources</phase>
<goals>
<goal>xmlbeans</goal>
</goals>
</execution>
</executions>
<inherited>true</inherited>
<configuration>
<memoryInitialSize>50m</memoryInitialSize>
<memoryMaximumSize>80m</memoryMaximumSize>
<schemaDirectory>src/xsddir</schemaDirectory>
<xmlConfigs>
<xmlConfig implementation="java.io.File">src/myconfig.xsdconfig</xmlConfig>
</xmlConfigs>
<sourceGenerationDirectory>target/generated/JARSources</sourceGenerationDirectory>
<debug>true</debug>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>net.sf.saxon</groupId>
<artifactId>saxon</artifactId>
<version>8.7</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans-xpath</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans-xmlpublic</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.xmlbeans</groupId>
<artifactId>xmlbeans-qname</artifactId>
<version>2.4.0</version>
</dependency>
<dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean</artifactId>
<version>2.5</version>
</dependency>
</dependencies>
xsd config below:
xb:config
xmlns:xs="http://www.w3.org/2001/XMLSchema"
xmlns:xb="http://xml.apache.org/xmlbeans/2004/02/xbean/config"
xmlns:ebpac="http://bct.com/platform/factory"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xml.apache.org/xmlbeans/2004/02/xbean/config xmlconfig.xsd">
<xb:usertype name="cl:myClass" javaname="java.lang.Class">
<xb:staticHandler>com.ImplClassHandler</xb:staticHandler>
</xb:usertype>
You may look into <scope>provided</scope> tag usage in Maven depedency, the jars would be available at the compile time from your .m2 directories; but not included in packaging.
However, you need to make sure that the library jar should be available somewhere in the classpath of the JVM.
Related
I am making a JavaFX project (for the GUI) on Maven and for the moment I want to convert a StringBuffer object to JSON.
I tried to add the dependency org.json from Maven but there is a problem in pom.xml file
Missing Artifact org.json:json:bundle:20220924
I tried adding an older version of org.json dependency, it had the same issue
I tried a different dependency, everything was ok in the pom.xml file but I could not import it into my project (any dependency).
All dependencies return this error: The type org.json.JSONArray is not accessible
Lastly, I tried to download the json-java.jar from github and add it into a libs folder on the base project directory and added it in the pom file as a dependency but it could not be resolved either.
My pom.xml file:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.example</groupId>
<artifactId>books</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20220924</version>
<type>bundle</type>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>com.sample</groupId>
<artifactId>sample</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/json-20220924.jar</systemPath>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.0</version>
<configuration>
<release>11</release>
</configuration>
</plugin>
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.6</version>
<executions>
<execution>
<!-- Default configuration for running -->
<!-- Usage: mvn clean javafx:run -->
<id>default-cli</id>
<configuration>
<mainClass>com.example.App</mainClass>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
In the end I downloaded Maven again and extracted it into a folder and changed my environment variables on path. Maven is successfully installed on version 3.8.7
Thank you in advance for any help!
UPDATE
I should mention that I tried it on a new java project (without maven) and it works fine, by importing the .jar file from git-hub repository
I want to use Java code in the web. For this I want to convert Java to WASM and use this wasm-file in JavaScript. For converting Java to WebAssembly, I am using TeaVM.
First, I created an archetype with this command: mvn archetype:generate -DarchetypeGroupId=org.teavm.flavour -DarchetypeArtifactId=teavm-flavour-application -DarchetypeVersion=0.2.0
In addition, I added these two dependencies (according to http://blog.dmitryalexandrov.net/webassembly-for-java-developers/):
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${teavm.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-interop</artifactId>
<version>${teavm.version}</version>
</dependency>
and added the following in the plugin section:
<targetType>WEBASSEMBLY</targetType>
<optimizationLevel>FULL</optimizationLevel>
<heapSize>8</heapSize>
My Java file:
#BindTemplate("templates/client.html")
public class Client extends ApplicationTemplate {
private String userName = "ABC";
public static void main(String[] args) {
Client client = new Client();
client.bind("application-content");
}
#Export(name = "getUserName")
public String getUserName() {
return userName;
}
}
But when I am doing mvn clean package, I am getting to following error (but a wasm file is created):
my complete 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>my.company</groupId>
<artifactId>java_wasm</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
<flavour.version>0.2.0</flavour.version>
<teavm.version>0.6.0</teavm.version>
<jackson.version>2.5.4</jackson.version>
</properties>
<dependencies>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-classlib</artifactId>
<version>${teavm.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-metaprogramming-impl</artifactId>
<version>${teavm.version}</version>
</dependency>
<dependency>
<groupId>org.teavm.flavour</groupId>
<artifactId>teavm-flavour-widgets</artifactId>
<version>${flavour.version}</version>
</dependency>
<dependency>
<groupId>org.teavm.flavour</groupId>
<artifactId>teavm-flavour-rest</artifactId>
<version>${flavour.version}</version>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-jso-apis</artifactId>
<version>${teavm.version}</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.teavm</groupId>
<artifactId>teavm-interop</artifactId>
<version>${teavm.version}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>${jackson.version}</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>${java.version}</source>
<target>${java.version}</target>
</configuration>
</plugin>
<plugin>
<artifactId>maven-war-plugin</artifactId>
<version>2.4</version>
<configuration>
<webResources>
<resource>
<directory>${project.build.directory}/generated/js</directory>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.teavm</groupId>
<artifactId>teavm-maven-plugin</artifactId>
<version>${teavm.version}</version>
<executions>
<execution>
<id>web-client</id>
<phase>prepare-package</phase>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<targetDirectory>${project.build.directory}/generated/js/teavm</targetDirectory>
<mainClass>my.company.Client</mainClass>
<minifying>true</minifying>
<debugInformationGenerated>true</debugInformationGenerated>
<sourceMapsGenerated>true</sourceMapsGenerated>
<sourceFilesCopied>true</sourceFilesCopied>
<optimizationLevel>ADVANCED</optimizationLevel>
<targetType>WEBASSEMBLY</targetType>
<optimizationLevel>FULL</optimizationLevel>
<heapSize>8</heapSize>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
How can I create a complete WASM without errors? Thank you in advance!
Wasm backend of TeaVM does not support JSO interop layer. It also supports subset of features available in JavaScript backend. So there's no way to make TeaVM Flavour work in Wasm, instead your should prefer JavaScript target. If you want to learn how to deal with Wasm BE, you can take a look at example.
Wasm has proven to be extremely inappropriate to run Java, so I recommend to use JavaScript BE of TeaVM. Also, please note that official site (htts://teavm.org) lists links where you can get help (google groups, gitter, direct email). I don't follow StackOverflow questions about TeaVM and don't receive notifications from SO.
I have 2 maven projects
1) My Utils Project - imports datecalc-common as a dependency, contains my custom utility classes. Note that it doesn't have a main class.
2) My Main Project - imports 'My Utils Project' as a dependency.
'My Main Project' shows the error 'Cannot find class HolidayCalculator'.
My Utils Project-pom.xml is given below.
How do I modify it so that the dependency jars are included as part of 'My Utils Project'.jar ?
<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>
<properties>
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
</properties>
<groupId>com.mycompany.mycommoncode</groupId>
<artifactId>myutilsjar</artifactId>
<version>0.0.12-SNAPSHOT</version>
<name>myutilsjar</name>
<description>Common Date Utils used by my classes</description>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>5.0.8.RELEASE</version>
</dependency>
<dependency>
<groupId>net.objectlab.kit</groupId>
<artifactId>datecalc-common</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>net.objectlab.kit</groupId>
<artifactId>datecalc-jdk8</artifactId>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.uuid</groupId>
<artifactId>java-uuid-generator</artifactId>
<version>3.1.4</version>
</dependency>
<dependency>
<groupId>javax.validation</groupId>
<artifactId>validation-api</artifactId>
<version>2.0.1.Final</version>
</dependency>
</dependencies>
<distributionManagement>
<snapshotRepository>
<id>snapshots</id>
<url>my maven url</url>
</snapshotRepository>
</distributionManagement>
</project>
NOTE: I DO NOT want to use 'shade' plugin. Is there any other way of doing this?
I had to solve that same issue some months ago. I wrote a small library that was to be shared between many projects and I wanted to add it to maven.
This is what I did.
For your "Utils project"
Compile it using maven-assembly-plugin:
Add this to your pom.xml:
<build>
<plugins>
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<configuration>
<descriptorRefs>
<descriptorRef>jar-with-dependencies</descriptorRef>
</descriptorRefs>
</configuration>
<executions>
<execution>
<id>make-assembly</id>
<phase>package</phase>
<goals>
<goal>attached</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
Build the library with it's dependencies using the following command:
mvn clean compile assembly:attached
For your main project
Add this plugin to your pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-install-plugin</artifactId>
<version>2.5.2</version>
<executions>
<execution>
<id>install-external</id>
<phase>clean</phase>
<configuration>
<file>${project.basedir}/src/main/resources/lib/sso-client-1.0.jar</file>
<repositoryLayout>default</repositoryLayout>
<groupId>SSOClient</groupId>
<artifactId>sso-client</artifactId>
<version>1.0</version>
<packaging>jar</packaging>
<generatePom>true</generatePom>
</configuration>
<goals>
<goal>install-file</goal>
</goals>
</execution>
</executions>
</plugin>
As you can see, I wrote a custom SSO Client.
This will read the jar you compiled in the previous step, and make it available as a dependency. I decided to place it in the resources folder of the main project. The version has to match the one in your "utils project".
Also add the dependency to the pom.xml:
<dependency>
<groupId>SSOClient</groupId>
<artifactId>sso-client</artifactId>
<version>1.0</version>
</dependency>
That's it! You can now reference the classes of the package in your main project.
Let me know if you need clarification.
The Apache Maven Shade Plugin provides the capability to package your artifact in a "uber-jar", that is to say a jar including all dependencies required to run the project. If needed this plugin also supports packages shading (renaming) for some of the dependencies.
More info at:
https://maven.apache.org/plugins/maven-shade-plugin/examples/includes-excludes.html#
I am having trouble creating a simple Java AWS Lambda that does not exceed the 50MB size limit and I am not sure where I am going wrong...
My actual Java code is only around 100 lines long. I am using Maven to pull in my dependencies, most of which are the AWS dependencies themselves...
After I do a mvn package or mvn clean install the resulting jar is around 64MB!
What am I doing wrong here? If I do not add the AWS dependencies then I cannot build with maven but if I do then the resulting jar file is huge and I am unable to upload it to AWS lambda because of the size restriction...
My pom file is below:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>lambda-handler</groupId>
<artifactId>lambda-handler</artifactId>
<version>0.0.1-SNAPSHOT</version>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<version>2.3</version>
<configuration>
<createDependencyReducedPom>false</createDependencyReducedPom>
</configuration>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-core</artifactId>
<version>1.1.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-lambda-java-events</artifactId>
<version>1.3.0</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk</artifactId>
<version>1.11.166</version>
</dependency>
<dependency>
<groupId>com.amazonaws</groupId>
<artifactId>aws-java-sdk-s3</artifactId>
<version>1.11.166</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.5.3</version>
</dependency>
</dependencies>
</project>
to fix this issue you need to do the following:
Remove the amazon SDK from your pom.
Add the Execution Amazon SDK variable:
AWSEXECUTIONENV -> AWSLambdajava8
Remember to use Java8 in your project. The total size of a simple project will be around 7-10 MB.
If you want to see HOW-TO with github sources and step by step you can see it on my blog:
jmazzetti.com -> Serverless on AWS Lambda using Java
All the best,
Jose.
you need to remove <artifactId>aws-java-sdk-s3</artifactId> and <artifactId>aws-java-sdk</artifactId> dependencies from your maven project and update and rebuild your maven project.
I am upgrading my system's Maven runtime from 3.0.5 to 3.1.1 and trying to build my project using mvn clean install like I normally would. Using the older Maven runtime, the build would always succeed. However, I am now always getting this error message during the build:
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor (default-descriptor) on project XYZ: Execution default-descriptor of goal org.apache.maven.plugins:maven-plugin-plugin:3.2:descriptor failed: 48188 -> [Help 1]
I thought that perhaps it was due to my dependencies and plugins being outdated, so I ran mvn versions:use-latest-versions to update my pom.xml versions. That still did not fix this issue. Any ideas?
UPDATE
By popular demand, here is what my pom.xml file looks like. Note that all dependency and plugin versions were updated by mvn versions:use-latest-versions except for Sitebricks and qdox, due to breaking changes that I didn't want to integrate into my project.
<?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.company</groupId>
<artifactId>my-own-project</artifactId>
<version>1.0.1-SNAPSHOT</version>
<name>My Cool Maven Plugin</name>
<packaging>maven-plugin</packaging>
<distributionManagement>
<repository>
<id>someID</id>
<url>http://some.url.com</url>
</repository>
</distributionManagement>
<licenses>
<license>
<name>The Apache Software License, Version 2.0</name>
<url>http://www.apache.org/licenses/LICENSE-2.0.txt</url>
<distribution>repo</distribution>
</license>
</licenses>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
</properties>
<dependencies>
<dependency>
<groupId>org.freemarker</groupId>
<artifactId>freemarker</artifactId>
<version>2.3.20</version>
</dependency>
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-plugin-api</artifactId>
<version>3.1.1</version>
</dependency>
<dependency>
<groupId>org.codehaus.jackson</groupId>
<artifactId>jackson-core-asl</artifactId>
<version>1.9.11</version>
</dependency>
<dependency>
<groupId>com.google.sitebricks</groupId>
<artifactId>sitebricks</artifactId>
<version>0.8.5</version>
</dependency>
<dependency>
<groupId>com.thoughtworks.qdox</groupId>
<artifactId>qdox</artifactId>
<version>1.12</version>
</dependency>
<dependency>
<groupId>org.testng</groupId>
<artifactId>testng</artifactId>
<version>6.8.7</version>
<scope>test</scope>
</dependency>
</dependencies>
<reporting>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>findbugs-maven-plugin</artifactId>
<version>2.3.1</version>
<configuration>
<effort>Max</effort>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>cobertura-maven-plugin</artifactId>
<version>2.4</version>
</plugin>
</plugins>
</reporting>
</project>
Upgrading and using below dependency with config resolved my issue:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-plugin-plugin</artifactId>
<version>3.6.0</version>
<configuration>
<!-- see http://jira.codehaus.org/browse/MNG-5346 -->
<skipErrorNoDescriptorsFound>true</skipErrorNoDescriptorsFound>
</configuration>
<executions>
<execution>
<id>mojo-descriptor</id>
<goals>
<goal>descriptor</goal>
</goals>
</execution>
</executions>
</plugin>
I had exactly the same problem and tried probably every hint provided in the possible duplicate Basic maven plugin project not working, Mojo plugin descriptors not generating, but nothing worked. Eventually in turned out that an old version 2.6.1 of the library com.ibm.icu:icu4j that was used by some other 3rd party module was responsible. I got rid of the icu4j dependency entirely and maven-plugin-plugin run with out problems thereafter.