Exception while starting jetty 9 from Ant and Ivy - ant

I am trying to start Jetty 9 from Ant using ivy (not maven) and getting the following exception
Object of class 'org.eclipse.jetty.ant.WebApplicationProxyImpl.AntWebAppContext' is not of type 'org.eclipse.jetty.webapp.WebAppContext'. Object Class and type Class are from different loaders.
jetty-env.xml ---
<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<New id="jdbc/datasource" class="org.eclipse.jetty.plus.jndi.Resource">
<Arg>java:comp/env/jdbc/datasource</Arg>
<Arg>
<New class="com.inet.tds.TdsDataSource">
<!--<Set name="driverClassName">com.inet.tds.TdsDriver</Set>-->
<Set name="serverName">serverDetails
</Set>
<Set name="user">user</Set>
<Set name="password">password</Set>
</New>
</Arg>
</New>
If I change the class in the Configure form "org.eclipse.jetty.webapp.WebAppContext" to "org.eclipse.jetty.ant.WebApplicationProxyImpl.AntWebAppContext", getting the ClassNotFoundException org.eclipse.jetty.ant.WebApplicationProxyImpl.AntWebAppContext - Even though I have the jar included in my classpath.

Related

Use Grab to Download Ivy Dependency Jar when Artifact name is not the same as Module name

