Spring Batch Listener defined with #Component not being found - spring

We have multiple jobs that all use a similar pattern.
Class file for MyJobListener is defined with #Component annotation.
Listener in XML is defined:
<batch:listeners>
<batch:listener ref="myJobListener" />
</batch:listeners>
Seems to work just fine in some cases but not for others. In some cases, we are getting an error:
ERROR (CommandLineJobRunner.java:355) - Job Terminated in error: Failed to load bean class: mypackage.myJobListener; nested exception is java.io.FileNotFoundException: class path resource [mypackage/myJobListener.class] cannot be opened because it does not exist
Not certain why it is doing this (the jobs are all coded the same way).
UPDATE
This seems to be an environment issue. The Spring Batch jobs run perfectly fine in one environment, but we are in the process of updating to a new server. On the new server, all of our jobs are getting the error (FileNotFoundException).
Please let me know what other information may be needed.
OLD SERVER
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
Java HotSpot(TM) Server VM (build 20.14-b01, mixed mode)
Machine hardware: sun4u
SunOS version: 5.10
Processor type: sparc
Hardware: SUNW,Sun-Fire-480R
NEW SERVER
java version "1.6.0_43"
Java(TM) SE Runtime Environment (build 1.6.0_43-b01)
Java HotSpot(TM) Server VM (build 20.14-b01, mixed mode)
Machine hardware: sun4v
SunOS Version: 5.10
Processor type: sparc
Hardware: sparc SUNW,T5240

Since you didn't post your config...
Make sure you define your class like this:
#Component("myJobListener")
public class MyJobListener implements JobExecutionListener{
And make sure you have something like this somewhere in your ApplicationContext.xml
<context:component-scan base-package="mypackage" />
to load your annotated beans (your listeners)

I failed to come out here and notify everyone of the resolution.
Looks like the issue had to do with a corrupted jar file.
We ran jar -tf on all of the project jar files. For one of the jar files, it recieved an error:
java.util.zip.ZipException: invalid END header (bad central directory offset)
Redploying the jar file seemed to take care of the issue.
Not certain why the jar file had issues. We use ANT to build the jar files, and then combine them into a tar file for deployment. We SFTP the tar file to the unix server, and then untar it. For some reason, the jar files sometimes are having issues, but redeploying seemes to clear it up.

Related

wrong java version in heroku

I've created a spring boot app and would like to run it on heroku.
My app is compiled using java 9.
As I'm deploying it to heroku using the CLI plugin I'm getting
Exception in thread "main" java.lang.UnsupportedClassVersionError: io/safeblocks/firewall/FirewallApplication has been compiled by a more recent version of the Java Runtime (class file version 53.0), this version of the Java Runtime only recognizes class file versions up to 52.0
Clearly this means java versions mismatch. I added the system.properties file to my resources folder with the property java.runtime.version=9 as explained but still getting the same error.
As I run the command heroku run java -version --app myApp I'm getting:
openjdk version "1.8.0_171-heroku"
OpenJDK Runtime Environment (build 1.8.0_171-heroku-b11)
OpenJDK 64-Bit Server VM (build 25.171-b11, mixed mode)
So it seems heroku is still not picking up the required java version.
Any ideas?
I see you added the system.properties file to your resources folder, I did the same mistake. The file system.properties must be placed under the root folder of your project.
The content of your file is correct:
java.runtime.version=9
After you moved the file to the root folder, commit your changes and do:
git push heroku master
Everything should be fine then.

Unable to start Spring Boot executable jar using IBM JRE 1.8

We have a Spring Boot application which is built as an executable jar and runs fine using both the Oracle and OpenJDK JREs (using 1.8 versions).
Attempting to run it using the IBM 1.8 JRE however results in the following error at the command line.
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
This occurs if we execute the jar (using ./application.jar) or using java -jar application.jar
This led us to change the packaging to not make the jar executable and this allows us to start the application using java -jar application.jar. So it appears the IBM JRE doesn't like the launch script.
The problem is we don't want to have two packaging methods for different deployment environments, if possible.
Does anyone have any experience of why the IBM JRE doesn't like the script on the front of the jar file and whether there are any command line options to disable whatever checking its doing?
From your post it is unclear if you have problem with
1) running jar from Linux like chmod a+x application.jar and executing
Or
2) running via /opt/IBM/java/jre/bin/java -jar application.jar
For option 1) it is not a good idea as you do not explicitly choose jvm binary and rely on OS to choose one for you.
Read about binfmt_misc mechanism:
https://en.m.wikipedia.org/wiki/Binfmt_misc
For option 2)-it might be class loading problem, please add
/opt/IBM/java/jre/bin/java -verbose:class -jar application.jar
and consult documentation here: https://www.ibm.com/developerworks/library/j-dclp1/index.html

Springboot Strange Resource Loading Behavior

