WebSphere wsadmin ClassNotFound Exceptions - reflection

I'm trying to use wsadmin with Jython to deploy an EAR file. Before the actual deployment, I need to run a DB update using a Java class. I'm running into a ClassNotFoundException that isn't making sense to me.
Background:
The EAR file is exploded. The wsadmin tool is started with the following options:
-wsadmin_classpath %CP%
-javaoption -Dpython.path=%CP%
Both of those point to the same classpath, which contains all necessary JARs.
The jython script gets a connection to a database, and calls a utility class to create a database script. The utility class uses reflection to load other classes from the classpath (that is a hard-and-fast requirement of the library we are using, it can't be changed). It basically looks like this:
from liquibase import Liquibase
def main(args):
conn = getConnection(args)
updater = Liquibase(conn)
updater.update()
During the update() method, Liquibase uses reflection to instantiate some Java classes. This is where I get a ClassNotFoundException, for example ClassNotFoundException: com.foo.CustomUpdate
In my script, I can import the com.foo.CustomUpdate class and get no errors:
from com.foo import CustomUpdate
c = CustomUpdate("select 1")
print c.getUpdate()
So I know that the class is on the classpath. My only idea is that it has something to do with the reflection aspect of the library we are using. Has anybody else run up against anything like this?
My only other idea, if the above is unfixable, is to split things out into a shell script and use Java to run the DB update and then wsadmin to deploy the EAR.

Related

Calling jar from XQuery

I have came across a situation where I have to call a jar with a string parameter and get the result. Is there any way i can able to do this? I came across a link where importing java:java.lang.Math namespace using Java function inside XQuery. This will help me to use library functions of Java. Is there any way I can call jar or customize function from XQuery?
MarkLogic doesn't have a way to directly call a Java method in a JAR file. The common practice is to have the required Java functionality available as a service, then call that from MarkLogic. For instance, you could set up Tomcat to host the functionality that lives in the JAR file.

Can't compile servlet using command line

I'm trying to compile a servlet which sets session data for my site. However I'm having big problems trying to import other class files which the servlet relies on.
I need to import my custom made MySQL class file which is located in evo.net. (WEB-INF/classes/evo/net). This is already compiled and works perfectly.
And I also need to import my custom made Encryption class for encrypting passwords using it's md5() method. This is located in evo.common (WEB-INF/classes/evo/common). This is already compiled and works perfectly too.
My Session servlet is located in the same package as my MySQL class (evo.net or WEB-INF/classes/evo/net).
I'm setting the classpaths as follows:
set classpath=;D:\Apache Software Foundation\Tomcat
7.0\lib\servlet-api.jar;D:\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\WEB-INF\classes\evo\common\Encryption;D:\Apache Software Foundation\Tomcat
7.0\webapps\ROOT\WEB-INF\classes\evo\net\MySQL
Is this the wrong way to set multiple classpaths? As its throwing 'cannot find symbol' errors. If I just set the classpath pointing at the servlet-api.jar it fixes the javax cannot find symbol errors, but when I add the others on the classpath it doesnt work. Help much appreciated. Thanks!

Unable to Build Spring Boot Project with Flyway and Test Class

I have added flyway to our spring boot java application. The only way I can successfully build the project with maven is to comment out
the test class. Otherwise I receive a flyway error when flyway encounters a SQL script that is attempting to create indexes within a
Create Table script. The errors are below:
Caused by: org.flywaydb.core.internal.dbsupport.FlywaySqlScriptException:
Message : Unknown data type: "IDK_COMPANIES_CITY"; SQL statement:
How can I get my project to build without commenting out the tests? The test class is below: Note: I can comment out the Test class, build and deploy the project successfully. All the SQL scripts migrate successfully. The application is using a MariaDB in the cloud. Thanks.
package com.spring.sample;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.SpringApplicationConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.test.context.web.WebAppConfiguration;
#RunWith(SpringJUnit4ClassRunner.class)
#SpringApplicationConfiguration(classes = DatabaseTestApplication.class)
#WebAppConfiguration
public class DatabaseTestApplicationTests {
#Test
public void contextLoads() {
}
}
I assume you're using an in-memory database in your tests, rather than connecting to a live one. That could mean that the in-memory database that is being created when your tests are run does not support the syntax inside your Flyway-scripts.
Try setting this in your test application properties:
spring.jpa.hibernate.dialect=org.hibernate.dialect.MySQLDialect
The reason I suggest using MySQLDialect is that there is none for MariaDB and because it says so in MariaDB's Knowledge Base.
If the above doesn't work, try this property instead:
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect

External classes/jar in OSGi

My application supports running on many dbms and it requires user to configure dbms connection setting and also provide the jdbc jar file.
Now the application is to be packaged as OSGi bundle. There will be another main jar which lanches OSGi server and starts the application as bundle.
Can you please suggest how can I package the application as bundle and let user provide the jdbc jar file.
Will it require something like the main launcher jar specifying JDBC driver classes as FRAMEWORK_SYSTEMPACKAGES property?
Thanks in advance,
Aman
There are two ways of doing this:
1) Adding the driver.jar to the classpath of the main launcher and, like you say, expose its packages via the framework by specifying that property (or actually you can use the FRAMEWORK_SYSTEMPACKAGES_EXTRA property to just specify additional packages, instead of specifying all of them).
2) Manually wrapping the driver.jar as a bundle, or doing it dynamically at runtime. For example, you could try to wrap bundles that are copied to a certain folder (similar to what Apache Felix File Install does) by using Pax URL or some other tool that can create a bundle out of an ordinary jar file for you (see http://team.ops4j.org/wiki/display/paxurl/Pax+URL).

include model libraries in appclient jar

I'm deploying an ear with an EJB onto glassfish 3.1 which I want to call using the appclient script.
The EJB has a method with as parameter a model object which is defined in a separate library.
If I want to use the appclient script I have a Main class with a main method which calls the EJB.
This is also put into a separate jar which is also deployed onto glassfish.
As the model object is located in a separate library I need it in the client jar but also in the EJB.
So I need to reference it somehow in the client jar.
The client jar is a jar (duh) so I cannot add other jars. The Java EE 6 docs say that I should create an ear with the libs but if I do that it doesn't deploy because an ear needs at least an ejb or web module and my client lib has neither.
The solution I found is using the assembly plugin/jar-with-dependencies. This plugin creates a new jar which contains all classes of all dependencies.
This solution works but I'm wondering if this is the way to go or I'm missing something obvious because I cannot imagine this is required. EJB's usually have model objects as parameters so this situation will happen a lot.
So my question is: is there a way to tell glassfish to reference the shared libraries between the app client jar and the ejb jar.
The way I do this is like this:
Separate Maven project with the model. In my case that's a bunch of simple POJOs with JPA and JAX-B annotations, some constants, etc. In Maven, I define this as an OSGi bundle, by specifying <packaging>bundle</packaging>. I call this project MyAppInterface.
Separate Maven projects for other elements that need to deal with the model. In my case, I have one Java EE application with EJBs, Database facade, REST servlet; I have an Integration-Test project which only does tests; a GWT application; etc... In those projects I specify the dependency to the model:
<dependency>
<groupId>com.skalio</groupId>
<artifactId>MyAppInterface</artifactId>
<version>1.0-SNAPSHOT</version>
</dependency>
When deploying MyAppInterface to Glassfish, I use the following syntax:
asadmin deploy --type osgi --name MyAppInterface /path/to/MyAppInterface-1.0-SNAPSHOT.jar
I understand it that this is placing the model on the classpath of Glassfish, similar to a mysql-connector, only OSGi-style.
I let all these projects be built by a central jenkins CI server, which deploys the artifacts to our internal maven repository. We then add the internal repository in pom.xml of each project. As a result, everyone automatically works with the latest stable MyAppInterface, even if they don't have the code checked out in NetBeans / Eclipse.
Let me know if you need more examples.

Resources