While trying to cennect HPQC from a 64bit machine(having 64bit JAVA, and ECLIPSE), I am getting the below mentioned exception:
Exception in thread "main" com4j.ExecutionException: com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153
at com4j.ComThread.execute(ComThread.java:203)
at com4j.Task.execute(Task.java:25)
at com4j.COM4J.createInstance(COM4J.java:97)
at com4j.COM4J.createInstance(COM4J.java:72)
at com.qc.ClassFactory.createTDConnection(ClassFactory.java:16)
at com.java.Test.main(Test.java:25)
Caused by: com4j.ComException: 80040154 CoCreateInstance failed : Class not registered : .\com4j.cpp:153
at com4j.Native.createInstance(Native Method)
at com4j.COM4J$CreateInstanceTask.call(COM4J.java:117)
at com4j.COM4J$CreateInstanceTask.call(COM4J.java:104)
at com4j.Task.invoke(Task.java:51)
at com4j.ComThread.run0(ComThread.java:153)
at com4j.ComThread.run(ComThread.java:134)
PFB my code:
public static void main(String[] args) {
// TODO Auto-generated method stub
//QC url
String url = "https://qc_link/qcbin";
//username for login
String username = "username";
//password for login
String password = "password";
//domain
String domain = "domain";
//project
String project = "project";
ITDConnection itdc = ClassFactory.createTDConnection();
System.out.println("Connecting");
itdc.initConnectionEx(url);
itdc.connectProjectEx(domain, project, username, password);
System.out.println("Connected......");
}
}
The above code works fine for 32bit Java and Eclipse.
Any help would be highly appreciated.
Regards,
Parag
The COM API's are 32-bit only and cannot be accessed by a 64-bit process. I have the same problem with .NET applications where I'm stuck in 32-bit until I can move to the REST API (which is bit-less) or host my COM-reliant code in an external process.
This issue can be solved by registering all 3 .dll files in c:\Windows\SysWow64. instead of c:\Windows\System32.
Hope it might be helpful:)
Related
I've used 'net.schmizz.sshj.SSHClient' package to connect to a server.
Below is my code:
public class ConnectToServer {
String hostName = "10.250.176.6";
int port = 22;
public ConnectToServer(String hostName, int port) {
this.hostName = hostName;
this.port = port;
}
public void ssh() {
SSHClient ssh = new SSHClient();
String cmd = "ipconfig";
try {
ssh.connect(this.hostName, this.port);
ssh.isConnected();
final Process process = Runtime.getRuntime().exec(cmd);
ssh.disconnect();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
However, I faced to an error: "Exception in thread "reader" java.lang.NoClassDefFoundError: org/bouncycastle/crypto/ec/CustomNamedCurves".
I added bcprov-jdk15on-1.49 and bouncycastle.jar into my classpath.
Please help me to resolve this error.
Complete exception:
08:46:05.526 [main] DEBUG net.schmizz.concurrent.Promise - Awaiting <<kex done>>
08:46:05.528 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Received SSH_MSG_KEXINIT
08:46:05.528 [reader] DEBUG n.s.sshj.transport.KeyExchanger - Negotiated algorithms: [ kex=curve25519-sha256#libssh.org; sig=ecdsa-sha2-nistp256; c2sCipher=aes128-ctr; s2cCipher=aes128-ctr; c2sMAC=hmac-sha1; s2cMAC=hmac-sha1; c2sComp=none; s2cComp=none ]
**Exception in thread "reader" java.lang.NoClassDefFoundError: org/bouncycastle/crypto/ec/CustomNamedCurves**
at net.schmizz.sshj.transport.kex.Curve25519DH.getCurve25519Params(Curve25519DH.java:60)
at net.schmizz.sshj.transport.kex.Curve25519SHA256.initDH(Curve25519SHA256.java:44)
at net.schmizz.sshj.transport.kex.AbstractDHG.init(AbstractDHG.java:46)
at net.schmizz.sshj.transport.KeyExchanger.gotKexInit(KeyExchanger.java:236)
at net.schmizz.sshj.transport.KeyExchanger.handle(KeyExchanger.java:356)
at net.schmizz.sshj.transport.TransportImpl.handle(TransportImpl.java:503)
at net.schmizz.sshj.transport.Decoder.decode(Decoder.java:102)
at net.schmizz.sshj.transport.Decoder.received(Decoder.java:170) at net.schmizz.sshj.transport.Reader.run(Reader.java:59)
Caused by: java.lang.ClassNotFoundException: org.bouncycastle.crypto.ec.CustomNamedCurves
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)
Your jar is probably missing its dependencies (or some of it.) If its a maven project i suggest you rather switch to Maven.
A nice tutorial can be found here: Maven in 5 Minutes
I think, the SSH Client is missing org.Bouncycastle.crypto as libary (dependency). Quick way to fix this is to get the jar for it too.
This issue might be occurred due to use of different versions of bouncycastle jars in the project.
the solution is ,
to find the different versions of bouncycastle jars getting used directly or indirectly in the project.
try to use one version of bouncycastle jars in whole project.
make changes according to version which you have chosen to use across project as code written with one version of bouncycastle jar may not work for other version of bouncycastle.
Clean your project or rebuild it again.
If the problem is not solved, please post complete exception so that we will get more clarity.
I recently switched to intellij but I'm finding it hard to connect to my localDB. The same code worked on eclipse fine. Also I have already added the sqljdbc42.jar as a module dependency.
package com.enter;
import java.sql.*;
public class SqlConnect {
private String username, password, url;
public Connection conn;
public SqlConnect() {
username = "user=admin;";
password = "password=admin";
url = "jdbc:sqlserver://Bossman-PC\\SQL2014TRAINING;databaseName=EnterDB;";
Connect();
}
public SqlConnect(String user, String pass) {
username = user;
password = pass;
url = "jdbc:sqlserver://Bossman-PC\\SQL2014TRAINING;databaseName=EnterDB;";
Connect();
}
public void Connect() { //Loads sql driver and creates a connection object with local database
try {
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
String connectionUrl = url + username + password;
conn = DriverManager.getConnection(connectionUrl);
System.out.println("Connected.");
} catch(Exception e) {
e.printStackTrace();
}
}
public Connection getConnection() {
return conn;
}
}
Error produced:
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/bind/DatatypeConverter
at com.microsoft.sqlserver.jdbc.SQLServerConnection.sendLogon(SQLServerConnection.java:4098)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.logon(SQLServerConnection.java:3160)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.access$100(SQLServerConnection.java:43)
at com.microsoft.sqlserver.jdbc.SQLServerConnection$LogonCommand.doExecute(SQLServerConnection.java:3123)
at com.microsoft.sqlserver.jdbc.TDSCommand.execute(IOBuffer.java:7505)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.executeCommand(SQLServerConnection.java:2445)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectHelper(SQLServerConnection.java:1981)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.login(SQLServerConnection.java:1628)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connectInternal(SQLServerConnection.java:1459)
at com.microsoft.sqlserver.jdbc.SQLServerConnection.connect(SQLServerConnection.java:773)
at com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1168)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:678)
at java.sql/java.sql.DriverManager.getConnection(DriverManager.java:252)
at com.enter.SqlConnect.Connect(SqlConnect.java:25)
at com.enter.SqlConnect.<init>(SqlConnect.java:12)
at com.enter.Login.makeConnection(Login.java:26)
at com.enter.Login.<init>(Login.java:16)
at com.enter.Execute.initLogin(Execute.java:14)
at com.enter.Execute.main(Execute.java:9)
Caused by: java.lang.ClassNotFoundException: javax.xml.bind.DatatypeConverter
at java.base/jdk.internal.loader.BuiltinClassLoader.loadClass(BuiltinClassLoader.java:582)
at java.base/jdk.internal.loader.ClassLoaders$AppClassLoader.loadClass(ClassLoaders.java:185)
at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:496)
... 19 more
Process finished with exit code 1
Any help would be greatly appreciated. I've also tried the overloaded DriverManager.getConnection(url, user, pass) method and same error.
For Java 9+ compatibility, you need to use version 6.4.0 or higher for the Java version you use as identified by the jreXX version suffix. Use the highest version lower or equal to you Java version).
Previous answer
As noted by Microsoft on GitHub:
Currently none of our driver released Jars are compatible with JDK9.
You can either switch to using the Java 8 JDK, or you can incorporate Microsoft's development code from their 'JDBC4.3' branch into your project and use that with the Java 9 JDK.
You can get this to work if you include the extra jvm parameter
--add-modules=java.se.ee
Which in your run configuration in Intellij would go here
This then includes several modules which in java 9 have been marked as deprecated for future removal so these could be removed in java 10 so it is only really a temporary solution until Microsoft release java 9 compatible jdbc drivers.
More on this can be found in the Java9 Migration guide
If you have a maven build, add the following to your pom.xml
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
</dependency>
im trying to create a connection to the MSSQL08 database on my computer :
this is my simple piece of code :
public class JavaApplication2 {
/**
* #param args the command line arguments
*/
public static void main(String[] args) throws ClassNotFoundException {
String userName ="username";
String password ="password";
String url ="jdbc:microsoft:sqlserver://localhost; databaseName=Lando";
Class.forName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
try {
Connection conn = DriverManager.getConnection(url, userName, password);
} catch (SQLException ex) {
Logger.getLogger(JavaApplication2.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
i get this Error :
SEVERE: null java.sql.SQLException: No suitable driver found for
jdbc:microsoft:sqlserver://localhost; databaseName=Lando at
java.sql.DriverManager.getConnection(DriverManager.java:596) at
java.sql.DriverManager.getConnection(DriverManager.java:215) at
javaapplication2.JavaApplication2.main(JavaApplication2.java:34)
when i change the URL to this : "jdbc:sqlserver://localhost; databaseName=Lando"
then i get this Error :
SEVERE: Java Runtime Environment (JRE) version 1.7 is not supported by
this driver. Use the sqljdbc4.jar class library, which provides
support for JDBC 4.0. Exception in thread "main"
java.lang.UnsupportedOperationException: Java Runtime Environment
(JRE) version 1.7 is not supported by this driver. Use the
sqljdbc4.jar class library, which provides support for JDBC 4.0. at
com.microsoft.sqlserver.jdbc.SQLServerConnection.(SQLServerConnection.java:304)
at
com.microsoft.sqlserver.jdbc.SQLServerDriver.connect(SQLServerDriver.java:1011)
at java.sql.DriverManager.getConnection(DriverManager.java:571) at
java.sql.DriverManager.getConnection(DriverManager.java:215) at
javaapplication2.JavaApplication2.main(JavaApplication2.java:34)
I added the sqldjbc4.jar file to the project libraries in neatbeans, i also set the CLASSPATH in enviroment variables to the directory of the Microsoft Driver.
what could be the problem ?
I created sample class Testws with one simple method sayHi(String name) that simply showing welcome message. The target is to create web service application for this class and applying OWSM policies.
All the needed file is generated from Jdeveloper 11.1.1.7 and I added the oracle/wss_username_token_client_policy to the client side in TestwsPortClient. Problem is that when I run the main method from TestwsPortClient I got the following error:
SEVERE: java.io.FileNotFoundException: .\config\jps-config.xml (The system cannot find the path specified)
Although I tried (But it did not work) to set the system propriety to find the missing file as follow:
System.setProperty("oracle.security.jps.config",
"C:\\Users\\user\\AppData\\Roaming\\JDeveloper\\system11.1.1.7.40.64.93\\DefaultDomain\\config\\fmwconfig\\jps-config.xml");
Here is the Client Class TestwsPortClient:
public static void main(String[] args) {
testwsService = new TestwsService();
SecurityPoliciesFeature securityFeatures =
new SecurityPoliciesFeature(new String[] { "oracle/wss_username_token_client_policy" });
Testws testws = testwsService.getTestwsPort(securityFeatures);
// Add your code to call the desired methods.
System.setProperty("oracle.security.jps.config",
"C:\\Users\\user\\AppData\\Roaming\\JDeveloper\\system11.1.1.7.40.64.93\\DefaultDomain\\config\\fmwconfig\\jps-config.xml");
List<CredentialProvider> credProviders =new ArrayList<CredentialProvider>();
String username = "weblogic";
String password = "weblogic1";
CredentialProvider cp =new ClientUNTCredentialProvider(username.getBytes(), password.getBytes());
credProviders.add(cp);
Map<String, Object> rc = ((BindingProvider)testws).getRequestContext();
rc.put(WSSecurityContext.CREDENTIAL_PROVIDER_LIST, credProviders);
testws.sayHi("Salman");
}
Here the exception stack trace:
Note: the stack trace is too long this is just part of it where I think it will gives an idea about the error
SEVERE: java.io.FileNotFoundException: .\config\jps-config.xml (The system cannot find the path specified)
SEVERE: java.io.FileNotFoundException: .\config\jps-config.xml (The system cannot find the path specified)
INFO: WSM-09004 Component auditing cannot be initialized.
INFO: Recipient Alias property not configured in the policy. Defaulting to encrypting with signers certificate.
WARNING: JPS-00065 Jps platform factory creation failed. Reason: java.lang.ClassNotFoundException: oracle.security.jps.se.JpsSEPlatformFactory.
WARNING: JPS-00065 Jps platform factory creation failed. Reason: {0}.
......
at $Proxy34.sayHi(Unknown Source)
at test.TestwsPortClient.main(TestwsPortClient.java:44)
Caused by: oracle.security.jps.JpsException: JPS-00065: Jps platform factory creation failed. Reason: java.lang.ClassNotFoundException: oracle.security.jps.se.JpsSEPlatformFactory.
at oracle.security.jps.ee.JpsPlatformFactory$2.run(JpsPlatformFactory.java:197)
at oracle.security.jps.ee.JpsPlatformFactory$2.run(JpsPlatformFactory.java:190)
........
I am very new to JMX. I am trying to log the tomcat statistics like threads used, cache, sessions and other standard values. I am trying to achieve this with java code.
I have done the following things as of now. (I am trying to access the values of a local tomcat 6.0 monitor on windows)
1)I have added the following options in the catalina.bat
set CATALINA_OPTS=-Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.port=9004 -Dcom.sun.management.jmxremote.ssl=false -Dcom.sun.management.jmxremote.authenticate=false
After that I restarted the tomcat server.
2) Then I wrote the following code.
package com.ss.fg;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.ObjectName;
public class SystemConfigManagement
{
static MBeanServer connection = ManagementFactory.getPlatformMBeanServer();
public static void main(String[] args) throws Exception {
getActiveSession();
}
public static void getActiveSession()throws Exception
{
ObjectName name=new ObjectName("Catalina:type=Manager,path=/MMDisplay,host=localhost");
String attrValue = ManagementFactory.getPlatformMBeanServer().getAttribute(name, "activeSessions").toString();
System.out.println(attrValue);
}
}
I even tried context instead of path.
I am getting the following exception
Exception in thread "main" javax.management.InstanceNotFoundException: Catalina:type=Manager,path=/MMDisplay,host=localhost
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getMBean(Unknown Source)
at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.getAttribute(Unknown Source)
at com.sun.jmx.mbeanserver.JmxMBeanServer.getAttribute(Unknown Source)
at com.softsmith.floodgates.SystemConfigManagement.getActiveSession(SystemConfigManagement.java:15)
at com.softsmith.floodgates.SystemConfigManagement.main(SystemConfigManagement.java:10)
How can I resolve this issue?
Should I add Some jar files, or should I do some other settings..
Please help
When using
MBeanServer connection = ManagementFactory.getPlatformMBeanServer();
you are actually connectiong to the MBean-Server of the JVM running your program, not to that of your tomcat-instance, so it doesn't know of the Catalina-MBeans.
To establish a connection to a remote jvm try something like:
JMXServiceURL url = new JMXServiceURL("service:jmx:rmi:///jndi/rmi://servername:9999/jmxrmi");
JMXConnector connector = JMXConnectorFactory.connect(url);
connector.connect();
MBeanServerConnection server = connector.getMBeanServerConnection();
//do work here
ObjectName name = new ObjectName("Catalina:type=Manager,path=/manager,host=localhost");
String attrValue = mb.getAttribute(name, "activeSessions").toString();
System.out.println(attrValue);
//..and don't forget to close the connection
connector.close();
If the error is still there make sure you are using the correct object-name.
When i using
MBeanServer connection = ManagementFactory.getPlatformMBeanServer();
i am actually connectiong to the MBean-Server of the JVM running my program, not to that of my tomcat-instance, so it doesn't know of the Catalina-MBeans.
so i try to connected remotly to jmx but have error like this :
java.io.IOException: Failed to retrieve RMIServer stub: javax.naming.CommunicationException [Root exception is java.rmi.ConnectIOException: error during JRMP connection establishment; nested exception is....
and now i solve :
for first i added catalina-jmx-remote.jar to TOMCAT_HOME/lib directory of Tomcat and then configure the listener on server.xml i added the following
snippet under the tag :
<Listener className="org.apache.catalina.mbeans.JmxRemoteLifecycleListener" rmiRegistryPortPlatform="10001" rmiServerPortPlatform="10002" useLocalPorts="true" />
and finally i set the following sentence in my catalina.bat :
JAVA_OPTS="$JAVA_OPTS -Djava.rmi.server.hostname=localhost -Dcom.sun.management.jmxremote -Dcom.sun.management.jmxremote.authenticate=false -Dcom.sun.management.jmxremote.ssl=false"