Code-changes in dependencies are not updated automatically - eclipse

I'm having some dependencies in my projects which I'm including in my pom.xml:
<packaging>war</packaging>
<dependencies>
<dependency>
<groupId>com.mahlzeit</groupId>
<artifactId>mz-data-model</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>mz-web-shared</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
However, my problem is that changes in the code of these projects are not visible to my web server when I'm running it.
I always have to run
mvn clean install
in mz-web-shared/ and mz-data-model/ such that the jar files are getting compiled and the repository updated.
Why do I have to do that and how can I make this work without me having to run mvn clean install manually in my dependencies?

Related

SAP jscoverage-plugin does not work on new Java/JDK

I have run the auto test of my UI5 app locally successfully. When I tried to generate the cobertura coverage report with:
mvn verify -f pom.xml com.sap.ca:jscoverage-plugin:1.36.0:jscoverage
I got following error.
[ERROR] Failed to execute goal
com.sap.ca:jscoverage-plugin:1.36.0:jscoverage (default-cli) on
project sap.support.sccd: Execution default-cli of goal
com.sap.ca:jscoverage-plugin:1.36.0:jscoverage failed: A required
class was missing while executing
com.sap.ca:jscoverage-plugin:1.36.0:jscoverage:
javax/xml/bind/JAXBException
The javax is not available in JDK>7 anymore for a such long time. Why SAP jscoverage-plugin still use it? Is there any method to get rid of the issue.
I have tried all following dependencies with version 2.3.2 and 3.0.0 in my pom:
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>2.3.2</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>jakarta.xml.bind</groupId>
<artifactId>jakarta.xml.bind-api</artifactId>
<version>2.3.2</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.2</version>
<scope>runtime</scope>
</dependency>
However, they can't solve the problem.
How can I mitigate the issue and go on cobertura coverage report generation with this plugin?

model.ecore is not generated project\target\classes\package\gen\model\impl during maven 'clean install' goal

I'm trying to create a Maven emf project, which can be packaged into a standalone jar, so that other projects can use it.
What I have did so far.
Created a Maven project and created the ECore model and created it's genModel file.
Now, I would like to package this project into a jar, so, that other projects can work on it.
When I run the goal 'clean install' the jar file is being created.
when I add this artifact as dependency and try to access any model object, it get the below exception
Caused by: java.lang.RuntimeException: Missing serialized package: model.ecore
at model.impl.ModelPackageImpl.loadPackage(TSGPackageImpl.java:13231) ~[sample.model-1.0.0.jar:1.0.0]
at model.impl.ModelPackageImpl.init(ModelPackageImpl.java:2792) ~[sample.model-1.0.0.jar:1.0.0]
at model.ModelPackage.<clinit>(ModelPackage.java:60) ~[sample.model-1.0.0.jar:1.0.0]
While searching for that specific issue, I understood that the model.ecore file should be present under the model.impl package, from below links:
Missing serialized package: uml.ecore
XSD to EMF Cannot Find *ecore File
java.lang.RuntimeException: Missing serialized package: TestSchema.ecore
-> Whenever the 'clean install' goal is run in maven, the folder 'project\target\classes' is fully cleaned and the class files are generated. But, I could not find the model.ecore file in the 'project\target\classes\package\gen\model\impl' folder. is there a specific way I can generate so that mode.ecore, after cleaning?
-> When I try 'project-> clean project' in eclipse, then, the 'project\target\classes' is fully cleaned and the class files along with mode.ecore files are generated.
-> is some EMF builder is not run during the 'clean install' goal?
-> Could someone point a way to generate the model.ecore file, during 'clean install' goal?
The project's 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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.0</version>
</parent>
<packaging>jar</packaging>
<artifactId>sample.model</artifactId>
<dependencies>
<!-- Emf dependencies -->
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.common</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore.xmi</artifactId>
<version>2.15.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.ecore.change</artifactId>
<version>2.13.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.emf</groupId>
<artifactId>org.eclipse.emf.edit</artifactId>
<version>2.14.0</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot</artifactId>
</dependency>
</dependencies>

