Both sides previous revision
Previous revision
Next revision
|
Previous revision
|
devel:documentation:quickstart:dev:ide:eclipse [2022/08/01 11:42] janatam |
devel:documentation:quickstart:dev:ide:eclipse [2024/01/09 08:27] (current) koulaj [Install Tomcat] |
export JAVA_HOME=/path/to/installed/jdk/ | export JAVA_HOME=/path/to/installed/jdk/ |
./eclipse | ./eclipse |
| |
| |
</code> | </code> |
**Note:** If you don't set metamodel generation, you will see Java problems like ''ExampleProduct_ cannot be resolved to a variable''. | **Note:** If you don't set metamodel generation, you will see Java problems like ''ExampleProduct_ cannot be resolved to a variable''. |
| |
* Go to Project → Properties → Java Compiler → Annotation Processing → check "Enable project specific settings" and fill "Generated source directory" = "target/metamodel". | * Go to Project → Properties → Java Compiler → Annotation Processing → check "Enable project specific settings" and fill "Generated source directory" = "target/metamodel". |
* Go to Project → Properties → Java Compiler → Annotation Processing → Factory path → check "Enable project specific settings" and add external jar **hibernate-jpamodelgen.jar** (version 5.x.x). Artefact could be found in local maven repository or downloaded from any public maven repository. | * Go to Project → Properties → Java Compiler → Annotation Processing → Factory path → check "Enable project specific settings" and add external jar **hibernate-jpamodelgen.jar** (version 5.x.x). Artefact could be found in local maven repository or downloaded from any public maven repository. |
| |
If this solution didn't help and you still see the ''ExampleProduct_ cannot be resolved to a variable'' error, you have to build the project in command line. Go to the relevant paths (e. g., /git/CzechIdMng/Realization/backend/rpt) and run ''mvn clean install''. Do this for every directory that shows this error. | |
| |
====== Build the Project ====== | If this solution didn't help and you still see the ''ExampleProduct_ cannot be resolved to a variable'' error, you have to build the project in command line. Go to the relevant paths (e. g., /git/CzechIdMng/Realization/backend/rpt) and run ''mvn clean install''. Do this for every directory that shows this error. |
After that you can build the projects from Eclipse by Project → Build Project or you can check "Build Automatically". If you see some dependency errors try this approach: Right-click the project "idm-aggregator" and choose "Run as" → "Maven install". The first build of the project will download necessary libraries to your local Maven repository (e.g. "forest" from Nexus repository). If dependency errors still remain, for all projects: Right click on the project → Maven → Update Project… → click Select All → Click OK | |
| |
====== Install Tomcat ====== | ====== Build the Project ====== |
Download Tomcat 8.0.* (tested version 8.0.36) from Apache website. Unzip it somewhere in your home directory. | |
| |
Next we will install Tomcat as a Server to the Eclipse: Show the tab "Servers" if it isn't visible yet: Window → Show View → Servers | After that you can build the projects from Eclipse by Project → Build Project or you can check "Build Automatically". If you see some dependency errors try this approach: Right-click the project "idm-aggregator" and choose "Run as" → "Maven install". The first build of the project will download necessary libraries to your local Maven repository (e.g. "forest" from Nexus repository). If dependency errors still remain, for all projects: Right click on the project → Maven → Update Project… → click Select All → Click OK |
| |
Create new server: In the tab "Servers", right-click and choose New → Server → Apache → Tomcat v8.0 Server - Next → For „Tomcat installation directory“ select the path to the installed Tomcat directory. As "JRE" choose installed JDK. Then Next → Next → Finish. | ====== Install Tomcat ====== |
| |
Add idm-app as an application to Tomcat: Right-click on the Tomcat server, choose "Add and Remove" and select "idm-app" | Download Tomcat 9.0.* (tested version 9.0.80) from Apache website. Unzip it somewhere in your home directory. |
| |
Optionally set some other options for the server: Double-click on the Tomcat server, then | Next we will install Tomcat as a Server to the Eclipse: Show the tab "Servers" if it isn't visible yet: Window → Show View → Servers |
* in the section "Timeouts" increase the timeout for start to 240 s. | |
* in the section "Server Options", uncheck "Modules auto reload by default". | |
| |
====== Deploy changes without reloading ====== | Create new server: In the tab "Servers", right-click and choose New → Server → Apache → Tomcat v8.0 Server - Next → For „Tomcat installation directory“ select the path to the installed Tomcat directory. As "JRE" choose installed JDK. Then Next → Next → Finish. |
Small changes in code may be applied to the server without restarting the server or reloading modules (hot code replacement). This can be configured as follows: | |
- Double-click on the Tomcat server, in the section "Publishing" choose the option "Automatically publish when resources change" | |
- Switch to the "Modules" tab of the Tomcat server and choose the module "idm-app". Click the button "Edit…" and uncheck "Auto reloading enabled". After submitting you should see the value "Disabled" in the column "Auto Reload". | |
- Save changes in the Tomcat server configuration | |
- Start the Tomcat server in "DEBUG" mode. | |
| |
====== Run unit & integration tests ====== | Add idm-app as an application to Tomcat: Right-click on the Tomcat server, choose "Add and Remove" and select "idm-app" |
When you want to run unit tests, you must switch to Maven profile **test**. Otherwise some tests (especially those which use database connection) may fail. Set the "test" profile: Right click "idm-app" (or the module which you want to test) → Maven → Select Maven Profiles → check "test" | |
| |
If you want to run only tests in some class: | Optionally set some other options for the server: Double-click on the Tomcat server, then |
1) open this class, | |
2) right click on the class name, | |
3) choose Run As → JUnit Test. | |
| |
====== Common development & tips ====== | |
| |
===== Tomcat server fails to start ===== | * in the section "Timeouts" increase the timeout for start to 240 s. |
If Tomcat server fails to start, try following: | * in the section "Server Options", uncheck "Modules auto reload by default". |
* Check all common development tips | |
* Check build errors - check that the tab Markers or Problems doesn't show any Java or Maven build error. (You can ignore XML validation problems.) If it does, try updating Maven project. | |
* Try Clean/Publish actions on the Tomcat server. | |
* Try restarting Eclipse. | |
| |
The exception: '' org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationFilter': Injection of autowired dependencies failed …… very long stacktrace ……. Error creating bean with name 'flywayCore' defined in class path resource [eu/bcvsolutions/idm/core/config/flyway/CoreFlywayConfig.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Comparison method violates its general contract! '' is probably caused by a bug in Flyway. | |
| |
In such case, go to Windows → Preferences → Installed JREs→ edit JRE and add to default VM arguments ''-Djava.util.Arrays.useLegacyMergeSort=true'' | |
| |
Another possible issue may be an exception like this one: '' java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/idm-app]] Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/idm-app]] at org.apache.catalina.util.L Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [eu.bcvsolutions.idm.IdmApplication]; nested exception is java.io.FileNotFoundException: class path resource [eu/bcvsolutions/idm/test/api/AbstractIntegrationTest.class] cannot be opened because it does not exist at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:182) '' | ====== Deploy changes without reloading ====== |
| |
If you see this, make sure that | Small changes in code may be applied to the server without restarting the server or reloading modules (hot code replacement). This can be configured as follows: |
* you have the project idm-core-test-api open | |
* in Properties of the idm-core-impl (or any problematic project), check Java Build Path and make sure that each test folder has the Output folder set to test-classes. | |
{{ .:screenshot_from_2019-06-17_16-26-24.png?direct&600 }} | |
| |
See below: If you have a problem in not being able to Add and Remove, try to open idm-app, look at Properties, Project Facets and check you have the correct version of Java: {{ .:screenshot_from_2019-06-20_09-55-36.png?direct&600 }} | - Double-click on the Tomcat server, in the section "Publishing" choose the option "Automatically publish when resources change" |
| - Switch to the "Modules" tab of the Tomcat server and choose the module "idm-app". Click the button "Edit…" and uncheck "Auto reloading enabled". After submitting you should see the value "Disabled" in the column "Auto Reload". |
| - Save changes in the Tomcat server configuration |
| - Start the Tomcat server in "DEBUG" mode. |
| |
| ====== Run unit & integration tests ====== |
| |
| When you want to run unit tests, you must switch to Maven profile **test**. Otherwise some tests (especially those which use database connection) may fail. Set the "test" profile: Right click "idm-app" (or the module which you want to test) → Maven → Select Maven Profiles → check "test" |
| |
=====Update project after pulling new version ===== | If you want to run only tests in some class: |
When you pull new version of the project from Git and there were some changes including Maven dependencies (e.g. newer version of some artifact), you should update your project: | |
* select all projects | |
* right-click and choose Maven → Update Project The IDE will update dependencies and rebuild the projects if necessary. | |
| |
===== Implementing a ConnId connector ===== | |
| |
We came across problematic behavior of Eclipse when implementing a ConnId connector. If you develop the connector that is a dependency of CzechIdM and the same connector (in the same version) is opened in Eclipse, then Tomcat with CzechIdM may fail to start with the following exception: '' Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationFilter': Injection of autowired dependencies failed …. nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [eu.bcvsolutions.idm.ic.service.impl.DefaultIcConfigurationFacade]: Constructor threw exception; nested exception is java.lang.NullPointerException '' | <code> |
| 1) open this class, |
| 2) right click on the class name, |
| 3) choose Run As → JUnit Test. |
| |
If you encounter this exception and you want to use Debug server mode for implementing the connector (deploying without restarts), try the following steps: | </code> |
| |
| ====== Common development & tips ====== |
| |
| ===== Tomcat server fails to start ===== |
| |
| If Tomcat server fails to start, try following: |
| |
| * Check all common development tips |
| * Check build errors - check that the tab Markers or Problems doesn't show any Java or Maven build error. (You can ignore XML validation problems.) If it does, try updating Maven project. |
| * Try Clean/Publish actions on the Tomcat server. |
| * Try restarting Eclipse. |
| |
| The exception: '' org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationFilter': Injection of autowired dependencies failed …… very long stacktrace ……. Error creating bean with name 'flywayCore' defined in class path resource [eu/bcvsolutions/idm/core/config/flyway/CoreFlywayConfig.class]: Initialization of bean failed; nested exception is java.lang.IllegalArgumentException: Comparison method violates its general contract! '' is probably caused by a bug in Flyway. |
| |
| In such case, go to Windows → Preferences → Installed JREs→ edit JRE and add to default VM arguments ''-Djava.util.Arrays.useLegacyMergeSort=true'' |
| |
| Another possible issue may be an exception like this one: '' java.util.concurrent.ExecutionException: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/idm-app]] Caused by: org.apache.catalina.LifecycleException: Failed to start component [StandardEngine[Catalina].StandardHost[localhost].StandardContext[/idm-app]] at org.apache.catalina.util.L Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: Failed to parse configuration class [eu.bcvsolutions.idm.IdmApplication]; nested exception is java.io.FileNotFoundException: class path resource [eu/bcvsolutions/idm/test/api/AbstractIntegrationTest.class] cannot be opened because it does not exist at org.springframework.context.annotation.ConfigurationClassParser.parse(ConfigurationClassParser.java:182) '' |
| |
| If you see this, make sure that |
| |
| * you have the project idm-core-test-api open |
| * in Properties of the idm-core-impl (or any problematic project), check Java Build Path and make sure that each test folder has the Output folder set to test-classes. |
| |
| {{ .:screenshot_from_2019-06-17_16-26-24.png?direct&600 }} |
| |
| See below: If you have a problem in not being able to Add and Remove, try to open idm-app, look at Properties, Project Facets and check you have the correct version of **Java ** (should be 11) abd **Dynamic Web Module ** (3.1): {{ .:screenshot_from_2019-06-20_09-55-36.png?direct&600 }} |
| |
| ===== Maven build passes, but Eclipse shows errors ===== |
| |
| It can happen that Maven builds the project fine, but eclipse Project -> Clean will throw an error, such as: |
| |
| <code>Description Resource Path Location Type |
| Failed to execute mojo org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy {execution: copy} (org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy:copy:compile) |
| |
| org.eclipse.core.runtime.CoreException: Failed to execute mojo org.apache.maven.plugins:maven-dependency-plugin:3.1.1:copy {execution: copy} |
| at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeMojo(MavenExecutionContext.java:340) |
| at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.lambda$0(MavenExecutionContext.java:291) |
| at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.executeBare(MavenExecutionContext.java:394) |
| at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:275) |
| at org.eclipse.m2e.core.internal.embedder.MavenExecutionContext.execute(MavenExecutionContext.java:290) |
| at org.eclipse.m2e.core.project.configurator.MojoExecutionBuildParticipant.build(MojoExecutionBuildParticipant.java:57) |
| at org.eclipse.m2e.core.internal.builder.MavenBuilderImpl.lambda$2(MavenBuilderImpl.java:153) |
| |
| </code> |
| |
| In that case, update the Maven project (right click project -> Maven -> Update Project. |
| |
| ===== Update project after pulling new version ===== |
| |
| When you pull new version of the project from Git and there were some changes including Maven dependencies (e.g. newer version of some artifact), you should update your project: |
| |
| * select all projects |
| * right-click and choose Maven → Update Project The IDE will update dependencies and rebuild the projects if necessary. |
| |
| ===== Implementing a ConnId connector ===== |
| |
| We came across problematic behavior of Eclipse when implementing a ConnId connector. If you develop the connector that is a dependency of CzechIdM and the same connector (in the same version) is opened in Eclipse, then Tomcat with CzechIdM may fail to start with the following exception: '' Exception encountered during context initialization - cancelling refresh attempt: org.springframework.context.ApplicationContextException: Unable to start embedded container; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'authenticationFilter': Injection of autowired dependencies failed …. nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [eu.bcvsolutions.idm.ic.service.impl.DefaultIcConfigurationFacade]: Constructor threw exception; nested exception is java.lang.NullPointerException '' |
| |
| If you encounter this exception and you want to use Debug server mode for implementing the connector (deploying without restarts), try the following steps: |
| |
| * Open **pom.xml** of the connector and add inside the tags ''<build><plugins>'': |
| |
* Open **pom.xml** of the connector and add inside the tags ''<build><plugins>'': | |
<code xml> | <code xml> |
<plugin> | <plugin> |
</configuration> | </configuration> |
</plugin> | </plugin> |
| |
</code> | </code> |
* Right-click on the project with the connector and run Maven → Update Project | |
* Right-click on the Tomcat server and run Clean or Publish | |
* Go to the deployments folder of the Tomcat server (this depends on your installation, e.g.: ''/home/user/bin/apache-tomcat-8.0.36/wtpwebapps/idm-app/WEB-INF/lib/'') and remove the folder ''META-INF/maven/'' from the JAR containing your connector: | |
<code bash> | |
cd /home/user/bin/apache-tomcat-8.0.36/wtpwebapps/idm-app/WEB-INF/lib/ | |
zip -d csv-connector-1.0.0.jar "META-INF/maven/*" | |
| |
deleting: META-INF/maven/ | * Right-click on the project with the connector and run Maven → Update Project |
deleting: META-INF/maven/eu.bcvsolutions.idm.connectors.csv/ | * Right-click on the Tomcat server and run Clean or Publish |
deleting: META-INF/maven/eu.bcvsolutions.idm.connectors.csv/csv-connector/ | * Go to the deployments folder of the Tomcat server (this depends on your installation, e.g.: ''/home/user/bin/apache-tomcat-8.0.36/wtpwebapps/idm-app/WEB-INF/lib/'') and remove the folder ''META-INF/maven/'' from the JAR containing your connector: |
deleting: META-INF/maven/eu.bcvsolutions.idm.connectors.csv/csv-connector/pom.properties | |
deleting: META-INF/maven/eu.bcvsolutions.idm.connectors.csv/csv-connector/pom.xml | <code bash> |
| cd /home/user/bin/apache-tomcat-8.0.36/wtpwebapps/idm-app/WEB-INF/lib/ |
| zip -d csv-connector-1.0.0.jar "META-INF/maven/*" |
| |
| deleting: META-INF/maven/ |
| deleting: META-INF/maven/eu.bcvsolutions.idm.connectors.csv/ |
| deleting: META-INF/maven/eu.bcvsolutions.idm.connectors.csv/csv-connector/ |
| deleting: META-INF/maven/eu.bcvsolutions.idm.connectors.csv/csv-connector/pom.properties |
| deleting: META-INF/maven/eu.bcvsolutions.idm.connectors.csv/csv-connector/pom.xml |
</code> | </code> |
| |