problem: My Java code cannot see BouncyCastle libraries.
situation: I have a component that needs to use BouncyCastle libraries. The other vendor has provided some Java examples on how to use their API and the examples uses BouncyCastle.I have tried using regular Java libraries (java.*) and it's not working. I'm just testing to see if the implementation requires BouncyCastle.
mvn integration with BouncyCastle:
To integrate BouncyCastle into my maven project, I changed core/pom.xml and added these lines
<dependency>
<groupId>commons-codec</groupId>
<artifactId>commons-codec</artifactId>
<version>1.10</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcpkix-jdk18on</artifactId>
<version>1.71</version>
</dependency>
<dependency>
<groupId>org.bouncycastle</groupId>
<artifactId>bcprov-jdk18on</artifactId>
<version>1.71</version>
</dependency>
According to this https://www.bouncycastle.org/latest_releases.html, I need to use jdk18on for Java 8+. I'm on Java11.
observations:
When running an "mvn clean install", mvn fetches the BouncyCastle libraries. (I previously didn't have the bouncycastle folder prior to running the nvm command. Also mvn does not produce any compilation errors)
my-work-desktop-mac in repository/org/bouncycastle
➜ pwd
/Users/myuser/.m2/repository/org/bouncycastle
my-work-desktop-mac in repository/org/bouncycastle
➜ ls -al
0755 - myuser 18 Apr 09:59 bcpkix-jdk18on
0755 - myuser 18 Apr 09:59 bcprov-jdk18on
0755 - myuser 18 Apr 09:59 bcutil-jdk18on
my-work-desktop-mac in repository/org/bouncycastle
➜ find . -iname "*.jar" -type f
./bcprov-jdk18on/1.71/bcprov-jdk18on-1.71.jar
./bcutil-jdk18on/1.71/bcutil-jdk18on-1.71.jar
./bcpkix-jdk18on/1.71/bcpkix-jdk18on-1.71.jar
When I try to debug this code, my execution never stops at the 2nd or 3rd breakpoint after "stepping over" on the 1st breakpoint.
try {
String publicKeyAsString = "my-public-key-here";
PEMParser pemParser = new PEMParser(new StringReader(publicKeyAsString)); //1st breakpoint
String test=""; //2nd breakpoint
} catch (Exception e) {
System.out.println("error in here"); //3rd breakpoint
}
I'm using IntelliJ and IntelliJ often highlights possible issues/problems in my code. Right now, it's highlighting all the import statements I have for "org.bouncycastle" and "PEMParser" line in no2.
If you can see the lib in maven repo locally then issue with IntelliJ, try to clean cache and restart the IntelliJ.
Your question is neither clear nor specific.
BouncyCastle must be working if your code is compiling. The PEMParser class belongs to the org.bouncycastle.openssl package which simply isn't available if BouncyCastle isn't available. So, if BouncyCastle wasn't available, your code wouldn't compile.
Are you having a problem with IntelliJ or with BouncyCastle?
What issues are being reported by IntelliJ?
Have you configured BouncyCastle as a Security provider?
if (Security.getProvider("BC") == null) {
Security.addProvider(new BouncyCastleProvider());
}
However, it sounds more like you are having an issue with IntelliJ but it's simply not clear.
To avoid any problems (for the moment) with IntelliJ, please use the command line with the mvn command.
What do you mean by "it's not working". This is not clear. What error are you receiving? How is it not working?
Related
I have a program that executes a command jpub like this
executeCommand("jpub -u "+args[0]+"/"+args[1]+" -package="+args[3]+" -codegen=iso -url="+args[2]+" -plsqlpackage="+resultSetMain.getString(1)+" -dir "+args[4]+" -case=lower -plsqlfile="+resultSetMain.getString(1)+"_wrapper.sql,"+resultSetMain.getString(1)+"_wrapper_drop.sql -s "+resultSetMain.getString(1)+":"+resultSetMain.getString(1)+"_OUT -compile=false -omit_schema_names");
when execCommand is simply a private function that gets a runtime instance and executes the command :
Process pr = rt.exec(command);
I'm using maven to build my project.
when I run my program with eclipse Juno everything is fine, but when I want to migrate to the latest version of eclipse when I run mvn clean install i had this error
Exception in thread "main" java.lang.NoClassDefFoundError: sun/io/CharToByteConverter
I have tried to build a jar converter that contains this class and to add it to my project but this is not working
<repositories>
<repository>
<id>my-local-repo</id>
<url>file://${basedir}/lib</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>ma.me</groupId>
<artifactId>converter</artifactId>
<version>1.0.0</version>
</dependency>
</dependencies>
How can I solve this problem?
After reading the documentation of the JPublisher I have found a section that speaks about how to specify JVM through which JPublisher is invoked doc.
We can use the -vm=value parameter where the value is the location of JDK6or 7, so you can run the command like this:
executeCommand("jpub -u "+args[0]+"/"+args[1]+" -package="+args[3]+" -codegen=iso -url="+args[2]+" -vm="+args[8]+" -plsqlpackage="+resultSetMain.getString(1)+" -dir "+args[4]+" -case=lower -plsqlfile="+resultSetMain.getString(1)+"_wrapper.sql,"+resultSetMain.getString(1)+"_wrapper_drop.sql -s "+resultSetMain.getString(1)+":"+resultSetMain.getString(1)+"_OUT -compile=false -omit_schema_names");
In our exemple args[8] contains the path of executable java 6 for exemple : D:\Java\jdk6\bin\java
I'm trying to import Cplex on a Maven project (using Ubuntu 16.04).
So I added cplex.jar to maven repository with this command :
mvn install:install-file -DgroupId=cplex -DartifactId=cplex -Dversion=12.8 -Dpackaging=jar -Dfile=/cplex/install/dir/CPLEX_Studio128/cplex/lib/cplex.jar
I added the dependency to my pom.xml :
<dependency>
<groupId>cplex</groupId>
<artifactId>cplex</artifactId>
<version>12.8</version>
</dependency>
I added the link of the Cplex Native Library (.so files) to the LD_LIBRARY_PATH :
export LD_LIBRARY_PATH="/cplex/install/dir/CPLEX_Studio128/cplex/bin/x86-64_linux"
But when I'm running my maven project with :
mvn exec:java -Dexec.mainClass="main.main"
I got the following error : java.lang.IncompatibleClassChangeError: Implementing Class
I have already checked this question but I don't understand, in this case, what kind of incompatibles binary changes can be made.
Is it possible that there's some "incompatibles binary changes" ?
And if it's not, is there any other explanation than an "incompatibles binary changes" to this error ?
Edit
I also use OPL library (same installation than Cplex library) and I have only the 12.8 version of Cplex and Oplall on my system.
I tried to clean and build again but got the same error.
This is the code I try to run (in ModelFileEvaluator.java) :
IloOplFactory.setDebugMode(true);
IloOplFactory oplF = new IloOplFactory();
IloOplErrorHandler errHandler = oplF.createOplErrorHandler();
IloOplModelSource modelSource = oplF.createOplModelSource(fileName);
IloOplSettings settings = oplF.createOplSettings(errHandler);
IloOplModelDefinition def = oplF.createOplModelDefinition(modelSource,settings);
IloCplex cplex = oplF.createCplex();
And this is the full backtrace :
java.lang.IncompatibleClassChangeError: Implementing class
at java.lang.ClassLoader.defineClass1(java.base#9-internal/Native Method)
at java.lang.ClassLoader.defineClass(java.base#9-internal/ClassLoader.java:939)
at java.security.SecureClassLoader.defineClass(java.base#9-internal/SecureClassLoader.java:152)
at java.net.URLClassLoader.defineClass(java.base#9-internal/URLClassLoader.java:463)
at java.net.URLClassLoader.access$100(java.base#9-internal/URLClassLoader.java:76)
at java.net.URLClassLoader$1.run(java.base#9-internal/URLClassLoader.java:371)
at java.net.URLClassLoader$1.run(java.base#9-internal/URLClassLoader.java:365)
at java.security.AccessController.doPrivileged(java.base#9-internal/Native Method)
at java.net.URLClassLoader.findClass(java.base#9-internal/URLClassLoader.java:364)
at java.lang.ClassLoader.loadClass(java.base#9-internal/ClassLoader.java:486)
at java.lang.ClassLoader.loadClass(java.base#9-internal/ClassLoader.java:419)
at java.lang.ClassLoader.defineClass1(java.base#9-internal/Native Method)
at java.lang.ClassLoader.defineClass(java.base#9-internal/ClassLoader.java:939)
at java.security.SecureClassLoader.defineClass(java.base#9-internal/SecureClassLoader.java:152)
at java.net.URLClassLoader.defineClass(java.base#9-internal/URLClassLoader.java:463)
at java.net.URLClassLoader.access$100(java.base#9-internal/URLClassLoader.java:76)
at java.net.URLClassLoader$1.run(java.base#9-internal/URLClassLoader.java:371)
at java.net.URLClassLoader$1.run(java.base#9-internal/URLClassLoader.java:365)
at java.security.AccessController.doPrivileged(java.base#9-internal/Native Method)
at java.net.URLClassLoader.findClass(java.base#9-internal/URLClassLoader.java:364)
at java.lang.ClassLoader.loadClass(java.base#9-internal/ClassLoader.java:486)
at java.lang.ClassLoader.loadClass(java.base#9-internal/ClassLoader.java:419)
at ilog.opl.IloOplFactory.createCplex(IloOplFactory.java:227)
at main.ModelFileEvaluator.testFile(ModelFileEvaluator.java:86)
at main.ModelFileEvaluator.main(ModelFileEvaluator.java:53)
at sun.reflect.NativeMethodAccessorImpl.invoke0(java.base#9-internal/Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(java.base#9-internal/NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(java.base#9-internal/DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(java.base#9-internal/Method.java:531)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
at java.lang.Thread.run(java.base#9-internal/Thread.java:804)
Using OPL requires using oplall.jar. That jar is not compatible with cplex.jar. You can use only one of the two at the same time. Removing cplex.jar from the class path should fix the issue.
I am trying to use selenium with sikuli.So sikuli would not run on a 64 bit using the current java set up so in my project changed the runtime to point to a 32 bit runtime environment and added my selenium jars using the 32 bit iewebdriver now I have a problem with the above Looked every where on the net added the guava.jar file v.21 it did not solve the problem changed that to the guava 26jre.jar and still nothing is working here is my code and errors if anyone can spot where I am going wrong
error
Exception in thread "main" java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V
at org.openqa.selenium.remote.service.DriverService$Builder.usingPort(DriverService.java:285)
at org.openqa.selenium.ie.InternetExplorerDriver.setupService(InternetExplorerDriver.java:242)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:211)
at org.openqa.selenium.ie.InternetExplorerDriver.<init>(InternetExplorerDriver.java:150)
at riOSikuliAutomation.RiOSikuliAutomation.main(RiOSikuliAutomation.java:33)
and here is my code
DesiredCapabilities cap = DesiredCapabilities.internetExplorer();
cap.setCapability("nativeEvents", false);
cap.setCapability("unexpectedAlertBehaviour", "accept");
cap.setCapability("ignoreProtectedModeSettings", true);
cap.setCapability("disable-popup-blocking", true);
cap.setCapability("enablePersistentHover", true);
cap.setCapability("ignoreZoomSetting", true);
cap.setCapability(InternetExplorerDriver.INTRODUCE_FLAKINESS_BY_IGNORING_SECURITY_DOMAINS,true);
InternetExplorerOptions options = new InternetExplorerOptions();
options.merge(cap);
System.setProperty("webdriver.ie.driver", "C:\\Users\\Selenium\\IEDriverServer.exe");
WebDriver driver = new InternetExplorerDriver(options);
as soon as it reads the last line the error pops up, anything I am not doing right please advise ?
This error message...
java.lang.NoSuchMethodError: com.google.common.base.Preconditions.checkArgument(ZLjava/lang/String;I)V
...implies that the IEDriverServer was unable to initiate/spawn a new WebBrowsing Session i.e. InternetExplorer Browser session.
Your main issue is the incompatibility between the version of the binaries you are using as follows:
You have mentioned about using guava-21.0-jre.jar which is pretty ancient.
Solution
Solution to your question would be either/all of the following steps:
Upgrade Selenium to current levels Version 3.14.0 which includes guava-25.0-jre.
Upgrade Guava to current levels of 26.0-jre (as per Selenium v3.14.0 Java clients).
Maven Dependency is as follows:
<!-- https://mvnrepository.com/artifact/com.google.guava/guava -->
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
<version>26.0-jre</version>
</dependency>
Ensure you don't have several versions in your dependency tree.
To look for the existing guava versions through Maven use the command:
mvn dependency:tree | less
Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
If issue still persists delete the MAVEN_HOME directory .m2 and download the binaries afresh.
I met the same problem, however the actual reason is that I used com.google.collections#google-collections and com.google.guava#guava at the same time in my project, which both declared class com.google.common.base.Preconditions, and result into a confliction.
Class defination confliction is a really annoying problem in java project.
Here I recommend a EASY TO USE toolkit arthas, you can find wihch jar is used when loading a class, or dump the real using bytecode in JVM into a .class file with it.
I have a Java EE Web Application which connects to a SQL Server 2008 instance. I don't have any problem connecting and retrieving to all my tables, except for one of them. The error in the Tomcat log is:
WARNING: Failed to load the sqljdbc_auth.dll cause :- no sqljdbc_auth in java.library.path
1) Download the JDBC Driver here.
2) unzip the file and go to sqljdbc_version\fra\auth\x86 or \x64
3) copy the sqljdbc_auth.dll to C:\Program Files\Java\jre_Version\bin
4) Finally restart eclipse
Here are the steps if you want to do this from Eclipse :
1) Create a folder 'sqlauth' in your C: drive, and copy the dll file sqljdbc_auth.dll to the folder
1) Go to Run> Run Configurations
2) Choose the 'Arguments' tab for your class
3) Add the below code in VM arguments:
-Djava.library.path="C:\\sqlauth"
4) Hit 'Apply' and click 'Run'
Feel free to try other methods .
For easy fix follow these steps:
goto: https://learn.microsoft.com/en-us/sql/connect/jdbc/building-the-connection-url#Connectingintegrated
Download the JDBC file and extract to your preferred location
open the auth folder matching your OS x64 or x86
copy sqljdbc_auth.dll file
paste in: C:\Program Files\Java\jdk_version\bin
restart either eclipse or netbeans
The error is clear, isn't it?
You've not added the path where sqljdbc_auth.dll is present. Find out in the system where the DLL is and add that to your classpath.
And if that also doesn't work, add the folder where the DLL is present (I'm assuming \Microsoft SQL Server JDBC Driver 3.0\sqljdbc_3.0\enu\auth\x86) to your PATH variable.
Again if you're going via ant or cmd you have to explicitly mention the path using -Djava.library.path=[path to MS_SQL_AUTH_DLL]
I've just encountered the same problem but within my own application.
I didn't like the solution with copying the dll since it's not very convenient so I did some research and came up with the following programmatic solution.
Basically, before doing any connections to SQL server, you have to add the sqljdbc_auth.dll to path.. which is easy to say:
PathHelper.appendToPath("C:\\sqljdbc_6.2\\enu\\auth\\x64");
once you know how to do it:
import java.lang.reflect.Field;
public class PathHelper {
public static void appendToPath(String dir){
String path = System.getProperty("java.library.path");
path = dir + ";" + path;
System.setProperty("java.library.path", path);
try {
final Field sysPathsField = ClassLoader.class.getDeclaredField("sys_paths");
sysPathsField.setAccessible(true);
sysPathsField.set(null, null);
}
catch (Exception ex){
throw new RuntimeException(ex);
}
}
}
Now integration authentication works like a charm :).
Credits to https://stackoverflow.com/a/21730111/1734640 for letting me figure this out.
I had to use windows authentication and I tried every suggested solution out there but with no success till I changed the name of the auth file as follows:
old-name: mssql-jdbc_auth-10.2.0.x64.dll
new-name: sqljdbc_auth.dll
And then it worked!
I looked up for this case to understand it more, apparently for Windows operating systems, the driver looks for sqljdbc_auth.dll by default.
Here is a useful link I've found:
https://learn.microsoft.com/en-us/sql/connect/jdbc/feature-dependencies-of-microsoft-jdbc-driver-for-sql-server?view=sql-server-ver15
To resolve I did the following:
Copied sqljdbc_auth.dll into dir: C:\Windows\System32
Restarted my application
I resolved the issue by:
Upgrading com.microsoft.sqlserver from 6.1.0.jre8 to 10.1.0.jre8-preview:
<dependency>
<groupId>com.microsoft.sqlserver</groupId>
<artifactId>mssql-jdbc</artifactId>
<version>10.1.0.jre8-preview</version>
</dependency>
Adding missing dependency:
<dependency>
<groupId>net.sourceforge.jtds</groupId>
<artifactId>jtds</artifactId>
<version>1.3.1</version>
</dependency>
Using the following jdbc connection:
jdbc:sqlserver://;authenticationScheme=NTLM;integratedSecurity=true;domain=;databasename=;encrypt=true;trustServerCertificate=true;user=;password=
I'm creating a cli tool to manage an existing application. Both the application and the tests build fine and run fine but despite that I receive a javassist failure when running my cli tool that exists within the jar:
INFO: Bytecode provider name : javassist
...
INFO: Hibernate EntityManager 3.5.1-Final
Exception in thread "main" javax.persistence.PersistenceException: Unable to configure EntityManagerFactory
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:371)
at org.hibernate.ejb.HibernatePersistence.createEntityManagerFactory(HibernatePersistence.java:55)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:48)
at javax.persistence.Persistence.createEntityManagerFactory(Persistence.java:32)
...
at com.sophware.flexipol.admin.AdminTool.<init>(AdminTool.java:40)
at com.sophware.flexipol.admin.AdminTool.main(AdminTool.java:69)
Caused by: java.lang.RuntimeException: Error while reading file:flexipol-jar-with-dependencies.jar
at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:131)
at org.hibernate.ejb.Ejb3Configuration.addScannedEntries(Ejb3Configuration.java:467)
at org.hibernate.ejb.Ejb3Configuration.addMetadataFromScan(Ejb3Configuration.java:457)
at org.hibernate.ejb.Ejb3Configuration.configure(Ejb3Configuration.java:347)
... 11 more
Caused by: java.io.IOException: invalid constant type: 60
at javassist.bytecode.ConstPool.readOne(ConstPool.java:1027)
at javassist.bytecode.ConstPool.read(ConstPool.java:970)
at javassist.bytecode.ConstPool.<init>(ConstPool.java:127)
at javassist.bytecode.ClassFile.read(ClassFile.java:693)
at javassist.bytecode.ClassFile.<init>(ClassFile.java:85)
at org.hibernate.ejb.packaging.AbstractJarVisitor.checkAnnotationMatching(AbstractJarVisitor.java:243)
at org.hibernate.ejb.packaging.AbstractJarVisitor.executeJavaElementFilter(AbstractJarVisitor.java:209)
at org.hibernate.ejb.packaging.AbstractJarVisitor.addElement(AbstractJarVisitor.java:170)
at org.hibernate.ejb.packaging.FileZippedJarVisitor.doProcessElements(FileZippedJarVisitor.java:119)
at org.hibernate.ejb.packaging.AbstractJarVisitor.getMatchingEntries(AbstractJarVisitor.java:146)
at org.hibernate.ejb.packaging.NativeScanner.getClassesInJar(NativeScanner.java:128)
... 14 more
Since I know the jar is fine as the unit and integration tests run against it, I thought it might be a problem with javassist, so I tried cglib. The bytecode provider then shows as cglib but I still get the exact same stack trace with javassist present in it.
cglib is definitely in the classpath:
$ unzip -l flexipol-jar-with-dependencies.jar | grep cglib | wc -l
383
I've tried with both hibernate 3.4 and 3.5 and get the exact same error. Is this a problem with javassist?
UPDATE: I can run the application successfully within Eclipse (Right click->Run As->Java Application), but using the maven-generated jar-with-dependencies fails. I presume the difference is that with Eclipse javassist isn't inspecting the containing jar, rather, it's inspecting all of the class files (and perhaps a few dependent 3rd-party jars).
The problem is ultimately caused by an invalid class in icu4j-2.6.1 as can be seen in this post. Specifically, this file is invalid:
com/ibm/icu/impl/data/LocaleElements_zh__PINYIN.class
Here's a simple way to identify a corrupt file:
for x in PATH_TO_EXTRACTED_JAR/**/*.class; do
java -cp PATH_TO/javassist.jar javassist.tools.Dump $x >/dev/null 2>&1 || echo "$x is invalid"
done
This file is being included by indirectly by maven through its transitive dependencies which is why I didn't recognize that page as referencing the error and a file contained within the jar as being the culprit and cause of the problem. Here's how it ended up included in my jar-with-dependencies bundle:
jaxen-1.1.1 -> xom-1.0 -> icu4j-2.6.1
After adding the following exclusion to the jaxen dependency, everything worked correctly for me (but be careful if you need its localization pieces):
<exclusions>
<exclusion>
<groupId>com.ibm.icu</groupId>
<artifactId>icu4j</artifactId>
</exclusion>
</exclusions>
Another option would be to remove the offending file(s) from the jar file:
#!/bin/sh
shopt -s extglob
shopt -s globstar
for x in **/*.jar ; do
zip -d $x 'com/ibm/icu/impl/data/*_zh*' >/dev/null 2>&1 && echo "Removed corrupted files from $x"
done