How to integrate JUnit 5 with an existing Eclipse project?

The existing Eclipse project uses Maven but does not know about JUnit. Should/can I integrate JUnit into the existing project or should I make a new project dedicated to JUnit or is there a better option?
You can add JUnit5 to that project by including the following dependencies in the pom.xml:
<properties>
<junit.jupiter.version>5.0.1</junit.jupiter.version>
<junit.platform.version>1.0.1</junit.platform.version>
</properties>
<!--
JUnit5 dependencies:
* junit-jupiter-api: for writing JUnit5 tests
* junit-jupiter-engine: for running JUnit5 tests
* junit-platform-xxx: the foundation for JUnit5
* (Optionally) you might want to include junit-vintage-engine for running JUnit4 tests
-->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-launcher</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>
To enable Maven Surefire to run JUnit5 tests just include the following plugin definition in the pom.xml:
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>${maven.surefire.plugin.version}</version>
<configuration>
<excludes>
<exclude>**/MongoPopulatorTool.java</exclude>
</excludes>
</configuration>
<dependencies>
<!-- integrates JUnit5 with surefire -->
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-surefire-provider</artifactId>
<version>${junit.platform.version}</version>
</dependency>
<!-- ensures that a JUnit5-aware test engine is available on the classpath when running Surefire -->
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>${junit.jupiter.version}</version>
</dependency>
</dependencies>
</plugin>
And, finally, to enable Eclipse's test runner to run JUnit5 tests you must be running Eclipse Oxygen.1a (4.7.1a) release (or later), have a look at the Eclipse docs.
The other answer gives the technical answer how to add JUnit to your project setup.
But sorry, the real answer is: don't add your unit tests to your other project. Create a new one instead.
One of the most important rules when doing development is the Single Responsibility Principle. Any class/method/xyz should be doing one thing.
In other words: your existing eclipse project has the responsibility to provide the context for your "product". Providing context for testing is a different responsibility.
And beyond that, you should always follow "best practices". And best practice is again to not have test and production code within the same project.
You see, you absolutely do not want that your test source code sits in the same directory as your production code. Therefore, you have two projects, that can both use the same packages - but have their source code sitting in different folders!
( the reason why you don't want to have that: you only want to allow your tests to depend from your production code. but when files sit in the same directory, you might inadvertently create dependencies in the other direction )

The maven project generated by gwt-maven-plugin can't be imported into eclipse via import existing maven project

I firstly generated a gwt maven project by executing --
mvn archetype:generate -DarchetypeGroupId=org.codehaus.mojo
-DarchetypeArtifactId=gwt-maven-plugin -DarchetypeVersion=2.7.0
After that, the pom.xml is as follows:
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.boye.games</groupId>
<artifactId>games-gwt</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>GWT Maven Archetype</name>
<properties>
<!-- Convenience property to set the GWT version -->
<gwtVersion>2.7.0</gwtVersion>
<!-- GWT needs at least java 1.6 -->
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt</artifactId>
<version>${gwtVersion}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-servlet</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-user</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.google.gwt</groupId>
<artifactId>gwt-dev</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<!-- Output classes directly into the webapp, so that IDEs and "mvn process-classes" update them in DevMode -->
<outputDirectory>${project.build.directory}/${project.build.finalName}/WEB-INF/classes</outputDirectory>
<plugins>
<!-- GWT Maven Plugin -->
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>gwt-maven-plugin</artifactId>
<version>2.7.0</version>
<executions>
<execution>
<goals>
<goal>compile</goal>
<goal>test</goal>
<goal>generateAsync</goal>
</goals>
</execution>
</executions>
<!-- Plugin configuration. There are many available options, see
gwt-maven-plugin documentation at codehaus.org -->
<configuration>
<runTarget>LineThree.html</runTarget>
<modules>
<module>com.boye.games.linethree.LineThree</module>
</modules>
</configuration>
</plugin>
</plugins>
</build>
</project>
Then I imported this project into eclipse via built-in eclipse function -- import existing Maven project.
However, the process failed due to several reasons:
GreetingServiceAsync cannot be resolved to a type
Execution default of goal org.codehaus.mojo:gwt-maven-plugin:2.7.0:generateAsync failed:
Plugin org.codehaus.mojo:gwt-maven-plugin:2.7.0 or one of its
dependencies could not be resolved: Failed to collect dependencies for
org.codehaus.mojo:gwt-maven-plugin:jar:2.7.0 ()
(org.codehaus.mojo:gwt-maven-plugin:2.7.0:generateAsync:default:generate-sources)
google plugin can't identify this project as gwt web application automatically.
My environment as follows:
java version 1.7.0_03
eclipse version Kepler Service Release 2
gwt version 2.7.0
Please advice, thanks a lot!
I did another attempt to try in a win32 computer, the problem re-appeared even if I set up the environment as aforementioned working in my win64 computer.
So I really got confused, like Klarki said, I have to do some tweaks to get it work. I generated GreetingServiceAsync via mvn gwt:generateAsync then manually copy GreetingServiceAsync to source folder, then I remove <goal>generateAsync</goal> in pom.xml, then import project via eclipse's existing maven project. It works again!
Sadly see it not working intelligently.
The problem was with generateAsync, which in your case generates GreetingServiceAsync on execution. Eclipse probably wasn't configured to handle it properly and this class was not generated and eclipse reported the missing class warning.
Another thing that could be done to get the project to work was to run mvn package from command line and add the generated dir in target dir as source dir in eclipse (vie right clicking the project and selecting New -> source folder > browsing folder name > target > generated-sources > the right folder)
Also you may run into same issue after you do mvn clean - the generated GreetingServiceAsync will be deleted and the problem may come back.
The problem exists because eclipse isn't tightly integrated with maven and uses its own build system ignoring maven targets that you don't have plugins for. What you could do is to open eclipse preferences > maven > lifecycle mappings and there you can enable generateAsync to execute.
If you copy the generated class manually you have to keep in mind that you need to update it when needed, where as it is intended to generate automatically. So you loose this convenience.
This work for me:
I deleted the local maven gwt repository, in windows 7 it's in C:\Users\.m2\repository\com\google\gwt, and then make a
mvn clean complile
so maven re-import al dependencys.
After I changed my environment as follows:
java version "1.8.0_05"
eclipse Version: Luna Release (4.4.0)
Google plugin for Eclipse 4.4
I works like a charm.
Probably, it's a version incompatibility issue.

Maven generates old and unwanted RichFaces jars

I have a JSF 2.0 project and when I run 'mvn package' from eclipse (right click on the pom file and run) I get the war file with older versions of the richfaces jars along with the latest jars as shown in the image below.
pom.xml:
<properties>
<org.richfaces.bom.version>4.3.4.Final</org.richfaces.bom.version>
</properties>
<dependencies>
<!-- Mojarra implementation of JSF spec 2.2 -->
<dependency>
<groupId>org.glassfish</groupId>
<artifactId>javax.faces</artifactId>
<version>2.1.6</version>
</dependency>
<dependency>
<groupId>org.richfaces</groupId>
<artifactId>richfaces-bom</artifactId>
<version>${org.richfaces.bom.version}</version>
<scope>import</scope>
<type>pom</type>
</dependency>
<dependency>
<groupId>org.richfaces.ui</groupId>
<artifactId>richfaces-components-ui</artifactId>
<version>${org.richfaces.bom.version}</version>
</dependency>
<dependency>
<groupId>org.richfaces.core</groupId>
<artifactId>richfaces-core-impl</artifactId>
<version>${org.richfaces.bom.version}</version>
</dependency>
</dependencies>
How can I fix this? Any help would be appreciated.
Suggest you to install maven outside of eclipse and try to run 'mvn package' from command line and see if you encounter the same problem in this way as well.
You may also create a 'New Launch Configuration' in eclipse for running mvn package from inside eclipse. To do this, right click on the pom.xml file > Run as > Run configuration ...
Hit 'New launch configuration'. This will take care of any mis-configuration you might have done inadvertently in your earlier launch configuration.