I'm working on a springboot 1.5.1 application that I'm trying to load a WSDL included in my resources directory in the wsdl directory. Depending on where my application executes I'm getting different results (command line, intellij, cloud foundry) and I can't seem to get all three to work at the same time.
I've tried several ways of locating the resource:
From prior to the migration to springboot we had this (worked in IntelliJ but not java -jar myboot.jar):
this.getClass().getResource("/wsdl/my.wsdl");
I switched it to the typically more correct version and got it to work in IntelliJ and java -jar but not Cloud Foundry:
this.getClass().getClassLoader().getResource("/wsdl/my.wsdl");
I switched it to use the Spring Resource Loader version and it worked in IntelliJ and CloudFoundry but not java -jar:
#Value("classpath:/wsdl/my.wsdl")
private Resource wsdlResource;
wsdlResource.getURL();
On the command line what I've noticed is that it seems to be thinking that BOOT-INF/classes is a JAR file (Note the ! after classes):
Caused by: javax.xml.ws.WebServiceException: Failed to access the WSDL at: jar:file:/C:/dev/redacted/build/libs/redacted.jar!/BOOT-INF/classes!/wsdl/my.wsdl. It failed with:
JAR entry BOOT-INF/classes!/wsdl/my.wsdl not found in C:\dev\redacted\build\libs\redacted.jar.
From looking at IntelliJ's URL, it's referring to the actual source folder which explains why it seems to always work.
What is causing this and how might I universally load these class path resources successfully with springboot?

Grails - How to add Oracle jdbc jar to classpath without placing in /lib?

I am attempting to get my grails application running locally with tomcat, but without placing ojdbc6.jar in /lib. My grails application is deployed to Glassfish and works fine on the server (because the ojdbc6.jar is available there). As expected the error is:
Could not load JDBC driver class [oracle.jdbc.driver.OracleDriver]
(Failed) Approach #1
I first customized my GGTS run-configuration to include the VM arguments:
-cp :/somelocalpath/oracle-jdbc-drivers
However the error persisted.
(Failed) Approach #2
I'm currently looking to use the jvmArgs to point to a local version of the jar.
grails.tomcat.jvmArgs = ["-cp:/somelocalpath/oracle-jdbc-drivers/ojdbc6.jar"]
However a run-war results in:
| Error Server failed to start: tomcat exited prematurely with code '1' (error output: 'Unrecognized option: -cp:/apps/glassfish3/oracle-jdbc-drivers/ojdbc6.jar
Error: Could not create the Java Virtual Machine.
Error: A fatal exception has occurred. Program will exit.
')
I should clarify my main focus - I do not want the jar to be included in the final war.
Any help would be appreciated. Thanks!
From the documentation:
grails.war.resources lets you do any extra processing you want
before the WAR file is finally created.
In your case, you need to add something like that to your build config to exclude the Jar of the final WAR.
grails.war.resources = { stagingDir ->
delete(file:"${ stagingDir }/WEB-INF/lib/yourJarFile.jar")
}

JDBC Driver class not found: oracle.jdbc.OracleDriver

I have installed a third party java webservice which uses Oralce jdbc thin driver to write data into Oracle database. When i run this, i get the following error;
JDBC Driver class not found: oracle.jdbc.OracleDriver
I have oracle installed and set classpath variable to following value:
*D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.zip;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.zip;C:\Program Files\Java\jdk1.7.0\jre\lib\rt.jar*
and path variable to following value;
*D:\oracle\product\10.2.0\client_1\bin;C:\Program Files\Java\jdk1.7.0\bin\;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\classes12.zip;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.jar;D:\oracle\product\10.2.0\client_1\jdbc\lib\ojdbc14.zip*
Any suggestion why web service is not able to identify jdbc driver?
Thanks
I know 2 ways of turning Java app into Windows service and both do not use CLASSPATH. One is Java Service Wrapper by Tanuki Software. This tool uses wrapper.conf where you can show directories with .jar libraries:
# Java Classpath (include wrapper.jar) Add class path elements as
# needed starting from 1
wrapper.java.classpath.1=c:\jars\*
wrapper.java.classpath.2=myservice.jar
Second tool I know is JSL: Java Service Launcher. In this tool there is jsl.ini where you put command line to run your server. It can use java with -cp option to show location of .jar libraries:
[defines]
MY_LIBS=d:\jars\*
AXIS_LIBS=d:\axis2-1.5.4\lib\*
CLASSPATH=.;%MY_LIBS%;%AXIS_LIBS%
export = CLASSPATH
...
[java]
...
cmdline = -Dfile.encoding=utf8 -cp %CLASSPATH% example.my.server
In both configuration you can use * to add all .jar files or you can show those files one by one (just like in CLASSPATH).
At first you should know what Windows is trying to execute. Check it in the service properties page. Then try to localize its configuration. If it uses one of tools I know then you know what to change. Other tools probably have similar configuration.
Method 1:
Download ojdbc.jar
add ojdbc6.jar to deployment assembly.
Right click on project->properties->select deployment assembly->click on 'Add'
->select 'Archives from File System'->browse to the folder where ojdbc6.jar is saved.->add the jar->click finish->Apply/OK.
Method 2:
if you want to add ojdbc.jar to your maven dependencies you follow this link:
http://www.mkyong.com/maven/how-to-add-oracle-jdbc-driver-in-your-maven-local-repository/
.
.
Even if you're using a maven project it is not necessary to add ojdbc to maven dependencies(method 2), method 1 (adding directly to deployment assembly) works just fine.
Make sure you have the ojdbc jar file (make sure you are using the correct one because depending on java version you may need to choose a different one).
use ojdbc14.jar for Java 1.4
use ojdbc5.jar for Java 1.5
ojdbc6.jar for Java 1.6
here is linke where you can download ojdbc6.jar file
http://www.oracle.com/technetwork/database/enterprise-edition/jdbc-112010-090769.html
You also have to add the jdbc jar to your server classpath. if tomcat, rigth-click on your Project->run as->run configurations, click on classpath and add your jdbc jar in Add external jars option
add ojdbc-6.jar to your lib directory of tomcat installation. Maven will downlowd this jar for you in .m2 directory, but you need to have this jar in tomcat lib as well.

Resources