How to run Liquibase on command line with Custom Change java class? - postgresql

I am trying to run my liquibase update from the command line. However, I have a customChange in my changelog file, i.e. a Java file that implements liquibase.change.custom.CustomChange. The update is successful when running via Spring. However, when I try to apply the update via command line using
liquibase --changeLogFile=<my_changelog_file> --username=<my_user> --password=<my_password> --url=<my_url> --driver=org.postgresql.Driver --classpath='<path_to>/postgresql-42.2.8.jar:<absolute_path_to_my_jar.jar>' update
I am getting this error:
Liquibase Community 3.8.6 by Datical
Unexpected error running Liquibase: liquibase.parser.core.ParsedNodeException: liquibase.exception.CustomChangeException: java.lang.ClassNotFoundException: com.<my_company>.platform.changeset.EncryptPasswordsChangeset
I have obscured any real values I am passing in for security reasons. Anyone know how to let liquibase find this file? I tried creating a jar with just the necessary files and adding that jar to the classpath, but that doesn't seem to work as the jar does not contain any main classes.
Running
jar tf <my_jar.jar>
results in:
META-INF/
META-INF/MANIFEST.MF
com/<my_company>/platform/changeset/EncryptPasswordsChangeset.java
com/<my_company>/platform/security/PasswordEncryptUtil.java
com/<my_company>/platform/encrypt/SymmetricCipher.java

My jar was not formed properly. Should be building it with compiled .class files, not .java files.

Related

Cannot find parser that supports .groovy

When I'm trying to start changelog.groovy via liquibase command line it tells me that
Unexpected error running Liquibase: Cannot find parser that supports changelog.groovy
I'm doing the next: java -jar liquibase.jar update
My liquibase.properties are:
driver=org.postgresql.Driver
classpath=C:\Users\Andrii\org.postgresql.Driver.jar;C:\Users\Andrii\liquibase-3.5.1-bin\lib\liquibase-groovy-dsl-1.2.2-SNAPSHOT.jar
changeLogFile=D:\changelog.groovy
url=jdbc:postgresql://localhost:5432/test
username=postgres
password=rup
It finds those jars since if I change something in that path it will tell that jars cannot be found.
I downloaded the groovy-liquibase-dsl project, build it and added a jar into classpath. What am I doing wrong?
To make it work, you need to additionally include groovy and groovy-sql jars in Liquibase's classpath.
So say you store all the jars in C:\Users\Andrii\LiquibaseDependencies, update your the classpath property of your file as such:
classpath=C:\Users\Andrii\LiquibaseDependencies\org.postgresql.Driver.jar;
C:\Users\Andrii\LiquibaseDependencies\liquibase-groovy-dsl-1.2.1.jar;
C:\Users\Andrii\LiquibaseDependencies\groovy-2.4.6.jar;
C:\Users\Andrii\LiquibaseDependencies\groovy-sql-2.4.6.jar

Building Customize Spark

We are creating a customize version of Spark since we are changing some lines of code from ALS.scala. We build the customize spark version using
mvn command:
./make-distribution.sh --name custom-spark --tgz -Psparkr -Phadoop-2.6 -Phive -Phive-thriftserver -Pyarn
However, upon using the customized version of Spark, we run into this error:
Do you guys have some idea on what causes the error and how we might solve the issue?
I am actually using a jar file in the local machine by building them using sbt: sbt compile then sbt clean package and putting the jar file here: /Users/user/local/kernel/kernel-0.1.5-SNAPSHOT/lib.
However in the hadoop environment, the installation is different. Thus, I use maven to build spark and that's where the error comes in. I am thinking that this error might be dependent on using maven to build spark as there are some reports like this:
https://issues.apache.org/jira/browse/SPARK-2075
or probably on building spark assembly files

Error in Eclipse about type indirectly referenced from required .class file

