Eclipse launch configuration: resolve active profiles in project - java

I have several .launch files for Eclipse (I'm using Eclipse Oxygen), here is an example
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<launchConfiguration type="org.eclipse.m2e.Maven2LaunchConfigurationType">
<booleanAttribute key="M2_DEBUG_OUTPUT" value="false" />
<stringAttribute key="M2_GOALS" value="clean com.google.cloud.tools:appengine-maven-plugin:deploy" />
<booleanAttribute key="M2_NON_RECURSIVE" value="false" />
<booleanAttribute key="M2_OFFLINE" value="false" />
<stringAttribute key="M2_PROFILES" value="" />
<listAttribute key="M2_PROPERTIES" />
<stringAttribute key="M2_RUNTIME" value="EMBEDDED" />
<booleanAttribute key="M2_SKIP_TESTS" value="true" />
<intAttribute key="M2_THREADS" value="1" />
<booleanAttribute key="M2_UPDATE_SNAPSHOTS" value="false" />
<stringAttribute key="M2_USER_SETTINGS" value="" />
<booleanAttribute key="M2_WORKSPACE_RESOLUTION" value="false" />
<stringAttribute key="org.eclipse.jdt.launching.WORKING_DIRECTORY" value="${project_loc}" />
</launchConfiguration>
Note that I'm using ${project_loc} variable in order to make it usable for any project.
I'm using this kind of files because I can share those with my team. Also the most used Maven Build configurations are ready to go w/o configuring every time a new launch profile.
The problem I'm facing is related to the profile value
<stringAttribute key="M2_PROFILES" value="" />
With the CTRL+ALT+P shortcut on a project, I can select the proper profile to load (Select Maven Profiles... function). I'm using different profile to discern the environment for the deploy (development, stage o production).
I'm trying to "inject" the profile I enabled for the project into the generic launch profile configuration, something like the ${project_loc} variable but related to the current Maven profile.
If this cannot be made I need to create a launch profile for each environment, which means 3 files per every goal to launch.
Is there a way to use/create an Eclipse variable that can be resolved with the Maven profile I activated on the project?
Something like
<stringAttribute key="M2_PROFILES" value="${maven.profile.id}" />

You'll need to create an Eclipse plugin (or contribute to Eclipse m2e project) in order to define a variable using the dedicated extension-point.

Related

WASX7109E: Insufficient data for install task "MapResRefToEJB

I have a web application which is installed on Websphere with WAR file. I am trying to automatically deploy the webapplication on websphere through a python script. The script is as follows:
###cat deplApps.py
import time
#the 3 arguments are jvm name, ent app name, and path to war file
print "Args are:" , sys.argv
SERVERMBEAN = AdminServerManagement.queryMBeans("AppSrvNode01", sys.argv[0] , "Server")
if SERVERMBEAN == [] :
print "Server is in stopped state"
else :
AdminServerManagement.stopSingleServer("AppSrvNode01", sys.argv[0] )
print "sleeping for 10 seconds"
time.sleep(10)
AdminApplication.updateApplicationUsingDefaultMerge( sys.argv[1], sys.argv[2] )
AdminConfig.save()
time.sleep(10)
Sync1 = AdminControl.completeObjectName('type=NodeSync,process=nodeagent,node=AppSrvNode01,*')
AdminControl.invoke(Sync1, 'sync')
print "sleeping for 120 seconds before starting the server"
time.sleep(120)
AdminServerManagement.startSingleServer("AppSrvNode01", sys.argv[0] )
When I run the script to deploy the war file on Websphere I get the following error:
Exception: <type 'com.ibm.ws.scripting.ScriptingException'> com.ibm.ws.scripting.ScriptingException: WASX7109E: Insufficient data for install task "MapWebModToVH
ADMA0010E: Validation error in task Selecting virtual hosts for Web modules. A virtual host is not specified for web module Work Queues with URI agriworxAPP.war,WEB-INF/web.xml."
WASX7017E: Exception received while running file "/apps/deploy/deplApps.py"; exception information: com.ibm.ws.scripting.ScriptingException: WASX7109E: Insufficient data for install task "MapWebModToVH
When I searched for the error it said I have to provide the ibm-web-bnd.xml ibm-web-ext.xml in the WAR file, So I provided the fillowing ibm-web-bnd.xml and ibm-web-ext.xml files inthe WAR file;
ibm-web-bnd.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-bnd
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-bnd_1_0.xsd"
version="1.0">
<virtual-host name="default_host"
<resource-ref>
<description>Work Queues</description>
<res-ref-name>jdbc/WorkQueuestDS</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>/>
</web-bnd>
ibm-web-ext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-ext
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="https://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-web-ext_1_0.xsd"
version="1.0">
<default-error-page uri="error.jsp"/>
<jsp-attribute name="useThreadTagPool" value="true" />
<jsp-attribute name="verbose" value="false" />
<jsp-attribute name="deprecation" value="false" />
<jsp-attribute name="reloadEnabled" value="true" />
<jsp-attribute name="reloadInterval" value="5" />
<jsp-attribute name="keepgenerated" value="true" />
<jsp-attribute name="trackDependencies" value="true" />
<reload-interval value="9"/>
<auto-encode-requests value="true"/>
<auto-encode-responses value="false"/>
<enable-directory-browsing value="false"/>
<enable-file-serving value="false"/>
<pre-compile-jsps value="false"/>
<enable-reloading value="true"/>
<enable-serving-servlets-by-class-name value="true"/>
</web-ext>
Now I am getting the following errorL
Exception: <type 'com.ibm.ws.scripting.ScriptingException'> com.ibm.ws.scripting.ScriptingException: WASX7109E: Insufficient data for install task "MapWebModToVH
ADMA0010E: Validation error in task Selecting virtual hosts for Web modules. A virtual host is not specified for web module Work Queues with URI agriworxAPP.war,WEB-INF/web.xml."
In my case, I was having this error because my app required some bindings to be made. As I wanted to install the app with all the default configurations I just needed to add the parameter -usedefaultbindings.
AdminApp.install("/work/shared/myApp.ear", "-appname myApp -node DefaultNode01 -server server1 -nouseMetaDataFromBinary -usedefaultbindings")
This error has nothing to do with .bnd or .ext files. The command AdminApplication.updateApplicationUsingDefaultMerge as it name stats is used to update existing app, not to install new one. If you want to install you need to use AdminApplication.installXXX commands. Check https://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/rxml_7libapp.html So you need to utilize AdminApplication.checkIfAppExists command and based on that either install or update app.
VH is virtual host on your WAS, typically default_host. Sometimes it is used to customize installation see this https://www.ibm.com/support/knowledgecenter/SSEQTP_8.5.5/com.ibm.websphere.base.doc/ae/rxml_taskoptions.html#rxml_taskoptions__cmd61 but I dont know how the AdminApplication is actually utilizing it.

Ant Multiple Property Values with the Same Name

I am working on an ant build script. How do i set the two property value with the same name:
<property name="java.src.dir" location="src" />
<property name="java.src.dir" location="src/java" />
In my application some of the directories are src/java and some are src. I need to make it flexible enough to work on both.

How to use Vaadin add-on with Spring Boot?

I'm using Vaadin 7.6.3 with Spring Boot. I'm trying to use the PopupButton add-on (but I don't think the issue is specific to the add-on).
I added the add-on as a dependency to gradle. This is the code for creating a PopupButton:
PopupButton btn = new PopupButton("Test Button");
btn.setContent(new Label("Test"));
layout.addComponent(btn);
Via the Vaadin plugin for Gradle I ran the task vaadinCompile which created the file src/main/resources/addon/client/ListaideWidgetset.gwt.xml and serveral files in src/main/webapp/VAADIN/gwt-unitCache and
src/main/webapp/VAADIN/widgetsets/addon.client.ListaideWidgetset. I also added #Widgetset("addon.client.ListaideWidgetset") to my UI. I confirmed that the widgetset is used via the client's ?debug mode.
Content of ListaideWidgetset.gwt.xml:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE module PUBLIC "-//Vaadin//DTD Vaadin 7//EN" "https://raw.github.com/vaadin/gwt/master/distro-source/core/src/gwt-module.dtd">
<!-- WS Compiler: manually edited -->
<module>
<inherits name="com.vaadin.DefaultWidgetSet" />
<set-configuration-property name="devModeRedirectEnabled" value="true" />
<set-property name="user.agent" value="ie8,ie9,gecko1_8,safari,ie10" />
<source path="client" />
<source path="shared" />
<collapse-all-properties />
<set-property name="compiler.useSymbolMaps" value="true" />
</module>
The problem is that on the client the button shows up as a standard button (no chevron) and doesn't open a popup when clicked.
Your widgetset does not contain the addon. See the the example:
<inherits name="org.vaadin.hene.popupbutton.widgetset.PopupbuttonWidgetset" />
Once added, recompile the widgetset, restart your application.
Usually the gradle plugin can handle this for you, but that feature can be disabled and or some other configuration error could prevent it. Hard to tell without the build.gradle...
edit
The gradle vaadin plugin seems not to be able to handle this addon properly. As a workaround disable the automatic management for widgetset, which prevents regeneration of the gwt.xml. See manageWidgetset in https://github.com/johndevs/gradle-vaadin-plugin/wiki/Tasks-and-configuration-DSL). E.g. add vaadinCompile.manageWidgetset = false in your vaadin{}-block.

log4j2 how to read property variable from file into log4j2

Background: As usual we have various life cycles like dev. stage, lt, prod all these are picked at deploy time from environment variable ${lifecycle}.
So JNDI setting we stores in ${lifecycle}.properties as variable datasource.jndi.name=jdbc/xxx. As other beans are also using this properties file, it is verified that such variable is loaded & file is in classpath, but somehow I am not able to consume this variable in log4j2.xml in below JDBC Appender.
<JDBC name="DBAppender" tableName="V1_QUERY_LOG" bufferSize="4" ignoreExceptions="false">
<DataSource jndiName="${sys:datasource.jndi.name}" />
<Column name="event_date" isUnicode="false" isEventTimestamp="true" />
<Column name="log_level" isUnicode="false" pattern="%level" />
<Column name="logger" isUnicode="false" pattern="%logger" />
<Column name="message" isUnicode="false" pattern="%message" />
<Column name="exception_msg" isUnicode="false" pattern="%ex{full}" />
</JDBC>
I have tried some option like "${datasource.jndi.name}" too, or is there any way I can fit the solution in
<Properties>
<Property name="datasource.jndi.name">get datasource.jndi.name from {lifecycle}.properties</property>
</Properties>
If you are not using java system properties, but environment variables, you should not use the ${sys:variable} prefix, but the ${env:variable} prefix instead. See also http://logging.apache.org/log4j/2.x/manual/lookups.html#EnvironmentLookup
In general the placeholders that work in Spring bean configuration files do not work in Log4j configuration. They look the same, but the syntax and underlying discovery mechanism are completely different.
For instance ${sys:something} attempts to resolve a Java system property. System properties are usually passed to JVM as command line arguments in format -Dkey=value and not stored in property files.
You can try to use Resource bundle syntax ${bundle:MyProperties:MyKey} however this will load from that specific file and will not perform any additional Spring substitutions.
See also:
http://logging.apache.org/log4j/2.x/manual/configuration.html#PropertySubstitution

Hibernate Second Level Cache and Hudson

I'm using SecondLevelCache with hibernate. This is my xml configuration file:
<persistence-unit name="EntityTestHibernate" transaction-type="RESOURCE_LOCAL">
<properties>
<property name="hibernate.show_sql" value="false"/>
<property name="hibernate.format_sql" value="false"/>
<property name="hibernate.connection.url" value="jdbc:postgresql://localhost:5432/DB_NAME"/>
<property name="hibernate.dialect" value="org.hibernate.dialect.PostgreSQLDialect"/>
<property name="hibernate.connection.driver_class" value="org.postgresql.Driver"/>
<property name="hibernate.connection.username" value="USERNAME"/>
<property name="hibernate.connection.password" value="PASSWORD"/>
<property name="hibernate.cache.use_second_level_cache" value="true"/>
<property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
My ehcache.xml:
<ehcache name="cacheTest" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="http://ehcache.org/ehcache.xsd">
<defaultCache eternal="true" maxElementsInMemory="100" overflowToDisk="false" />
<cache name="entityCache"
maxEntriesLocalHeap="50"
eternal="false"
timeToLiveSeconds="120"
/>
</ehcache>
and on my entity there is an annotation like this
#Cache(region="entityCache", usage=CacheConcurrencyStrategy.READ_WRITE )
When i run locally my UnitTest i have no problems. All tests passed, but if i run tests on my Hudson continuos integretion i have following error (problem is same if i set or not annotation on it #DirtiesContext):
> javax.persistence.PersistenceException: org.hibernate.cache.CacheException: java.lang.IllegalStateException:
> The cacheTest Cache is not alive (STATUS_SHUTDOWN) at
> org.hibernate.ejb.AbstractEntityManagerImpl.convert(AbstractEntityManagerImpl.java:1167)
> at
> org.hibernate.ejb.AbstractEntityManagerImpl.refresh(AbstractEntityManagerImpl.java:673)
> at
> org.hibernate.ejb.AbstractEntityManagerImpl.refresh(AbstractEntityManagerImpl.java:641)
> Caused by: org.hibernate.cache.CacheException:
> java.lang.IllegalStateException: The cacheTest Cache is not alive
> (STATUS_SHUTDOWN) at
> net.sf.ehcache.hibernate.regions.EhcacheTransactionalDataRegion.remove(EhcacheTransactionalDataRegion.java:164)
> at
> net.sf.ehcache.hibernate.strategy.AbstractEhcacheAccessStrategy.evict(AbstractEhcacheAccessStrategy.java:119)
> at
> net.sf.ehcache.hibernate.nonstop.NonstopAwareEntityRegionAccessStrategy.evict(NonstopAwareEntityRegionAccessStrategy.java:96)
> at
> org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:144)
> at
> org.hibernate.event.def.DefaultRefreshEventListener.onRefresh(DefaultRefreshEventListener.java:62)
> at org.hibernate.impl.SessionImpl.fireRefresh(SessionImpl.java:1118)
> at org.hibernate.impl.SessionImpl.refresh(SessionImpl.java:1098) at
> org.hibernate.ejb.AbstractEntityManagerImpl.refresh(AbstractEntityManagerImpl.java:666)
> Caused by: java.lang.IllegalStateException: The cacheTest Cache is
> not alive (STATUS_SHUTDOWN) at
> net.sf.ehcache.Cache$CacheStatus.checkAlive(Cache.java:3946) at
> net.sf.ehcache.Cache.checkStatus(Cache.java:2664) at
> net.sf.ehcache.Cache.removeInternal(Cache.java:2288) at
> net.sf.ehcache.Cache.remove(Cache.java:2207) at
> net.sf.ehcache.Cache.remove(Cache.java:2125) at
> net.sf.ehcache.hibernate.regions.EhcacheTransactionalDataRegion.remove(EhcacheTransactionalDataRegion.java:160)
How could i solve that problem?
Why that happens only on Hudson?
UPDATE
As suggested by #lanimall i have:
disabled all nodes on Hudson;
modified persistence.xml.
Replacing
< property name="hibernate.cache.provider_class" value="net.sf.ehcache.hibernate.EhCacheProvider" />
with
<property name="hibernate.cache.region.factory_class" value="net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory" />
but that doesn't solve my problem (but it's a good starting :-)...error is same).
My environment configuration is hibernate3 and ehcache-2.7.2
what version of hibernate are you using? and Ehcache?
I think what could be happening is that hudson is running on some application server (such as Glassfish, Tomcat 5, JBoss, Jetty 6, etc) and it might have either some ehcache or hibernate lib versions that are competing with the ones you're embedding in your app...hence the problem happening only when running tests in hudson. Make sure to look into that...
Also, per ehcache/hibernate documentation (http://ehcache.org/documentation/user-guide/hibernate#Configure-Ehcache-as-the-Second-Level-Cache-Provider), please try to use the "hibernate.cache.region.factory_class" setting as opposed to the "hibernate.cache.provider_class"...
And I also usually use the singleton factory (otherwise your JUNIT tests will not work...). Based on hibernate version, use
hibernate.cache.region.factory_class=net.sf.ehcache.hibernate.SingletonEhCacheRegionFactory
or (for hibernate 4.x and above)
hibernate.cache.region.factory_class=org.hibernate.cache.ehcache.SingletonEhCacheRegionFactory
hope that helps...
I have found solution!
In my persistence.xml i had 2 persistence-unit configured as Singleton and in some tests were used both. In that way those share EhCacheSingleton.
Then happens that when EntityFactory associated to one of that was shutdown, consequently make a ehcache shutdown that was used by the other one (because there is one instance of Singleton shared between those 2 entity manager).
Many thanks to #lanimall to open my mind!
JUnit share Spring context for speed. I've avoid from this exception when remove explicitly Spring context closing in one of my test.

Categories