Run time java jar file with jython exceptions - batch-file

I have a big application that worked perfect inside eclipse, I create an executable jar file for my application, My application use jython to define some resources. Also I create `the following .bat file to run the file:
# echo off
java -Xms64m -Xmx512m -Xincgc -Dpython.home=jython-2.1 -Dpython.path=jython-2.1/Lib/alice -Djava.library.path=lib/win32;externalLib/win32; -jar MyProg23.jar
When execute the .bat file an exception appeared, this is a part of this exception:
java.lang.ExceptionInInitializerError
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Unknown Source)
at edu.cmu.cs.stage3.alice.authoringtool.JAlice.main(JAlice.java:163)
Caused by: Traceback (innermost last):
File "C:\MyWork\AliceDev\Alice test\resources\Alice Style.py", line 23, in ?
File "C:\MyWork\AliceDev\Alice test\resources\common\StandardResources.py", li
ne 181, in ?
AttributeError: java package 'javax' has no attribute 'vecmath'
at org.python.core.Py.AttributeError(Py.java)
at org.python.core.PyObject.__getattr__(PyObject.java)
at org.python.pycode._pyx1.f$0(C:\MyWork\AliceDev\Alice test\resources\c
ommon\StandardResources.py:181)
at org.python.pycode._pyx1.call_function(C:\MyWork\AliceDev\Alice test\r
esources\common\StandardResources.py)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at org.python.core.__builtin__.execfile_flags(__builtin__.java)
at org.python.core.__builtin__.execfile(__builtin__.java)
at org.python.core.__builtin__.execfile(__builtin__.java)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java
)
at org.python.core.PyReflectedFunction.__call__(PyReflectedFunction.java
)
at org.python.core.PyObject.__call__(PyObject.java)
at org.python.pycode._pyx0.f$0(C:\MyWork\AliceDev\Alice test\resources\A
lice Style.py:23)
at org.python.pycode._pyx0.call_function(C:\MyWork\AliceDev\Alice test\r
esources\Alice Style.py)
at org.python.core.PyTableCode.call(PyTableCode.java)
at org.python.core.PyCode.call(PyCode.java)
at org.python.core.Py.runCode(Py.java)
at org.python.core.__builtin__.execfile_flags(__builtin__.java)
at org.python.core.__builtin__.execfile(__builtin__.java)
at edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.loadReso
urcesPy(AuthoringToolResources.java:199)
at edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.<clinit>
(AuthoringToolResources.java:108)
... 3 more
The vecmath.jar file and other external lib are founded inside a folder called externalLib which in the same folder of the Myprog23.jar and .bat files
How to solve the problem and what is need to be set?

You need to add all jars used in program to classpath. So, in your case all jars present in externalLib directory should be added in classpath.
For adding jars in classpath you may refer Setting multiple jars in java classpath

I am assuming that you have correctly set your CLASSPATH variable. Also assuming you have correctly installed JyThon. You should really make sure to TEST JyThon hello world OUTSIDE of your application environment as well. You need to take this step by step, Alice is a complex system, and so it is difficult to debug your issue without making sure basic structure of libraries is in place.
With these assumptions, you can proceed with JyThon documentation FAQ:
Jython cannot find your Java class, even though it exists in the class path.
Jython cannot find your Java class, even though it exists in the class
path. This shows up as "ImportError: cannot import name xxx" or
"AttributeError: java package xxx' has no attribute 'yyy'"
This happens when Jython is installed as a Java extension (i.e. when
jython.jar is installed in java\jre\lib\ext) and your classes are
installed in the classpath.
The reason is Java extensions can only see other extensions, not other
classes defined in the CLASSPATH or passed in to java using the
--classpath option.
There are two ways to fix this:
Move your classes to the java\jre\lib\ext directory.
Remove jython.jar from the java\jre\lib\ext directory and put
jython.jar in the CLASSPATH or use the java --classpath option.

Related

Integrate Saxon-PE in Camel using camel-saxon

I use Camel 2.22.1 with springboot 2.0.4.RELEASE. The camel component camel-saxon use default Saxon-HE. I have some Xquery files, which call Java method, so I want to replace Saxon-HE with Saxon-PE. I requested one test license for Saxon-PE and tried different ways and didn't get it work. The Saxon-PE jar file saxon9pe.jar is already loaded, however, it is still working as Saxon HE edition. I guess, the license is not correctly loaded by Saxon-PE.
I tried following ways, none of them has worked.
put license file saxon-license.lic and saxon9pe.jar in the same folder
define an environment variable SAXON_HOME, and put saxon-license.lic and saxonpe.jar in SAXON_HOME\bin
modify org.apache.camel.component.xquery.XQueryBuilder.configuration in class XqueryBuild.java in package org.apache.camel.component.xquery to set LICENSE_FILE_LOCATION ( I got Error: Unknown configuration property http://saxon.sf.net/feature/licenseFileLocation)
The Saxon Documentation mentioned to create an XML configuration file, but I don't know where should I put this XML configuration file.
When running an Xquery with Java call I got the error:
Caused by: net.sf.saxon.trans.XPathException: Cannot find a 0-argument function named Q{java:java.lang.Double}MAX_VALUE(). Reflexive calls to Java methods are not available under Saxon-HE at net.sf.saxon.query.UnboundFunctionLibrary.bindUnboundFunctionReferences(UnboundFunctionLibrary.java:166) ~[saxon9pe.jar!/:na]
at net.sf.saxon.query.QueryModule.bindUnboundFunctionCalls(QueryModule.java:1172) ~[saxon9pe.jar!/:na]
at net.sf.saxon.expr.instruct.Executable.fixupQueryModules(Executable.java:462) ~[saxon9pe.jar!/:na]
at net.sf.saxon.query.XQueryParser.makeXQueryExpression(XQueryParser.java:176) ~[saxon9pe.jar!/:na]
at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:597) ~[saxon9pe.jar!/:na]
at net.sf.saxon.query.StaticQueryContext.compileQuery(StaticQueryContext.java:658) ~[saxon9pe.jar!/:na]
at org.apache.camel.component.xquery.XQueryBuilder$3.createQueryExpression(XQueryBuilder.java:276) ~[classes!/:2.23.1]
at org.apache.camel.component.xquery.XQueryBuilder.initialize(XQueryBuilder.java:745) ~[classes!/:2.23.1]
at org.apache.camel.component.xquery.XQueryBuilder.evaluateAsDOM(XQueryBuilder.java:190) ~[classes!/:2.23.1]
at org.apache.camel.component.xquery.XQueryBuilder.evaluate(XQueryBuilder.java:151) ~[classes!/:2.23.1]
... 40 common frames omitted
Can some share some experience with setting up Saxon-PE with camel to get calling Java working within Xquery?
Thanks!
From the extra information supplied, it looks as if you're picking up the Saxon JAR file but not the license file.
Putting the license file in the same folder as the JAR file is often enough, but it only works with some classloaders.
In general you either need to ensure that the directory containing the JAR file is on the classpath, or you need to (somehow) set Saxon's configuration property LICENSE_FILE_LOCATION.
According to https://github.com/apache/camel/blob/master/components/camel-saxon/src/main/docs/xquery-component.adoc, you can set Saxon configuration properties using configuration and configurationProperties, but I don't see any further explanation of how this works. I'll have a dig around.

Flink Error: java.lang.ClassNotFoundException: org.apache.flink.shaded.calcite.com.google.common.base.Throwables

I am using Flink for streaming the data which is in the csv file. I want to put it into table format with certain schema. For this purpose I am using Flink-table_2.10-1.1.3.jar (Table api) but I got the errors:
log4j:WARN No appenders could be found for logger (org.apache.flink.api.java.typeutils.TypeExtractor).
log4j:WARN Please initialize the log4j system properly.
log4j:WARN See http://logging.apache.org/log4j/1.2/faq.html#noconfig for more info.
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/shaded/calcite/com/google/common/base/Throwables
at org.apache.calcite.rel.metadata.JaninoRelMetadataProvider.create(JaninoRelMetadataProvider.java:450)
at org.apache.calcite.rel.metadata.JaninoRelMetadataProvider.revise(JaninoRelMetadataProvider.java:460)
at org.apache.calcite.rel.metadata.RelMetadataQuery.revise(RelMetadataQuery.java:186)
at org.apache.calcite.rel.metadata.RelMetadataQuery.collations(RelMetadataQuery.java:484)
at org.apache.calcite.rel.metadata.RelMdCollation.project(RelMdCollation.java:207)
at org.apache.calcite.rel.logical.LogicalProject$1.get(LogicalProject.java:122)
at org.apache.calcite.rel.logical.LogicalProject$1.get(LogicalProject.java:120)
at org.apache.calcite.plan.RelTraitSet.replaceIfs(RelTraitSet.java:238)
at org.apache.calcite.rel.logical.LogicalProject.create(LogicalProject.java:116)
at org.apache.calcite.rel.logical.LogicalProject.create(LogicalProject.java:108)
at org.apache.flink.api.table.plan.logical.Project.construct(operators.scala:90)
at org.apache.flink.api.table.plan.logical.Project.construct(operators.scala:85)
at org.apache.flink.api.table.plan.logical.LogicalNode.toRelNode(LogicalNode.scala:78)
at org.apache.flink.api.table.Table.getRelNode(table.scala:66)
at org.apache.flink.api.table.StreamTableEnvironment.translate(StreamTableEnvironment.scala:243)
at org.apache.flink.api.java.table.StreamTableEnvironment.toDataStream(StreamTableEnvironment.scala:147)
at table_streaming_test.main(table_streaming_test.java:90)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.shaded.calcite.com.google.common.base.Throwables
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
... 17 more
When I explore the corresponding jar, the respective class is present there. Can you please tell that why this is happening?
Also can I get the maven source so that I can build the Flink-table .jar at my place?
I had the same problem with CEP library. I added to my pom file but I kept getting ClassNotFoundException. I even packaged it with my jar file via IntelliJ but didn't work.
If you're using their flink-quickstart archetype, I think there are some other things to change in pom file to make it work. When I created a clean project and added flink dependencies myself, I didn't get that exception anymore. You can try and see if this approach works.
You can also add flink-table JAR file to lib folder in Flink. this also fixed my problem with CEP library. the JAR file is available in Maven repository website. download the version you want.
According to the Table and SQL document on Flink website:
Note: The Table API is currently not part of the binary distribution.
See linking with it for cluster execution here.
I was also facing the same problem with Table api in flink v1.4.2.
I added flink-table_2.11-1.4.2.jar file present in opt folder to the lib folder and restarted flink.
This works for me. Hopefully works for you too :)

Running Flink Program on a Remote Cluster

I have a program in Apache Flink. I tested and ran it on the local machine and every thing works fine. To run the program on a remote cluster, I did necessary changes as mentioned in Apache Flink Official Website.
I did the following changes:
The two points below
ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
ExecutionEnvironment env = ExecutionEnvironment.createRemoteEnvironment("taskManagerName",
portNo,paralelismNo);
Fixing the necessary paths to read input files and write outputs.
Generate a thin jar out of the program and put the necessary jar
libraries into a folder besides my project jar file called
myproj.jar.
copying the data and the jar library and myproj.jar into the cluster
and run the following command remotely on the cluster:
java -cp pathToJarLib \\* -jar myproj.jar
But, I get the below error and I don't have any clue to fix the issue. There are no relevant log files which can aid me in fixing this issue.
Error:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/flink/api/common/functions/MapFunction
at java.lang.Class.getDeclaredMethods0(Native Method)
at java.lang.Class.privateGetDeclaredMethods(Class.java:2570)
at java.lang.Class.getMethod0(Class.java:2813)
at java.lang.Class.getMethod(Class.java:1663)
at sun.launcher.LauncherHelper.getMainMethod(LauncherHelper.java:494)
at sun.launcher.LauncherHelper.checkAndLoadMain(LauncherHelper.java:486)
Caused by: java.lang.ClassNotFoundException: org.apache.flink.api.common.functions.MapFunction
at java.net.URLClassLoader$1.run(URLClassLoader.java:366)
at java.net.URLClassLoader$1.run(URLClassLoader.java:355)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:354)
at java.lang.ClassLoader.loadClass(ClassLoader.java:425)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:308)
at java.lang.ClassLoader.loadClass(ClassLoader.java:358)
... 6 more
Your classpath is obviously not complete. Try to submit via bin/flink run myproj.jar. This sets up the classpath correctly.

How to run command in windows batch Command in jenkins

I am trying to run a command in Jenkins under build step of running commands in Execute windows batch command.
I wrote dir to run as a command
and when the job runs in Jenkins which is triggered by a change in content of a file following error is shown
[FSTrigger] Triggered by a change to a file (log)
Building in workspace C:\Users\Pankaj\.jenkins\jobs\convert File to text form\workspace
FATAL: null
java.util.NoSuchElementException
at java.util.TreeMap$PrivateEntryIterator.nextEntry(Unknown Source)
at java.util.TreeMap$EntryIterator.next(Unknown Source)
at java.util.TreeMap$EntryIterator.next(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.buildFromSorted(Unknown Source)
at java.util.TreeMap.putAll(Unknown Source)
at hudson.EnvVars.<init>(EnvVars.java:82)
at hudson.EnvVars$GetEnvVars.call(EnvVars.java:207)
at hudson.EnvVars$GetEnvVars.call(EnvVars.java:205)
at hudson.remoting.LocalChannel.call(LocalChannel.java:45)
at hudson.EnvVars.getRemote(EnvVars.java:202)
at hudson.model.Computer.getEnvironment(Computer.java:837)
at hudson.model.Run.getEnvironment(Run.java:1883)
at hudson.model.AbstractBuild.getEnvironment(AbstractBuild.java:836)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:75)
at hudson.tasks.CommandInterpreter.perform(CommandInterpreter.java:58)
at hudson.tasks.BuildStepMonitor$1.perform(BuildStepMonitor.java:19)
at hudson.model.AbstractBuild$AbstractRunner.perform(AbstractBuild.java:710)
at hudson.model.Build$RunnerImpl.build(Build.java:178)
at hudson.model.Build$RunnerImpl.doRun(Build.java:139)
at hudson.model.AbstractBuild$AbstractRunner.run(AbstractBuild.java:480)
at hudson.model.Run.run(Run.java:1434)
at hudson.model.FreeStyleBuild.run(FreeStyleBuild.java:46)
at hudson.model.ResourceController.execute(ResourceController.java:88)
at hudson.model.Executor.run(Executor.java:239)
Please see to this issue.
I don't think that you need to install Jenkins as a Windows service to execute a batch command as a build step. What might be an issue is that on Windows, commands such as dir are internal to the command interpreter (i.e. cmd.exe). In short, it means that in a Java program you cannot simply run the internal dir command using the java.lang.Runtime.exec("dir") method because there is no such a program as dir.exe (on your PATH). What you should do is execute the command interpreter itself and specify the internal command as a parameter, i.e. java.lang.Runtime.exec("cmd /C dir").
Having that said and being aware that Jenkins is a Java application, it's better to use cmd /C dir instead of just typing dir in Jenkins' job configuration. Internally, Jenkins might use some 3rd pary libraries for executing external processes, such as Apache Commons Exec (see http://commons.apache.org/exec/), which hide the details between internal command(s) and "normal" commands, but from my experience it's not the case for all releases - especially the old ones.
Answer to this question:
Actually i haven't installed Windows as a service in Jenkins. So for this we need to go to "manage Jenkins" and then click on "windows as a service".I.e Installing Jenkins as a windows service.

batch file execution of jar error - Could not find the main class

My intent is to give a batch file that executes a jar of a java application/tool to functional analysts team who do not know java. When I execute the batch file, I get the below error.
Any help is highly appreciated.
How to debug to find out if the issues is in main() which takes care of loading log4j and config files?
Exception in thread "main" java.lang.NoClassDefFoundError: x.y.XYZClass Caused by: java.lang.ClassNotFoundException: x.y.XYZClass at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
Could not find the main class: x.y.XYZClass
. Program will exit.
This what I did so far:
I packaged an application using Maven with the following directory structure:
bin/run.bat
lib/application.jar and other jars that it depends on
config.properties
log4j.xml
jar manifest file content:
Manifest-Version: 1.0
Archiver-Version: Plexus Archiver
Created-By: Apache Maven
Built-By:
Build-Jdk: 1.6.0_20
Main-Class: x.y.XYZClass
Class-Path: vn.jar pn.jar
run.bat content:
java -cp .;../lib/application.jar x.y.XYZClass -Dconfig.properties.name=../config.properties -Dlog4j.configuration=../log4j.xml
I execute run.bat from command line from bin folder.
XYZClass main() does the following:
loads log4j.xml and config.properties and does other stuff.
Verify that the XYZClass exists inside application.jar, in the correct directory. From the bin directory, run the command:
jar tvf ../lib/application.jar.
The output should resemble:
META-INF/
META-INF/MANIFEST.MF
x/
x/y/
x/y/XYZClass.class
Also, since you've created an executable jar (by specifying Main-Class in your manifest), you should be able to run it with: java -jar ..\lib\application.jar

Resources