I want to create an Eclipse plugin that is able to execute Python code. For this I want to use Jython. Additionally I use Maven for dependencies and want to use Maven for packaging.
My problem: (Solution added below)
I'm not able to build with Maven a eclipse plugin which is using Jython. Maven tells "BUILD SUCCESS" but Tycho & jython-compile-maven-plugin doesn't work together. The jython plugin is working because there are two jar as output, the normal jar and the jar with Jython extracted. The Tycho plugin is working because the normal jar is a valid plugin. But the jar with Jython extracted, which is needed, isn't a valid plugin. So how to bundle this 2 plugins correct?
Questions:
How to bring Tycho + jython-compile-maven-plugin together?
Iam using unpack-dependencies to unpack the python libs, but its working only once, if the folder is deleted/renamed/... Maven Update Project never called this again.
Because Maven, Tycho, Jython, M2E is new for me I ...:
created java project using Jython, packed as runnable jar with Maven, working
created eclipse plug-in, build with Maven & tycho plugins, working
created eclipse-plugin using Jython with "BundleShape: dir" without Maven, working
How to reproduce the problem?
Eclipse Photon, Modeling + installed M2E:
- Create new Plug-in Project name: ExampleMavenJythonEclipsePlugin, Version: 1.0.0.qualifier
- [x] This plug-in will make contributions to the UI (and no RC Application)
- [x] Create a plug-in using one of the templates
- View contribution using 3.x API
- View Class Name: SampleView
- Convert Project to Maven Project
- Replace POM with given given source
- Run Maven "Update Project...", refresh workspace after
- if there are pom errors like "Execution default-compile of goal org.eclipse.tycho:tycho-compiler-plugin [...]" do a change anywhere in pom and save (like insert newline, whitespace, tab, ...)
- Replace SampleView Class with given source (don't delete your package)
- Open plugin.xml, runtime, add classpath libs/jython-standalone.jar
- right click pom, run as, maven build..., goals: clean package
Testing:
- Put the plugin to eclipse plugin dir, restart eclipse
- window -> show view -> other
- Sample Category, Sample View
Additionally:
"run as Eclipse Application" doesn't mean that its working if packed.
Iam using Jython-Standalone.
Edit 1:
I made some progress. I did not understand correctly how Tycho works at the beginning. Tycho is using the Manifest / build.properties not the pom dependencies. The POM manages not the runtime dependencies, that why I needed to add the jython-standalone.jar to runtime. The jython-compile-maven-plugin isn't needed. I seems most important for Jython that the /Lib folder with python code is at the root point if in a jar. There are many possibilities to solve this, I am using a source folder created with eclipse named "pythonExtracted". The new source folder should now be in build.properties. Every source folder is copied to the root of the jar. The jython-standalone.jar ist in libs/ and is added to classpath manually. If you set "python.home" to the plugin.jar it looks working. But I can't resolve the bundle and the path "." points to the eclipse.exe not the jar like it is if a runnable jar is used.
I don't like that I now have 2 times the Lib folder with the same code. I tried to extract jython into lib/jython and set the runtime classpath. Tried to vary python home path. Nothing worked if the plugin is packed as jar. It really seems like it can only be /Lib inside of the jar. I tried to use Jython (not standalone) in libs but extracted Lib folder from standalone, but PySystemState / PythonInterpreter couldn't be resolved after packaged.
Solution:
- you need to add libs/jython to runtime classpath manually
- you need to create a source folder named: pythonExtracted (or adjust pom.xml below)
+ working if eclipse plugin packed as jar
+ Maven Update Project prepares the project
- python libs are twice in (extra ~10MB)
Solution: Pom.xml (without M2E config)
<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>ExampleMavenJythonEclipsePlugin</groupId>
<artifactId>ExampleMavenJythonEclipsePlugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<eclipse-release-url>http://download.eclipse.org/releases/photon</eclipse-release-url>
<maven-tycho-version>1.2.0</maven-tycho-version>
<maven-dependency-plugin-version>3.1.1</maven-dependency-plugin-version>
<maven-compiler-plugin-version>3.8.0</maven-compiler-plugin-version>
</properties>
<repositories>
<repository>
<id>eclipse-release</id>
<layout>p2</layout>
<url>${eclipse-release-url}</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin-version}</version>
<executions>
<execution> <!-- JythonStandalone to /libs, strip version -->
<id>copyLibs</id>
<phase>process-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
<stripClassifier>true</stripClassifier>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<outputDirectory>${project.basedir}/libs</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpackPythonLibsFromJython</id>
<phase>initialize</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.python</includeGroupIds>
<includeArtifactIds>jython-standalone</includeArtifactIds>
<includes>Lib/**/*</includes>
<outputDirectory>${project.basedir}/pythonExtracted</outputDirectory> <!-- has to be a source folder -->
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${maven-tycho-version}</version>
<extensions>true</extensions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${maven-tycho-version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
</build>
</project>
Solution: Pom.xml (with M2E config)
<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>ExampleMavenJythonEclipsePlugin</groupId>
<artifactId>ExampleMavenJythonEclipsePlugin</artifactId>
<version>1.0.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<eclipse-release-url>http://download.eclipse.org/releases/photon</eclipse-release-url>
<maven-tycho-version>1.2.0</maven-tycho-version>
<maven-dependency-plugin-version>3.1.1</maven-dependency-plugin-version>
<maven-compiler-plugin-version>3.8.0</maven-compiler-plugin-version>
</properties>
<repositories>
<repository>
<id>eclipse-release</id>
<layout>p2</layout>
<url>${eclipse-release-url}</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
<version>2.7.1</version>
</dependency>
</dependencies>
<build>
<sourceDirectory>src</sourceDirectory>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-dependency-plugin</artifactId>
<version>${maven-dependency-plugin-version}</version>
<executions>
<execution> <!-- JythonStandalone to /libs, strip version -->
<id>copyLibs</id>
<phase>process-sources</phase>
<goals>
<goal>copy</goal>
</goals>
<configuration>
<stripVersion>true</stripVersion>
<stripClassifier>true</stripClassifier>
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
<outputDirectory>${project.basedir}/libs</outputDirectory>
<artifactItems>
<artifactItem>
<groupId>org.python</groupId>
<artifactId>jython-standalone</artifactId>
</artifactItem>
</artifactItems>
</configuration>
</execution>
<execution>
<id>unpackPythonLibsFromJython</id>
<phase>initialize</phase>
<goals>
<goal>unpack-dependencies</goal>
</goals>
<configuration>
<includeGroupIds>org.python</includeGroupIds>
<includeArtifactIds>jython-standalone</includeArtifactIds>
<includes>Lib/**/*</includes>
<outputDirectory>${project.basedir}/pythonExtracted</outputDirectory> <!-- has to be a source folder -->
<overWriteReleases>true</overWriteReleases>
<overWriteSnapshots>true</overWriteSnapshots>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>${maven-compiler-plugin-version}</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-maven-plugin</artifactId>
<version>${maven-tycho-version}</version>
<extensions>true</extensions>
</plugin>
<!-- Enable the replacement of the SNAPSHOT version in the final product
configuration
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<version>${maven-tycho-version}</version>
<executions>
<execution>
<phase>package</phase>
<id>package-feature</id>
<configuration>
<finalName>${project.artifactId}_${unqualifiedVersion}.${buildQualifier}</finalName>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-p2-repository-plugin</artifactId>
<version>${maven-tycho-version}</version>
<configuration>
<includeAllDependencies>true</includeAllDependencies>
</configuration>
</plugin>-->
<plugin>
<groupId>org.eclipse.tycho</groupId>
<artifactId>target-platform-configuration</artifactId>
<version>${maven-tycho-version}</version>
<configuration>
<pomDependencies>consider</pomDependencies>
<environments>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86</arch>
</environment>
<environment>
<os>linux</os>
<ws>gtk</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86</arch>
</environment>
<environment>
<os>win32</os>
<ws>win32</ws>
<arch>x86_64</arch>
</environment>
<environment>
<os>macosx</os>
<ws>cocoa</ws>
<arch>x86_64</arch>
</environment>
</environments>
</configuration>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<!--This plugin's configuration is used to store Eclipse m2e settings
only. It has no influence on the Maven build itself. -->
<plugin>
<groupId>org.eclipse.m2e</groupId>
<artifactId>lifecycle-mapping</artifactId>
<version>1.0.0</version>
<configuration>
<lifecycleMappingMetadata>
<pluginExecutions>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-packaging-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>validate-version</goal>
<goal>validate-id</goal>
<goal>build-qualifier</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>org.eclipse.tycho</groupId>
<artifactId>tycho-compiler-plugin</artifactId>
<versionRange>[1.0.0,)</versionRange>
<goals>
<goal>compile</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
<pluginExecution>
<pluginExecutionFilter>
<groupId>
org.apache.maven.plugins
</groupId>
<artifactId>
maven-dependency-plugin
</artifactId>
<versionRange>
[${maven-dependency-plugin-version},)
</versionRange>
<goals>
<goal>copy</goal>
<goal>unpack-dependencies</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>false</runOnIncremental>
</execute>
</action>
</pluginExecution>
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Solution: Activator.java (set it in plugin.xml)
package examplemavenjythoneclipseplugin.views;
import org.eclipse.ui.plugin.AbstractUIPlugin;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
/**
* The activator class controls the plug-in life cycle
*/
public class Activator extends AbstractUIPlugin {
public static Bundle bundle = null;
// The shared instance
private static Activator plugin;
/**
* The constructor
*/
public Activator() {
}
/*
* (non-Javadoc)
* #see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
*/
public void start(BundleContext context) throws Exception {
super.start(context);
plugin = this;
if (bundle == null) {
bundle = context.getBundle();
}
}
/*
* (non-Javadoc)
* #see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
*/
public void stop(BundleContext context) throws Exception {
super.stop(context);
}
/**
* Returns the shared instance
*
* #return the shared instance
*/
public static Activator getDefault() {
return plugin;
}
}
Solution: SampleView.java
package examplemavenjythoneclipseplugin.views;
import java.io.File;
import java.util.Properties;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.FormAttachment;
import org.eclipse.swt.layout.FormData;
import org.eclipse.swt.layout.FormLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;
import org.osgi.framework.Bundle;
import org.python.core.PySystemState;
import org.python.util.PythonInterpreter;
public class SampleView extends ViewPart {
private static void pythonTest(final String home) {
final Properties propsPre = System.getProperties();
final Properties propsPost = new Properties();
// suppress warning console encoding not set
propsPost.put("python.console.encoding", "UTF-8");
// if no Lib folder is found, constructor of PythonInterpreter fails, but this isn't useful
propsPost.put("python.import.site", "false");
// set python home path / cache dir for Jython (just package information)
propsPost.put("python.cachedir", new File(home, "cachedir").getAbsolutePath());
propsPost.put("python.home", new File(home).getAbsolutePath());
// used for our own "System.out" => we can read it later with ease
final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
// needed only once in any application before any other Python/Jython code is used.
PySystemState.initialize(propsPre, propsPost, new String[0]);
try (final PythonInterpreter interpreter = new PythonInterpreter();) {
interpreter.setOut(new java.io.PrintStream(out));
interpreter.exec("print('Hello World')"); // checks if start is fine
interpreter.exec("print ' '");
interpreter.exec("print('importing sys'); import sys; print('done');"); // should work even if Lib not found
interpreter.exec("print 'prefix:', sys.prefix");
interpreter.exec("print ' '");
interpreter.exec("print 'System path:', sys.path");
interpreter.exec("print('importing os'); import os; print('done');"); // needs access to lib folder
interpreter.exec("print('Hello World')"); // if anything above fails, null is printed not Hello World
MessageDialog.openInformation(Display.getDefault().getActiveShell(), "Output:",
out.toString() + "\n" + (home));
} catch (Throwable t) {
MessageDialog.openError(Display.getDefault().getActiveShell(), "Jython failed",
out.toString() + "\n" + t.toString());
t.printStackTrace();
}
}
#Override
public void createPartControl(Composite parent) {
/* 1) Show Python home path
* 2) make Python home path changable
* 3) create button to start PythonInit & test
*/
// I have no clue why, getBundle failed in various situations, the plugin Activator gets the bundle better.
// final Bundle bundle = Platform.getBundle("ExampleMavenJythonEclipsePlugin"); // Argument = Manifest.Bundle-SymbolicName
final Bundle bundle = Activator.bundle; // start(BundleContext context) => context.getBundle()
// 1 & 2) Create input showing the home path used (fallback "." = not valid in this working version but is vor runnable jar)
parent.setLayout(new FormLayout());
final Text input = new Text(parent, SWT.SINGLE);
FormData d = new FormData();
d.top = new FormAttachment(parent, 0);
d.left = new FormAttachment(parent, 0);
d.right = new FormAttachment(100, 0);
input.setLayoutData(d);
try {
File b = FileLocator.getBundleFile(bundle);
input.setText(b.getAbsolutePath());
} catch (Throwable e) {
input.setText(".");
}
// 3) create button to start test
final Button button = new Button(parent, SWT.PUSH);
d = new FormData();
d.top = new FormAttachment(input, 5);
d.left = new FormAttachment(parent, 0);
d.right = new FormAttachment(100, 0);
button.setLayoutData(d);
button.setText("test");
button.addSelectionListener(new SelectionAdapter() {
#Override
public void widgetSelected(SelectionEvent e) {
pythonTest(input.getText());
}
});
}
#Override
public void setFocus() {
}
}
Solution: Maven Console "mvn clean package"
[INFO] Scanning for projects...
[INFO] Computing target platform for MavenProject: ExampleMavenJythonEclipsePlugin:ExampleMavenJythonEclipsePlugin:1.0.0-SNAPSHOT # D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\pom.xml
[INFO] Fetching p2.index from http://download.eclipse.org/releases/photon/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/photon/
[INFO] Adding repository http://download.eclipse.org/releases/photon
[INFO] Fetching p2.index from http://download.eclipse.org/technology/epp/packages/photon/
[INFO] Fetching p2.index from http://download.eclipse.org/technology/epp/packages/photon/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/photon/201806271001/
[INFO] Fetching p2.index from http://download.eclipse.org/releases/photon/201806271001/
[INFO] Fetching content.xml.xz from http://download.eclipse.org/releases/photon/201806271001/
[INFO] Fetching content.xml.xz from http://download.eclipse.org/releases/photon/201806271001/
[INFO] Fetching content.xml.xz from http://download.eclipse.org/releases/photon/201806271001/ (248,94kB at 247,04kB/s)
[INFO] Fetching content.xml.xz from http://download.eclipse.org/releases/photon/201806271001/ (701,55kB at 349,82kB/s)
[INFO] Resolving dependencies of MavenProject: ExampleMavenJythonEclipsePlugin:ExampleMavenJythonEclipsePlugin:1.0.0-SNAPSHOT # D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\pom.xml
[INFO] Resolving class path of MavenProject: ExampleMavenJythonEclipsePlugin:ExampleMavenJythonEclipsePlugin:1.0.0-SNAPSHOT # D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\pom.xml
[INFO]
[INFO] -----
[INFO] Building ExampleMavenJythonEclipsePlugin 1.0.0-SNAPSHOT
[INFO] ---------------------------[ eclipse-plugin ]---------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # ExampleMavenJythonEclipsePlugin ---
[INFO] Deleting D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\target
[INFO]
[INFO] --- tycho-packaging-plugin:1.2.0:build-qualifier (default-build-qualifier) # ExampleMavenJythonEclipsePlugin ---
[INFO] The project's OSGi version is 1.0.0.201812181615
[INFO]
[INFO] --- tycho-packaging-plugin:1.2.0:validate-id (default-validate-id) # ExampleMavenJythonEclipsePlugin ---
[INFO]
[INFO] --- tycho-packaging-plugin:1.2.0:validate-version (default-validate-version) # ExampleMavenJythonEclipsePlugin ---
[INFO]
[INFO] --- maven-dependency-plugin:3.1.1:unpack-dependencies (unpackPythonLibsFromJython) # ExampleMavenJythonEclipsePlugin ---
[INFO] Unpacking D:\Programme\.m2\org\python\jython-standalone\2.7.1\jython-standalone-2.7.1.jar to D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\pythonExtracted with includes "Lib/**/*" and excludes ""
[INFO]
[INFO] --- maven-dependency-plugin:3.1.1:copy (copyLibs) # ExampleMavenJythonEclipsePlugin ---
[INFO] Configured Artifact: org.python:jython-standalone:?:jar
[INFO] Copying jython-standalone-2.7.1.jar to D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\libs\jython-standalone.jar
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:resources (default-resources) # ExampleMavenJythonEclipsePlugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\src\main\resources
[INFO]
[INFO] --- tycho-compiler-plugin:1.2.0:compile (default-compile) # ExampleMavenJythonEclipsePlugin ---
[INFO] Compiling 2 source files to D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\target\classes
[INFO]
[INFO] --- maven-resources-plugin:2.4.3:testResources (default-testResources) # ExampleMavenJythonEclipsePlugin ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\src\test\resources
[INFO]
[INFO] --- target-platform-configuration:1.2.0:target-platform (default-target-platform) # ExampleMavenJythonEclipsePlugin ---
[INFO]
[INFO] --- tycho-packaging-plugin:1.2.0:package-plugin (default-package-plugin) # ExampleMavenJythonEclipsePlugin ---
[INFO] Building jar: D:\Programme\eclipse\modeling oxygen\MDSD-Prototyping\ExampleMavenJythonEclipsePlugin\target\ExampleMavenJythonEclipsePlugin-1.0.0-SNAPSHOT.jar
[INFO]
[INFO] --- tycho-p2-plugin:1.2.0:p2-metadata-default (default-p2-metadata-default) # ExampleMavenJythonEclipsePlugin ---
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 55.097 s
[INFO] Finished at: 2018-12-18T17:16:51+01:00
[INFO] ------------------------------------------------------------------------
Related
My project structure is:
Project_Name
|-src/main/java
|-src/test/java
|-default package
|-MyIT.java
|-steps
|-MySteps.java
|-pom.xml
MyIT.java:
#RunWith(SerenityRunner.class)
public class MyIT {
#Steps
MySteps mySteps;
#BeforeClass
public static void setUp() {
RestAssured.baseURI="https://restcountries.com/";
System.out.println("1");
}
#Test
#Title("Check \"Republic Of India\"")
public void verify_that_given_string_found_in_the_response() {
mySteps.whenIOpenURLForIndia();
mySteps.thenRepublicOfIndiaFoundInResponse();
}
}
MySteps.java:
public class MySteps {
#Step("When I Open the URL for India")
public void whenIOpenURLForIndia() {
SerenityRest.given().relaxedHTTPSValidation().basePath("v2/name/{country}").pathParam("country", "INDIA").when().get();
}
#Step("Then \"Republic of India\" found in the response")
public void thenRepublicOfIndiaFoundInResponse() {
SerenityRest.lastResponse().then().body("[1].altSpellings",hasItem("Republic of India"));
}
}
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>org.restcountries</groupId>
<artifactId>Serenity_RestAssured_Assignment1</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Serenity_RestAssured_Assignment1</name>
<!-- FIXME change it to the project's website -->
<url>http://www.example.com</url>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-core -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-core</artifactId>
<version>3.1.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-junit -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-junit</artifactId>
<version>3.1.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/net.serenity-bdd/serenity-rest-assured -->
<dependency>
<groupId>net.serenity-bdd</groupId>
<artifactId>serenity-rest-assured</artifactId>
<version>3.1.15</version>
</dependency>
<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
</dependency>
<!-- https://mvnrepository.com/artifact/io.rest-assured/rest-assured -->
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>4.4.0</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.hamcrest/java-hamcrest -->
<dependency>
<groupId>org.hamcrest</groupId>
<artifactId>java-hamcrest</artifactId>
<version>2.0.0.0</version>
</dependency>
</dependencies>
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.8.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skip>true</skip>
</configuration>
</plugin>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M4</version>
<configuration>
<skipTests>false</skipTests>
</configuration>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>
Now when I run it using:
mvn clean verify
its output is:
[INFO] Scanning for projects...
[INFO]
[INFO] ---------< org.restcountries:Serenity_RestAssured_Assignment1 >---------
[INFO] Building Serenity_RestAssured_Assignment1 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-clean-plugin:2.5:clean (default-clean) # Serenity_RestAssured_Assignment1 ---
[INFO] Deleting C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # Serenity_RestAssured_Assignment1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\main\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:compile (default-compile) # Serenity_RestAssured_Assignment1 ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # Serenity_RestAssured_Assignment1 ---
[INFO] Using 'UTF-8' encoding to copy filtered resources.
[INFO] skip non existing resourceDirectory
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:3.8.1:testCompile (default-testCompile) # Serenity_RestAssured_Assignment1 ---
[INFO] Changes detected - recompiling the module!
[INFO] Compiling 2 source files to
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\test-classes
[INFO]
[INFO] --- maven-surefire-plugin:3.0.0-M4:test (default-test) # Serenity_RestAssured_Assignment1 ---
[INFO] Tests are skipped.
[INFO]
[INFO] --- maven-jar-plugin:2.4:jar (default-jar) # Serenity_RestAssured_Assignment1 ---
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar:
C:\ eclipse_workspace\Serenity_RestAssured_Assignment1\target\Serenity_RestAssured_Assignment1-0.0.1-SNAPSHOT.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.305 s
[INFO] Finished at: 2022-06-24T04:14:55+05:30
It shows “tests are skipped” and “jar will be empty”.
My question is why mvn verify is not running MyIT.java test despite that naming convention is proper for integration test(maven failsafe plugin). Maven surefire plugin is skipping the tests but maven failsafe plugin should identify the MyIT.java test.
EDIT: mvn clean test-compile failsafe:integration-test is able to run the MyIT.java test successfully but mvn clean test-compile failsafe:verify does not.
The issue is simply because you have defined the maven-failsafe-plugin in pluginManagement only.
The usual way is to define the version in pluginManagement while the binding has to be done in build area.
<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<version>3.0.0-M7</version>
</plugin>
</plugins>
</pluginManagement>
<plugins>
<plugin>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
I also recommend to upgrade your used plugins which means define newer versions of all used plugin in pluginManagement.
Furthermore you should not define a configuration for maven-surefire-plugin:
<configuration>
<skip>true</skip>
</configuration>
I have a spring based web application in which I am trying to consume a SOAP service. I am using jaxb2-maven-plugin(org.codehaus.mojo) for that. However I see an empty jaxb2 folder which is crated under target and I dont see any java classes in it. I have the wsdl placed correctly under the resources folder itself.
Below is the plugin config created in pom.xml
<build>
<finalName>${project.artifactId}</finalName>
<resources>
<resource>
<directory>src/main/resources</directory>
</resource>
<resource>
<directory>src/main/java/com/xyz/rap/service/impl/wsdl</directory>
<targetPath>wsdl</targetPath>
</resource>
<resource>
<directory>src/main/config</directory>
<targetPath>config</targetPath>
</resource>
</resources>
<plugins>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>1.6</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<!-- Package to store the generated file -->
<packageName>com.xxx.gen.retail.abc</packageName>
<!-- Treat the input as WSDL -->
<wsdl>true</wsdl>
<!-- Input is not XML schema -->
<xmlschema>false</xmlschema>
<!-- The location of the WSDL file -->
<schemaDirectory>${project.basedir}/src/main/resources</schemaDirectory>
<!-- The WSDL file that you saved earlier -->
<schemaFiles>gene.wsdl</schemaFiles>
<!-- Don't clear output directory on each run -->
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<!-- or whatever version you use -->
<source>1.7</source>
<target>1.7</target>
</configuration>
</plugin>
</plugins>
</build>
</project>
Below is the log when I run "maven install"
[INFO] Building rap-web Maven Webapp 0.0.1-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
**[INFO] --- jaxb2-maven-plugin:1.6:xjc (xjc) # rap-web ---
[INFO] Generating source...
[WARNING] No encoding specified; default platform encoding will be used for generated sources.
[INFO] parsing a schema...
[INFO] compiling a schema...
[INFO]
[INFO] --- maven-resources-plugin:2.6:resources (default-resources) # rap-web ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 15 resources
[INFO] Copying 3 resources to wsdl
[INFO] Copying 1 resource to config
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) # rap-web ---
[WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent!
[INFO] Compiling 50 source files to C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\target\classes**
[INFO]
[INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) # rap-web ---
[WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\src\test\resources
[INFO]
[INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) # rap-web ---
[INFO] Nothing to compile - all classes are up to date
[INFO]
[INFO] --- maven-surefire-plugin:2.12.4:test (default-test) # rap-web ---
It says Parsing and compiling the schema in logs but I dont see any java classes getting created in the logs and I see an empty jaxb2 folder and an other empty generated-sources folder getting created. Please refer below image for that:
jaxb2-maven-plugin will create classes by default into target/generated-sources/jaxb. if you are stil not getting classes into target folder then If you are using Eclipse, you can add this folder into your project build path: right-clicking on project and selecting "Build Path > Use Source Folder.
then you need to run mvn clean install it will clean or delete the target folder and regenerate everything.
Try the version 2.2 of the codehaus. Keep in mind that you will need to change your xml a bit since there is a difference between 1.x and 2.x.
Having said that I would like to tell you that I'm having a similar issue. But it could be caused by something else. I'm using IntelliJ and it's generating empty jaxb folder under the /target/generated-sources/.
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxb2-maven-plugin</artifactId>
<version>2.2</version>
<executions>
<execution>
<id>xjc</id>
<goals>
<goal>xjc</goal>
</goals>
</execution>
</executions>
<configuration>
<sources>
<source>/src/main/resources/xsd/</source>
</sources>
<outputDirectory>${project.basedir}/target/generated-sources/jaxb</outputDirectory>
<clearOutputDir>false</clearOutputDir>
</configuration>
</plugin>
I am trying to learn about jax-ws and created a simple Bottom-Up HelloWorld webservice in order to train myself:
import org.jboss.annotation.ejb.LocalBinding;
import javax.ejb.Remote;
import javax.ejb.Stateless;
import javax.jws.WebMethod;
import javax.jws.WebService;
import javax.jws.soap.SOAPBinding;
#WebService(serviceName = "HelloWorldWebServiceExperiment",
portName = "HelloWorldPort",
name = "HelloWorld")
#SOAPBinding(style = SOAPBinding.Style.DOCUMENT,
use = SOAPBinding.Use.LITERAL,
parameterStyle = SOAPBinding.ParameterStyle.WRAPPED)
#Stateless
#Remote
#LocalBinding(jndiBinding = "training.webservice.HelloWorldWebServiceRemote/local")
public class HelloWorldWebServiceBean {
private static final String HELLO_WORLD = "Hello World";
#WebMethod
public String helloWorld() {
return HELLO_WORLD;
}
}
When I deploy this webservice I can access the wsdl, so that seems to work fine.
Then I tried to generate a webservice client. And to do so I needed to create stubs, which I tried to create with the maven plugin jaxws-maven-plugin. Here is my pom.xml:
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<properties>
<wsdlPath>${project.build.directory}</wsdlPath>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>2.3</version>
<configuration>
<source>1.5</source>
<target>1.5</target>
</configuration>
<executions>
<execution>
<goals>
<goal>compile</goal>
</goals>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<configuration>
<webResources>
<resource>
<targetPath>WEB-INF</targetPath>
<directory>src/main/webapp/WEB-INF</directory>
<includes>
<include>web.xml</include>
</includes>
<filtering>true</filtering>
</resource>
</webResources>
</configuration>
</plugin>
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>jaxws-maven-plugin</artifactId>
<executions>
<execution>
<id>genwsdl</id>
<phase>process-classes</phase>
<goals>
<goal>wsgen</goal>
</goals>
<configuration>
<genWsdl>true</genWsdl>
<sei>training.webservice.HelloWorldWebServiceBean</sei>
</configuration>
</execution>
<execution>
<id>consumeWsdlForStubs</id>
<phase>process-classes</phase>
<goals>
<goal>wsimport</goal>
</goals>
<configuration>
<wsdlDirectory>target/jaxws/wsgen/wsdl</wsdlDirectory>
<wsdlFiles>
<wsdlFile>HelloWorldWebServiceExperiment.wsdl</wsdlFile>
</wsdlFiles>
<keep>true</keep>
<destDir>target/classes</destDir>
<sourceDestDir>target/stubs</sourceDestDir>
<verbose>true</verbose>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<executions>
<execution>
<id>package-wsclient-jars</id>
<phase>package</phase>
<goals>
<goal>jar</goal>
</goals>
<configuration>
<classesDirectory>target/stubs</classesDirectory>
<classifier>wsclient</classifier>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
<dependencies>
<!-- JAX-WS Annotations -->
<dependency>
<groupId>javax.jws</groupId>
<artifactId>jsr181-api</artifactId>
<version>1.0-MR1</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jbossws-spi</artifactId>
<version>1.0.0.GA</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb3x</artifactId>
<version>4.2.2</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>jboss</groupId>
<artifactId>jboss-annotations-ejb3</artifactId>
<version>4.2.2.GA</version>
<!--<scope>provided</scope>-->
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-jaxws</artifactId>
<version>4.2.2</version>
<scope>provided</scope>
</dependency>
</dependencies>
The Build with maven will generate the follwoing output and a .jar file with generated .java files:
> mvn clean install
[INFO] Scanning for projects...
[INFO] ------------------------------------------------------------------------
[INFO] Building Unnamed - training.webservice:HelloWorldWebServiceExperiment:war:1.0-SNAPSHOT
[INFO] task-segment: [clean, install]
[INFO] ------------------------------------------------------------------------
[INFO] [clean:clean {execution: default-clean}]
[INFO] Deleting directory ---/HelloWorldWebServiceExperiment/target
[INFO] [resources:resources {execution: default-resources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] Copying 0 resource
[INFO] [compiler:compile {execution: default-compile}]
[WARNING] File encoding has not been set, using platform encoding UTF-8, i.e. build is platform dependent!
[INFO] Compiling 2 source files to ---/HelloWorldWebServiceExperiment/target/classes
[INFO] [compiler:compile {execution: default}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [jaxws:wsgen {execution: genwsdl}]
[INFO] [jaxws:wsimport {execution: consumeWsdlForStubs}]
[INFO] Processing: ---/HelloWorldWebServiceExperiment/target/jaxws/wsgen/wsdl/HelloWorldWebServiceExperiment.wsdl
[INFO] jaxws:wsimport args: [-s, ---/ /HelloWorldWebServiceExperiment/target/jaxws/wsimport/java, -d, ---/HelloWorldWebServiceExperiment/target/classes, -verbose, -Xnocompile, ---/HelloWorldWebServiceExperiment/target/jaxws/wsgen/wsdl/HelloWorldWebServiceExperiment.wsdl]
parsing WSDL...
generating code...
training/webservice/HelloWorld.java
training/webservice/HelloWorldResponse.java
training/webservice/HelloWorldWebServiceExperiment.java
training/webservice/HelloWorld_Type.java
training/webservice/ObjectFactory.java
training/webservice/package-info.java
[INFO] [resources:testResources {execution: default-testResources}]
[WARNING] Using platform encoding (UTF-8 actually) to copy filtered resources, i.e. build is platform dependent!
[INFO] skip non existing resourceDirectory ---/HelloWorldWebServiceExperiment/src/test/resources
[INFO] [compiler:testCompile {execution: default-testCompile}]
[INFO] Nothing to compile - all classes are up to date
[INFO] [surefire:test {execution: default-test}]
[INFO] No tests to run.
[INFO] [war:war {execution: default-war}]
[INFO] Packaging webapp
[INFO] Assembling webapp[HelloWorldWebServiceExperiment] in [---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT]
[INFO] Processing war project
[INFO] Copying webapp webResources[---/HelloWorldWebServiceExperiment/src/main/webapp/WEB-INF] to[---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT]
[INFO] Copying webapp resources[---/HelloWorldWebServiceExperiment/src/main/webapp]
[INFO] Webapp assembled in[33 msecs]
[INFO] Building war: ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war
[INFO] [jar:jar {execution: package-wsclient-jars}]
[WARNING] JAR will be empty - no content was marked for inclusion!
[INFO] Building jar: ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar
[INFO] [install:install {execution: default-install}]
[INFO] Installing ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war to ~/.m2/repository/training/webservice/HelloWorldWebServiceExperiment/1.0-SNAPSHOT/HelloWorldWebServiceExperiment-1.0-SNAPSHOT.war
[INFO] Installing ---/HelloWorldWebServiceExperiment/target/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar to ~/.m2/repository/training/webservice/HelloWorldWebServiceExperiment/1.0-SNAPSHOT/HelloWorldWebServiceExperiment-1.0-SNAPSHOT-wsclient.jar
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESSFUL
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 2 seconds
[INFO] Finished at: Tue Aug 25 09:31:20 CEST 2015
[INFO] Final Memory: 32M/487M
[INFO] ------------------------------------------------------------------------
EDIT (for precision): When I try use the stub archive in another project to create a webclient, (i do this with intellij idea), idea automatically finds the file from my maven repository and suggests it to me, generating the following dependency:
<dependency>
<groupId>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0-SNAPSHOT-wsclient</version>
</dependency>
however none of the genereated .java files can actually be imported and used in code! E.g. idea fails on usage or import
import training.webservice.HelloWorld;
private training.webservice.HelloWorld helloWorld;
with the error message "Cannot resolve symbol 'HelloWorld'"
What am I doing wrong? Is this connected to the fact that my stub only contains .java files, but no .class files? Obviously the plugin jaxws-maven-plugin runs wsimport with the -xnocompile flag, but I haven't been able to figure out how to configure maven not to do that, none of the options keep, destDir or sourceDestDir have had any effect on that! Or is this completely irrelevant, as the project importing the stubs should be able to compile them itself and the problem is somewhere else? Any help would be greatly appreciated!
I found a temporary work arround:
I generate a client stub .jar file manually. As my company still works with Java 1.5, I had to install metro in order to use wsimport (I chose version 1.6.2) and then I could call:
wsimport target/generated-sources/wsdl/HelloWorldWebServiceExperiment.wsdl -d target/generated-sources/wsdl/ -keep
afterwards I had .java and .class files which I could manually package into a .jar file, then I moved that .jar into the ressource folder of my webservice client project and manually added the dependency into my pom.xml:
<dependency>
<groupId>training.webservice</groupId>
<artifactId>HelloWorldWebServiceExperiment</artifactId>
<version>1.0</version>
<scope>system</scope>
<systemPath>${project.basedir}/src/main/resources/client.jar</systemPath>
</dependency>
I would prefer an automatic build and deploy from maven, and I am now sure that the problem must lie within my maven setup, however I have still no clue how to do it any better. At least I can continue working on the webservice client for now, and revisit the issue at a later point again!
I am having a problem with some functionality I need configured.
Here is a part of my POM, where I configured a project to be assembled into two different files: FirstNameProject-VERSION-bin.zip and SecondNameProject-VERSION-bin.zip.
The idea is that I had to maintain those names set, even if the original artefact is common.
<?xml version="1.0" encoding="UTF-8"?>
http://maven.apache.org/xsd/maven-4.0.0.xsd">
4.0.0
<groupId>com.project.my</groupId>
<artifactId>MyGenericProject</artifactId>
<name>Generic Project</name>
<version>2.0.2-SNAPSHOT</version>
...
<build>
<plugins>
....
<plugin>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.2.1</version>
<executions>
<execution>
<id>first</id>
<configuration>
<finalName>FirstNameProject-${project.version}-bin</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/resources_first.xml</descriptor>
</descriptors>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
<execution>
<id>second</id>
<configuration>
<finalName>FirstNameProject-${project.version}-bin</finalName>
<appendAssemblyId>false</appendAssemblyId>
<descriptors>
<descriptor>src/main/assembly/resources_second.xml</descriptor>
</descriptors>
</configuration>
<phase>package</phase>
<goals>
<goal>single</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
This is working properly and in the mvn package logs I can see:
[INFO] --- maven-assembly-plugin:2.2.1:single (first) # MyGenericProject ---
[INFO] Reading assembly descriptor: src/main/assembly/resources_first.xml
[INFO] Building zip: C:\MyPath\MyProject_trunk\target\FirstNameProject-2 .0.2-bin.zip
[INFO]
[INFO] --- maven-assembly-plugin:2.2.1:single (second) # MyGenericProject ---
[INFO] Reading assembly descriptor: src/main/assembly/resources_second.xml
[INFO] Building zip: C:\MyPath\MyProject_trunk\target\SecondNameProject-2.0 .2-bin.zip
The problem is that, at during install, it just reverts to the generic name and install the the rightly named file as the Generic one!
[INFO] --- maven-install-plugin:2.3.1:install (default-install) # MyGenericProject ---
[INFO] Installing C:\MyPath\MyProject_trunk\target\MyGenericProject-2.0.2-SNAPSHOT.jar to C:.m2\repository\com\project\my\MyGenericProject\2.0.2-SNAPSHOT\MyGenericProject-2.0.2-SNAPSHOT.jar
[INFO] Installing C:\MyPath\MyProject_trunk\pom.xml to C:.m2\repository\com\project\my\MyGenericProject\2.0.2-SNAPSHOT\MyGenericProject-2.0.2-SNAPSHOT.pom
[INFO] Installing C:\MyPath\MyProject_trunk\target\FirstNameProject-2.0.2-SNAPSHOT-bin.zip to C:.m2\repository\com\project\my\MyGenericProject\2.0.2-SNAPSHOT\MyGenericProject-2.0.2-SNAPSHOT.zip
I am imagining that this is because the install plugin has no visibility on exactly how the assembly plugin was configured so I ask you: how can I configure the install plugin so that I will end up with FirstNameProject-VERSION-bin.zip and SecondNameProject-VERSION-bin.zip installed in my repository??
I hope I was clear enough,
Thanks
It sounds like Maven is "attaching" the assembly artifact to the project under the default name. The first option is to scour the assembly plugin configuration to see if there's a way to control this. Looking through it myself, I don't see a way to do this. I would have thought it would have used your final name configuration, but if it doesn't, it doesn't.
The workaround I can offer, and I would hope someone can offer something more standard, is to configure the assembly to NOT attach itself.
Next, take the file it creates, the one with the name you want, and use the build-helper plugin to attach the file under the precise coordinates that you want.
I need to set a property in maven pom.xml file which should be a UUID. Can anybody tell me
what is the best possible way to set a property to UUID?
I am using a profile which launch the gigaspaces and gigaspaces requires group name which I
want to be unique(uuid). So, in my profile I want to set a groupName property value which
should change for each build. I wrote a UUIDGenerator plugin myself as I didn't found any.
So, I am looking How can this be achieved? Is writing a plugin better option or there is an
easier option.
Thanks,
Shekhar
Arian's solution (implementing a maven plugin) is IMO a clean way to implement your requirement (and +1 for his answer).
But if you don't plan to reuse your plugin somewhere else, a quick alternative would be to hack the pom using the GMavenPlus plugin. Here is an example showing how to do so using a Java class from a library to generate some uuid and set it as a property:
<project>
<modelVersion>4.0.0</modelVersion>
<groupId>com.stackoverflow</groupId>
<artifactId>Q3984794</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.safehaus.jug</groupId>
<artifactId>jug</artifactId>
<version>2.0.0</version>
<!-- the classifer is important!! -->
<classifier>lgpl</classifier>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
...
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.codehaus.gmaven</groupId>
<artifactId>gmaven-plugin</artifactId>
<version>1.3</version>
<executions>
<execution>
<id>set-custom-property</id>
<phase>initialize</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<classpath>
<element>
<groupId>org.safehaus.jug</groupId>
<artifactId>jug</artifactId>
<classifier>lgpl</classifier>
</element>
</classpath>
<source>
import org.safehaus.uuid.UUIDGenerator
def uuid = UUIDGenerator.getInstance().generateRandomBasedUUID()
project.properties.setProperty('groupName', uuid.toString())
</source>
</configuration>
</execution>
<execution>
<id>show-custom-property</id>
<phase>generate-resources</phase>
<goals>
<goal>execute</goal>
</goals>
<configuration>
<source>
def props = project.properties
props.each {key, value -> println key + "=" + value}
</source>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Just bind the plugin to a phase prior to the gigaspaces stuff.
The second execution is just there for demonstration purpose (to show the properties):
$ mvn generate-resources
[INFO] Scanning for projects...
[INFO]
[INFO] ------------------------------------------------------------------------
[INFO] Building Q3984794 1.0-SNAPSHOT
[INFO] ------------------------------------------------------------------------
[INFO]
[INFO] --- gmaven-plugin:1.3:execute (set-custom-property) # Q3984794 ---
[INFO]
[INFO] --- gmaven-plugin:1.3:execute (show-custom-property) # Q3984794 ---
downloadSources=true
downloadJavadocs=true
project.reporting.outputEncoding=UTF-8
project.build.sourceEncoding=UTF-8
groupName=814ff1a5-a102-426e-875c-3c40bd85b737
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
...
First of all, if your set up requires something called "group name", you probably should provide a meaningful value. If it has to be unique, you can append some generated characters, like "MyApplication-10937410". Also, using a UUID seems to me like using a sledge-hammer to crack a nut. But this is independent of your actual problem, so here is the solution I propose:
If you have not already done so, create a maven plugin (there's an archetype for that). Add this dependency:
<dependency>
<groupId>org.apache.maven</groupId>
<artifactId>maven-project</artifactId>
<version>2.2.1</version>
</dependency>
This is how your MOJO should look like:
/**
* Goal which generates a group name.
*
* #goal generate
* #phase initialize
*/
public class GroupNameGeneratorMojo extends AbstractMojo {
/**
* #parameter expression="${project}"
* #required
* #readonly
*/
private MavenProject project;
#Override
public void execute() throws MojoExecutionException {
String groupName = ... ;
project.getProperties().setProperty("uniqueGroupName", groupName);
}
}
In your actual projects pom, use ${uniqueGroupName} whereever you need it and configure your plugin like this
<build>
<plugins>
<plugin>
<groupId>the.plugin.groupid</groupId>
<artifactId>groupNameGenerator</artifactId>
<executions>
<execution>
<goals><goal>generate</goal></goals>
</execution>
</executions>
<plugin>
There is https://github.com/stevespringett/maven-uuid-generator which exposes a uuid for the build as ${project.build.uuid}. You can use it like
<plugins>
<plugin>
<groupId>us.springett</groupId>
<artifactId>maven-uuid-generator</artifactId>
<version>1.0.1</version>
<executions>
<execution>
<phase>initialize</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>