Within a Jenkins groovy script I'm trying to download a dependency using the following:
#Grab(group='myorg', module='SuiteCreator', version='1.16.1', conf='jar', transitive=false)
import myorg.myorgAPI
I have a /home/jenkins/.groovy/grapeConfig.xml file with the following:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-settings>
<settings defaultResolver="downloadGrapes"/>
<resolvers>
<chain name="downloadGrapes">
<sftp user="admin" userPassword="pw" host="ivy.myorg.com" name="myrepository" checkmodified="true">
<ivy pattern="/data/ivy/repo/[organisation]/[module]/[branch]/[revision]/ivy-[revision].xml"/>
<artifact pattern="/data/ivy/repo/[organisation]/[module]/[branch]/[revision]/[artifact]-[revision].[ext]"/>
</sftp>
</chain>
</resolvers>
</ivy-settings>
The ivy-1.16.1.xml of the Module I've trying to grab:
<?xml version="1.0" encoding="UTF-8"?>
<ivy-module version="1.0">
<info organisation="myorg" module="SuiteCreator" branch="master" revision="1.16.1" status="release" publication="20190417105814"/>
<configurations>
<conf name="jar" description="Distribution jar"/>
</configurations>
<publications>
<artifact name="myorg-suitecreator" type="jar" ext="jar" conf="jar"/>
</publications>
</ivy-module>
So I'm just trying to grab the artifact: myorg-suitecreator-1.16.1.jar.
When I run my groovy script in Jenkins I get the following error:
2019.07.09 18:06:15 org.codehaus.groovy.control.MultipleCompilationErrorsException:
startup failed:
2019.07.09 18:06:15 General error during conversion: Error grabbing Grapes -- [download failed:
myorg#SuiteCreator#master;1.16.1!SuiteCreator.jar]
2019.07.09 18:06:15
2019.07.09 18:06:15 java.lang.RuntimeException: Error grabbing Grapes -- [download failed: myorg#SuiteCreator#master;1.16.1!SuiteCreator.jar]
2019.07.09 18:06:15 at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
From the error it seems Grape is assuming the Ivy Artifact Name is the same as the Module name. The ivy-1.16.1.xml Artifact Name at: /ivy-module/publications/artifact/#name is defined as myorg-suitecreator However Grab appears to be attempt to download: SuiteCreator.jar.
The artifact pattern in grapeConfig.xml is:
<artifact pattern="/data/ivy/repo/[organisation]/[module]/[branch]/[revision]/[artifact]-[revision].[ext]"/>
And so the file I'm trying to grab is actually: /data/ivy/repo/myorg/SuiteCreator/1.16.1/myorg-suitecreator-1.16.1.jar
Does anyone have any suggestions on how to get this to work (or if Grab can download artifacts with different artifact name to the module name from Ivy?).
I gave up trying to use Grab to achieve this. I found another limitation of Grab is that it doesn't allow the specification of the branch of the artifact you wish to retrieve. I realise that not having releases on a master branch or a single release branch may not be best practice, but we do have this requirement in our dev environment.
Instead I simply used an Invoke Ant build step within Jenkins to retrieve my Ivy artifact. We use ANT already in our dev process so this was not difficult.
The ANT build.xml script is located in the same git repository as the Groovy script I wish to run. The retrieve-suite-creator target is simply an ivy-retrieve
<target name="retrieve-suite-creator" depends="clean, install-ivy">
<ivy:retrieve conf="suite-creator" type="jar" pattern="${build.dir}/[artifact].[ext]" log="${ivy.resolve.log}" settingsRef="${ivy.build.settings}"/>
</target>
Using my ivy.xml (again in the same repo as the groovy script):
<ivy-module version="1.0">
<info organisation="myorg" module="MyAutomation" status="integration" branch="${ivy.branch}"/>
<configurations>
<conf name="suite-creator" description="Configuration for Suite Creator"/>
</configurations>
<dependencies>
<dependency org="myorg" name="SuiteCreator" branch="mybranch" rev="1.16.1" conf="suite-creator->suite-creator" changing="true"/>
</dependencies>
</ivy-module>
I had to add the suite-creator ivy configuration to the SuiteCreator module's ivy.xml (in a separate SuiteCreator Git repo). I couldn't use the existing jar configuration as this also downloaded all the transitive dependencies which I didn't need.
<ivy-module version="1.0">
<info organisation="myorg" module="SuiteCreator" status="integration" branch="${ivy.branch}"/>
<configurations>
<!-- Build configurations -->
<conf name="build" description="Classes used in jar compilation"/>
<conf name="jar" description="Distribution jar"/>
<conf name="suite-creator" description="Just the myorg-suitecreator.jar"/>
</configurations>
<publications>
<artifact name="myorg-suitecreator" type="jar" ext="jar" conf="jar,suite-creator"/>
</publications>
<dependencies>
...
</dependencies>
</ivy-module>
Finally in my Jenkins job after the Invoke Ant build step, I then had an Execute Groovy Script build step, where I had to add the downloaded jar to my Class path.

Access to Wildfly <system-properties><property> through JNDI

is it possible to access Wildfly properties (defined in standalone.xml) through JNDI?
Like:
<system-properties>
<property name="MY_PROPERTY" value="some value"/>
...
</system-properties>
and read it in java:
#Resource(lookup = "java:comp/env/MY_PROPERTY")
private String property;
<system-properties> are used to define environment variables and not JNDI variables. Define JNDI variables inside
<subsystem xmlns="urn:jboss:domain:naming:2.0">
<bindings>
...
<simple name="java:/env/MY_PROPERTY" value="some value"/>
</bindings>
</subsystem>
Now, you can read it as a JNDI.

ivy install from maven repo with dependency wrong type element value: source

I'm trying to install in a ivy local repository from the following repository http://repository.pentaho.org/artifactory/repo the below artifact:
<dependency>
<groupId>pentaho</groupId>
<artifactId>mondrian</artifactId>
<version>3.6.7</version>
</dependency>
Below the ant task in common.xml:
<target name="import">
<ivy:install organisation="${module.organization}" module="${module.name}" revision="${module.version}"
from="${module.resolver.source}" to="${module.resolver.target}" transitive="${module.transitive}" overwrite="true"/>
</target>
with the following properties values:
<property name="module.organization" value="pentaho" />
<property name="module.name" value="mondrian" />
<property name="module.version" value="3.6.7" />
<property name="module.transitive" value="true" />
<property name="module.resolver.source" value="pentaho-chain" />
<property name="module.resolver.target" value="thirdparty" />
But it fails, because its pom contains a dependency (see below), which has a wrong type element value:
<dependency>
<groupId>org.olap4j</groupId>
<artifactId>olap4j</artifactId>
<version>1.1.0</version>
<type>source</type>
<classifier>sources</classifier>
<optional>true</optional>
</dependency>
This snippet is translated into the following line in the ivy file:
...
<artifact name="olap4j" type="source" ext="jar" conf="sources" m:classifier="sources"/>
...
This line leads to the following download url:
http://repository.pentaho.org/artifactory/repo/org/olap4j/olap4j/1.1.0/olap4j-1.1.0-sources.source
with .source instead of .jar, so as result the artifact hasn't been found.
Is there a way to configure ivy properly to workaround this situation?
Thanks
Remove type, its adding source by default to your url. By default ivy takes type as jar.
Also you dont need classifier like maven does here.
So if you remove these attributes, it should work fine.

Ivy Resolve of "latest.integration" fails when run from Jenkins

so I have an existing ant build and I'd like to resolve its dependencies using Ivy. I have an ivy.xml and ivysettings.xml file which both work with IvyDE in Eclipse and also work when run from the command line against the ivy-2.3.0.jar. (They work as in Ivy reports it has downloaded the dependencies).
The problem I have is that they do not work when running from the any build script when the 'rev' attribute is listed as 'latest.integration'. If I specify a version then the dependency is resolved. To be clear this specific dependency is an internal library that is hosted by Artifactory.
I'm fairly stumped as to what I can change or try to identify the problem. I get the same failure when running an ivy findrevision.
To note Jenkins is running on a mac, but I can use the Ivy jar directly to resolve the dependencies using the same ivy files on that machine, the problem is only related to when resolving through Jenkins.
I realise this isn't likely to be something someone can look at and point directly to the problem, especially given that in seemingly all other situations, even running the snippet from the ant build through eclipse, the resolve works correctly. But if anyone has any suggestions they'd be more than welcome!
Anyway my ivy.xml
<ivy-module version="2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="http://ant.apache.org/ivy/schemas/ivy.xsd">
<info
organisation="MyOrg"
module="MyModule"
status="integration">
</info>
<dependencies>
<dependency org="MyOrg" name="DEP" rev="latest.integration">
<artifact name="DEP" type="jar" ext="jar" />
</dependency>
<dependency org="junit" name="junit" rev="4.8.1" />
</dependencies>
</ivy-module>
And my ivysettings.xml (The dependency is named for example DEP-0.1-SNAPSHOT.jar)
<?xml version="1.0" encoding="UTF-8"?>
<ivy-settings>
<settings defaultResolver="snapshot" />
<!--Authentication required for publishing (deployment). 'Artifactory Realm' is the realm used by Artifactory so don't change it.-->
<credentials host="HOST" realm="Artifactory Realm" username="USR" passwd="PASS" />
<resolvers>
<chain name="main">
<!-- <ibiblio name="release" m2compatible="true" root="http://HOST/artifactory/libs-release" /> -->
<chain name="snapshot" changingPattern="0.*" checkmodified="true">
<ibiblio name="public" m2compatible="true" root="http://HOST/artifactory/libs-snapshot" />
</chain>
</chain>
</resolvers>
</ivy-settings>
And finally my build script looks something like
<project name="MyModule Continuous Integration" xmlns:ivy="antlib:org.apache.ivy.ant">
....
<target name = "resolveDependencies" >
<ivy:configure file="/MyModule/ivysettings.xml" />
<ivy:findrevision organisation="MyOrg" module="DEP" revision="latest.integration" property="found.revision" />
<echo message="Found revision: ${found.revision}" />
<ivy:resolve file="/MyModule/ivy.xml" refresh="true" type="jar" />
<ivy:cachepath pathid="ivy.dependencies" />
</target>
....
</project>
And for completion the sort of output I'm getting from the Jenkins build is:
[ivy:findrevision] snapshot: Checking cache for: dependency: MyOrg#DEP;latest.integration {}
[ivy:findrevision] don't use cache for MyOrg#DEP;latest.integration: checkModified=true
[ivy:findrevision] default-cache: no cached resolved revision for MyOrg#DEP;latest.integration
[ivy:findrevision] tried http://HOST/artifactory/libs-snapshot/MyOrg/DEP/[revision]/DEP-[revision].pom
[ivy:findrevision] CLIENT ERROR: Not Found url=http://HOST/artifactory/libs-snapshot/MyOrg/DEP/maven-metadata.xml
[ivy:findrevision] maven-metadata not available: http://HOST/artifactory/libs-snapshot/MyOrg/DEP/maven-metadata.xml
[ivy:findrevision] WARN: problem while listing resources in http://HOST/artifactory/libs-snapshot/MyOrg/DEP/ with public:
[ivy:findrevision] WARN: java.lang.NullPointerException null
[ivy:findrevision] tried http://HOST/artifactory/libs-snapshot/MyOrg/DEP/[revision]/DEP-[revision].jar
[ivy:findrevision] maven-metadata not available: http://HOST/artifactory/libs-snapshot/MyOrg/DEP/maven-metadata.xml
[ivy:findrevision] WARN: problem while listing resources in http://HOST/artifactory/libs-snapshot/MyOrg/DEP/ with public:
[ivy:findrevision] WARN: java.lang.NullPointerException null
[ivy:findrevision] public: no ivy file nor artifact found for MyOrg#DEP;latest.integration
Property "found.revision" has not been set
[echo] Found revision: ${found.revision}
Thanks again for any ideas,
Dan.
For future reference, I have managed to resolve this by swapping to the latest Ivy 2.4 alpha build. Seems it must have been a problem with 2.3.0.

Not able to read environment variable in persistence.xml

I have a Maven3 project where I'm using the tomcat7-maven-plugin. I would like to set the path for the embedded database via an environment variable argument to the jvm.
Reading the variable with System.getenv("myDataDir") within a Java-Method returns the correct path.
But when I try to set the variable ${myDataDir} in my persistence.xml and then I start tomcat with "mvn tomcat:run" I get FileNotFoundExceptions because the variable is not replaced with the actual value (it says e.g. Cannot find path for ${myDataDir}\derby.log)
I don't know what's causing this - if it's the persistence provider (EclipseLink) that doesn't support this or if it's something else.
My persistence.xml looks like this:
<persistence xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" version="2.0" xmlns="http://java.sun.com/xml/ns/persistence">
<persistence-unit name="myPersistence" transaction-type="RESOURCE_LOCAL">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<properties>
<property name="javax.persistence.jdbc.driver" value="org.apache.derby.jdbc.EmbeddedDriver" />
<property name="javax.persistence.jdbc.url" value="jdbc:derby:${myDataDir}/DB;create=true;upgrade=true" />
<property name="javax.persistence.jdbc.user" value="admin" />
<property name="javax.persistence.jdbc.password" value="password" />
<property name="eclipselink.ddl-generation" value="create-tables" />
<property name="eclipselink.ddl-generation.output-mode" value="both" />
<property name="eclipselink.logging.level" value="SEVERE" />
<property name="eclipselink.logging.file" value="${myDataDir}/derby.log" />
<property name="eclipselink.application-location" value="${myDataDir}/dbScripts" />
</properties>
</persistence-unit>
</persistence>
EDIT:
I forgot to mention, that I'm in a Spring 3 Framework environment. According to the examples on the web, this should be capable of using environment variables in persistence.xml...
Using ${myDataDir} in a database URL is not valid, unless supported by your database, or unless you are translating the variable during your own build scripts.
What you can do is pass a properties map to Persistence.createEntityManagerFactory() that has the URL you want, that you must build at runtime in code.

Resources