I'm having this exception with some stubs generateds by Axis2:
"The type org.apache.axiom.om.OMElement cannot be resolved. It is
indirectly referenced from required .class files"
I've been reading many posts, and trying to find a solution. What I've found so far is to add the apache tomcat 5.5 library to the build path. It removed the error in the java file, but then, when I to execute any java program inside the project, I got this error:
'Launching myApp' has encountered a problem Exception occurred
executing command line. Cannot run program "C:\Program
Files\Java\jdk1.5.0_22\bin\javaw.exe" (in directory
"D:\Digicel\workspace\Digicel\myClassSample"): CreateProcess error=87,
The parameter is incorrect
then if I remove the apache tomcat library from the build path, I can run the other java programs, but not the one mentioned initially.
Any thoughts about it?
Okay, I've found the cause of the problem with the help of a friend :)
The thing is that Eclipse is aware that one of my dependencies, depends of another library, and Eclipse is checking for it when it tries to build the code.
So, what I've done is try to check which jar file contains this library: " org.apache.axiom.om.OMElement".
I've googled it and found that it is "axiom-api-1.2.10.jar" and finally my file compiled with 0 errors.
He also explained to me that my original solution of adding the apache tomcat server library is adding all the jars that cames with apache tomcat (which is a big list), and probably there may have been a version conflict with my current list of added jars.
So, the fix was to find the appropriate jar and add it to the project.
This error can also occur when a indirect dependency has a corrupt jar file. This may be caused by problems at the public maven repository.
If this is the case removing the local maven repository to download fresh jar files will fix your problem:
rm -Rf ~/.m2/repository/{enter/path/to/broken/stuff}
Goto Maven >Update Maven project>checkmark the Force update >Then Run
..That error Will gone....

Scala SBT: standalone jar

The answer: Making stand-alone jar with Simple Build Tool seems like what I need, but it did not have enough information for me, so this is a followup.
(1) How do I adapt the answer to my need? I don't understand what would need to be changed.
(2) What command do I run to create the standalone jar?
(3) Where can I find the jar after it has been created?
What I've tried:
Pasting the code in the linked answer verbatim into my: project/build/dsg.scala file. The file now has a
class ForkRun(info: ProjectInfo) extends DefaultProject(info)
(from before, used for running projects in a separate VM from SBT) and the new:
trait AssemblyProject extends BasicScalaProject
from the linked answer.
I also tried pasting the body (all defs and the lazy val of the AssemblyProject into the body of ForkRun.
To create a jar I ran package at the SBT prompt and get:
[info] Packaging ./target/scala_2.8.1/dsg_2.8.1-1.0.jar ...
[info] Packaging complete.
So I tried running the dsg_2.8.1-1.0.jar from the shell via:
java -jar dsg_2.8.1-1.0.jar
But I get:
Failed to load Main-Class manifest attribute from
dsg_2.8.1-1.0.jar
Could this be caused by having multiple entry points into my project? I select from a list when I execute run from the SBT prompt. Perhaps I need to specify the default when creating the package?
Here's a writeup I did on one way to make an executable jar with SBT:
http://janxspirit.blogspot.com/2011/01/create-executable-scala-jar-with-sbt.html
sbt-assembly is a sbt plugin to create a standalone jar of Scala sbt project with all of its dependencies.
Refer this post for more details with an example.

Hadoop throwing java.lang.VerifyError after exporting jar file

I'm altering a hadoop map - reduce job that currently compiles and runs fine without my changes.
As part of the job, I will now be connecting to S3 to deliver a file.
I developed a (very simple) s3Connector class, tested and ran it in eclipse,
then went to hook it into my reduce job. In order to run the job in hadoop, I have to export the project as a jar file, then call it from hadoop. The jar file seems to compile and export without problem from eclipse, but when I run it in hadoop, I get a java.lang.VerifyError exception.
java.lang.VerifyError: (class: com/extrabux/services/S3Connector, method:
connectToS3 signature: ()V) Incompatible argument to function
Several other posts mention that there may be jar version dependencies that are conflicting, but in my eclipse build path, I added all the latest jar files for the specified libs, and pushed them to the top of the build path order.
This is about as simple as I can isolate it down to:
import org.jets3t.service.impl.rest.httpclient.RestS3Service;
import org.jets3t.service.security.AWSCredentials;
public class S3Connector {
protected RestS3Service s3Service;
protected AWSCredentials awsCredentials;
public S3Connector()
{
this.awsCredentials= new AWSCredentials("my secret 1", "my secret 2");
}
public void connectToS3() throws Exception
{
this.s3Service = new RestS3Service(this.awsCredentials);
}
}
Even that simple class will die.. Same message. As soon as I comment out the AWS credentials in the constructor and RestS3Service, the issue disappears. Basically, I think it's some kind of library export problem out of eclipse, but not sure how to find it.
Figured this out. There was an old version of the jets3t jar that was in the hadoop lib dir
the hadoop command line script loops over all jars in the lib dir and physically adds them to the classpath on the final exec'ed command line command that it builds. This command line classpath of the 0.6.0 jar was overriding the good 0.8.0 jar that I was exporting in my jar file. Since the 0.6.0 version did not have the specified constructor for RestS3Service , the java.lang.VerifyError was getting thrown. By removing the 0.6.0 lib from hadoop, all was well.