I have developed a java web application integrating with SAP. I have developed it with Linux Server and Tomcat 7.0. I have added sapjco3.jar and libsapjco3.so in WEB-INF/lib folder. It is working fine local server. But when deploying WAR file in remote server the following error is generating.
java.lang.NoClassDefFoundError: com.sap.conn.rfc.driver.CpicDriver
at com.sap.conn.rfc.engine.DefaultRfcRuntime.createChannel(DefaultRfcRuntime.java:52)
at com.sap.conn.rfc.engine.RfcIoOpenCntl.open_channel(RfcIoOpenCntl.java:1260)
at com.sap.conn.rfc.engine.RfcIoControl.ab_rfcopen(RfcIoControl.java:85)
at com.sap.conn.rfc.api.RfcApi.RfcOpen(RfcApi.java:83)
at com.sap.conn.jco.rt.MiddlewareJavaRfc$JavaRfcClient.connect(MiddlewareJavaRfc.java:1107)
at com.sap.conn.jco.rt.ClientConnection.connect(ClientConnection.java:659)
at com.sap.conn.jco.rt.PoolingFactory.init(PoolingFactory.java:103)
at com.sap.conn.jco.rt.ConnectionManager.createFactory(ConnectionManager.java:171)
at com.sap.conn.jco.rt.DefaultConnectionManager.createFactory(DefaultConnectionManager.java:44)
at com.sap.conn.jco.rt.ConnectionManager.getFactory(ConnectionManager.java:160)
at com.sap.conn.jco.rt.RfcDestination.initialize(RfcDestination.java:754)
at com.sap.conn.jco.rt.RfcDestination.ping(RfcDestination.java:964)
at com.my.ciry.sap.Connection.<init>(Connection.java:63)
The error is arising when ping the destination from Tomcat Server.
private JCoDestination dest;
public Connection(SapSystem system) {
dest = JCoDestinationManager.getDestination(SAP_SERVER);
dest.ping();
}
What's the cause of the problem.
SAP Servers are generally configured based on
System ID , the Message Server and possible a Group Server along with an Instance Number.
You probably need to pass these parameters when instantiating your connection. It could be that on localhost, these are not needed/ignorable, but on production, it is required.
Try connecting to the server using SAP's tools and try to provide all the settings that you would otherwise provide.
If you post what settings you are using for your JCO, perhaps I can help more.
Ideally, you should keep libsapjco3.so file outside your web application. Place it in any arbitary location and add that folder path to LD_LIBRARY_PATH environment variable. sapjco.jar can be in your classpath.
If the tomcat cannot load the .so file using the environment variable, you can try using System.setProperty("java.library.path", "folder_path_of_.so_file");
OR try to supply this variable by editing tomcat configuration files.
Finally, ensure that folder_path_of_.so_file has needed privileges for tomcat user.
This will solve your problem.
......
Related
My project uses some external dependencies to create JPA datasources and other entity manager related configuration (which I do not have access). To enable ssl I was using this url format :
url: jdbc:mariadb:loadbalance://<<Server>>:<port>/<<database>>?serverSslCert=${someCertificatePemFileLocation}&verifyServerCertificate=true&useSSL=true&enabledSslProtocolSuites=TLSv1.1&autoReconnect=false&disableSslHostnameVerification=true
The problem is when I'm testing my database connection in my local system. I'm able to connect by just giving absolute path for "someCertificatePemFileLocation" which is like "/Users/myName/path/to/pem/PemFile.pem". I mounted some location in my server, Path for the certificate as "/opt/some/other/certs/path/PemFile.pem". But I'm unable to make connection with my database on the server. Please note the serverPath is outside my jar file.
Is this the correct way to give path of files outside jar or Am I having other problem and this is not related to file path?
We have a database library that gets the connection information (user, host, etc) from a properties file. This file can be a config.properties file located in the classpath, or next to the execution jar or can be passed as an argument -Dproperties=/path/to/myConfig.properties.
We also have several applications that use this library, so each one has its own config.properties file used in its own execution.
But now I'm creating two web applications that use the same library. So, if I deploy them in Tomcat (war file), I have two options (to my knowledge):
1.- Include each config inside the WAR file. But with this, every time I need to tweak something in the config.properties I'll have to repack the war.
2.- Pass the -Dproperties parameter as an execution argument of Tomcat. But different war deployments will have to share the same properties file.
Is there a way around this?
Can I pass the -D argument to a specific deployment in Tomcat (or any other server)?
PS: This is one of the scenarios we have, but is not constraint to database connection info. We have other libraries that get parameters through config.properties file.
EDIT: I want to be able to have different config.properties file for each deployment. Not the same properties shared among them.
I think I found a way around using self contained webserver inside the application, like Jetty.
We've a similar requirement in which we share a common property file between different applications deployed into JBoss EAP server.
In $JBOSS_HOME/bin/standalone.conf file you can add configuration file path as below:
JAVA_OPTS="$JAVA_OPTS -DCONFIG_LOCATION=/external/config/configuration.properties"
Start the server with above specified property and within your application you can read this property file with apache commons-configuration api as below:
try {
props = new PropertiesConfiguration(System.getProperty("CONFIG_LOCATION"));
FileChangedReloadingStrategy strategy = new FileChangedReloadingStrategy();
// Delay 30s
// strategy.setRefreshDelay(30000);
props.setReloadingStrategy(strategy);
} catch (ConfigurationException e) {
e.printStackTrace();
}
With this reload strategy you can change your properties while your server is running. Also you can specify the interval after which all properties specified in the external file needs to be refreshed within your application without bouncing it. Hope this helps!
You can create an environment variable whose value will be the path where the properties file are located. Later use this environment variable will creating bean for property placeholder config.
for UNIX, you can add in your bash profile file
export CONF_DIR=/path/to/conf
And in spring context file, add this
<context:property-placeholder
location="file:///${CONF_DIR}/path/myConfig1.properties,
file:///${CONF_DIR}/path/myConfig2.properties"
properties-ref="applicationDefaultProperties" ignore-resource-not-found="false"
ignore-unresolvable="false"/>
So, when you want to change any thing in the properties file, you can change at one location, and then restart the application to load the new values in your app.
So, if your config file is this
db.user=username
db.password=password
Inside java class, you can use the keys as like this
#Value("${db.user")
private String username;
#Value("${db.password")
private String password;
The solution I found for my problem is using an embedded web server in my application. In my case, I'm using Jetty.
Now I pack my application as an executable jar and pass the system parameters as -D arguments and they live inside the instance of the application.
Like this:
java -Dproperties=config.properties -jar java_app_with_embedded_server.jar
I know this question has answered many a time with most useful answer as below,
Where to place and how to read configuration resource files in servlet based application?
However, We have some special requirement as below,
Webapp will be deployed to tomcat.
Normal java app in form of .jar will be placed under folder /myapp
myappConfig.property file will be placed under /myapp
Directory Structure on client machine
/myapp
/myapp.jar
/assests/myappConfig.property
/tomcat/webapps/myapp.war
Basically myapp.jar and myapp.war will access sql db connection values for MySql database connection and db operations.
Accessing myappConfig.property from myapp.jar --> Working fine
File jarPath = new File(Myapp.class.getProtectionDomain().getCodeSource().getLocation().getPath());
String propertiesPath = jarPath.getParent();
System.out.println(" propertiesPath-" + propertiesPath);
mainProperties.load(new FileInputStream(propertiesPath + "\\assets\\myapp.property"));
Can anyone help/suggest how to implement,
Accessing myappConfig.property file from mywebapp,
provided run time change in myappConfig.property file does not required myapp.war to be redeployed
Thanks for your help in advance.
edit
Below is the steps in which we want to deliver the project to client.
Below is my app directory
/myapp
/myapp.jar
/assests/myappConfig.property
/tomcat/webapps/myapp.war
pack everything in one package with some packaging tool.
Run this package in client machine at any location and it will have same directory structure as above
Here, I do not want to hard code any location in webapp or tomcat for "/assests/myappConfig.property"
Normal Java app I can read property file but for wepapp I am not getting clear idea for how to do that?
You can add a <context> to tomcat/conf/server.xml (in this example, linux path):
<Context docBase="/home/yourusername/tomcat/assests" path="/assets" />
If you are using Windows:
<Context docBase="C:\path\to\myapp\assets" path="/assets" />
And then you can access it like any other resource within your webapp (e.g.: /assets/myappConfig.property).
If you are using JDBC for example, you could store the connection properties in a Singleton and request it from there, and that class could take care of change checks on that file.
I am currently working on a weblogic 10 application server that has several installed ears. I got a request to change the application name of some aps as they appear in
Home >Summary of Deployments
I went to the appropiate Plan.xml and changed the with the appropriate name, restarted the domain but the name did not change.
Any ideas?
You can do that easily by modifying config.xml file in
DOMAIN_NAME/config
You can just modify the name and restart the server.
<app-deployment>
<name>jms-rename</name>
<target>DefaultServer</target>
<module-type>ear</module-type>
<source-path>C:\JMSTest\application\jms\target\jms-0.0.1-SNAPSHOT.ear</source-path>
<security-dd-model>DDOnly</security-dd-model>
</app-deployment>
The answer was very simple in the end. I added inside the EAR's manifest file the following entry
Weblogic-Application-Version: x.y.z
In this way I didn't have to mess up with any of the Weblogics configuration files.
In the standlone.xml file in JBoss AS7, I have set the variable my.dir in system properties as
<system-properties>
<property name="my.dir" value="D:\\mylocation"
</system-properties>
Now I am trying to use this variable to specify the location of the keystore file in the standalone.xml in the following way
certificate-key-file="${my.dir}\cert\mycert.keystore"
However, while starting JBoss, I am getting IO exception as JBoss is not able to locate the path. Could you please let me know if I am doing anything wrong?
As far as I know the ssl element in the jboss web subsystem does not support system property substitution (yet). You have 3 choices:
Use an absolute path
Use a relative path from $JBOSS_AS7\bin location
Store the certificate in the default location where JBoss looks for them - ${user.home}/.keystore which is the operating system home directory the user running jboss.web.
See more details on jboss.web ssl configuration here.