Unable to load Aspera Library in Ubuntu - ibm-cloud

I am trying to load files from on-prem to IBM Cloud Object Store using Aspera High Speed API. It works fine in Mac, but when the same code is run on Ubuntu 18.0.4 it gives following error.
Failed to load Aspera dynamic library from candidates
[libfaspmanager2.so] at location: /root/.aspera/cos-aspera/0.1.163682
With dependency:
<dependency>
<groupId>com.ibm.cos-aspera</groupId>
<artifactId>cos-aspera-linux-64</artifactId>
<version>0.1.163682</version>
</dependency>
Made sure below env variable is set:
a) export LD_LIBRARY_PATH=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/server:/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64
b) export LD_PRELOAD=/usr/lib/jvm/java-8-openjdk-amd64/jre/lib/amd64/libjsig.so
Using following java:
openjdk version "1.8.0_222" OpenJDK Runtime Environment (build
1.8.0_222-8u222-b10-1ubuntu1~18.04.1-b10) OpenJDK 64-Bit Server VM (build 25.222-b10, mixed mode)

You can try to decompile the java code that loads the native lib. (e.g using JAD).
You would find that in:
com.ibm.cloud.objectstorage.services.aspera.transfer.AsperaLibraryLoader
Here is the method:
public static void loadLibrary(File extractedPath, List<String> candidates) {
for (String lib : candidates) {
File libPath = new File(extractedPath, lib);
String absPath = libPath.getAbsolutePath();
log.debug("Attempting to load dynamic library: " + absPath);
try {
System.load(absPath);
log.info("Loaded dynamic library: " + absPath);
return;
} catch (UnsatisfiedLinkError e) {
log.debug("Unable to load dynamic library: " + absPath, e);
}
}
throw new RuntimeException("Failed to load Aspera dynamic library from candidates " + candidates + " at location: " + extractedPath);
}
You can try to reproduce the error and get the actual message by compiling:
public class TestLoad { public static void main(String[] args) {
System.load("/root/.aspera/cos-aspera/0.1.163682/libfaspmanager2.so");
}}
On windows, similar problem due to missing dependency for the libfaspmanager2.so lib. which are fixed by setting by adding to PATH the folder where missing libs are.
On Linux check dependencies with:
ldd /root/.aspera/cos-aspera/0.1.163682/libfaspmanager2.so
If there are missing deps, then add folder path to LD_LIBRARY_PATH.
Another note:
The java lib is equipped with Apache commons logging:
https://commons.apache.org/proper/commons-logging/guide.html
So, activate logs, and get better idea.

Related

Could not find main method from given launch configuration

I've a simple Java project that works when I execute it at Eclipse environment. But when I try to export it to a Runnable Jar, I get the following error:
JAR export finished with warnings. See details for additional information.
Exported with compile warnings: JavaSwing/src.main.java/com/cansoft/GUIProgram.java
Exported with compile warnings: JavaSwing/src.main.java/com/util/Util.java
Jar export finished with problems. See details for additional information.
Could not find main method from given launch configuration.
I read other posts which suggest to create a MANIFEST.MF file specifying the main-class which I did. It is placed at MyProjectFolder/META-INF/MANIFEST.MF and it contains the following information:
Manifest-Version: 1.0
Class-Path: resources
main-class: com.cansoft.GUIProgram
My main class is as follows:
public class GUIProgram {
private JFrame folderCreationSubappFrame;
private Color color;
private String home;
private final static Logger LOG_MONITOR = Logger.getLogger("com.cansoft");
public static void main(String[] args) {
try {
new GUIProgram();
} catch (Exception e) {
LOG_MONITOR.log(Level.INFO,e.getMessage());
}
}
public GUIProgram() throws InterruptedException, SecurityException, IOException {
home = System.getProperty("user.home") + File.separator + "Documents";
startLogSystem();
if(isFirstRun()) {
showWelcomeFrame();
} else {
initialize();
}
} .... More and more code
Does anybody know what am I missing? Any help much appreciated.
Thank you.
It is not enough to create the manifest file, you need to explicitly choose it in the Eclipse jar export dialog.
Answer to Comment
If you use "runnable jar", make sure that you chose the correct launch configuration and that the launch configuration successfully runs when chosing "Run As" -> "Run Configurations" -> "Java Application" -> Your Configuration -> "Run"
I finally find out where the problem was, it was quite simple btw. I had created my GUIProgram within a src.main.java package, but that package was created (my bad) as resources instead of folders, so Eclipse was smart enought to run it but when trying to generate the JAR which expected a correct java project structure, it was failing because truly there were not GUIProgram java class at src path (src was not folder type but resources).
Hope I succeed explaining.

Use webapp classpath using JavaCompiler in Tomcat within Eclipse with Maven

I have an existing "Example Webapp" that references "Example Library" using Maven. I'm running Tomcat 7 inside Eclipse 4.3RC3 with the m2e plugin. When I launch Example Webapp on Tomcat inside Eclipse, I have verified that the example-library.jar is probably getting deployed in the Tomcat instance's WEB-INF/lib folder.
The Example Webapp has code that compiles certain classes on the fly using JavaCompiler.CompilationTask. These dynamically generated classes reference classes in example-library.jar. Unfortunately the compile task is failing because the referenced classes cannot be found.
I understand that I can set the JavaCompiler classpath, but System.getProperty("java.class.path") only returns me the Tomcat classpath, not the webapp classpath:
C:\bin\tomcat\bin\bootstrap.jar;C:\bin\tomcat\bin\tomcat-juli.jar;C:\bin\jdk6\lib\tools.jar
Other have said that I need to get the real path of WEB-INF/lib from the servlet context, but the class generation code doesn't know anything about a servlet context --- it is written to be agnostic of whether it is used on the client or on the server.
In another question, one answer indicated I could enumerate the classloader URLs, and sure enough this provides me with the jars in WEB-INF/lib, but when I provide this as a -classpath option to compiler.getTask(), the task still fails because it can't find the referenced classes.
How can I simply provide the classpath of the currently executing code to the JavaCompiler instance so that it will find the classes from the libraries in WEB-INF/lib? (A similar question was raised but never answered regarding referencing jars within ear files using JavaCompiler.)
Example: In an attempt to get things working at any cost, I even tried to hard-code the classpath. For example, I have foobar.lib in my webapp lib directory, so I used the following code, modified from the answers I indicated above:
List<String> options = new ArrayList<String>();
options.add("-classpath");
options.add("C:\\work\\.metadata\\.plugins\\org.eclipse.wst.server.core\\tmp0\\wtpwebapps\\FooBar\\WEB-INF\\lib\\foobar.jar");
JavaCompiler.CompilationTask task = compiler.getTask(null, fileManager, diagnostics, options, null, compilationUnits);
boolean success = task.call();
In the end success is false, and my diaognostics indicates package com.example.foo.bar does not exist..., even though that package is in foobar.jar.
Put example-library.jar somewhere in your file system and pass that location to the code that runs JavaCompiler (the -classpath option). If you use an exploded WAR file to deploy, you can of course point it to the physical location within the WEB-INF/lib folder. The point is that you only need one configurable parameter in your webapp to do this, which can be a properties file entry, -D system property, database row or something else entirely.
Sample code (tested in Tomcat 7 and OpenJDK 1.7 on Fedora 18 x64):
private File compile(File javaFile, String classpath) throws IOException {
JavaCompiler compiler = ToolProvider.getSystemJavaCompiler();
StandardJavaFileManager fileManager = compiler.getStandardFileManager(null, null, null);
Iterable<? extends JavaFileObject> compilationUnit = fileManager.getJavaFileObjects(javaFile);
List<String> options = classpath != null ? Arrays.asList("-classpath", classpath) : null;
StringWriter output = new StringWriter();
try {
boolean successful = compiler.getTask(output, fileManager, null, options, null, compilationUnit).call();
if (!successful) {
throw new CompilationException("Failed to compile: " + javaFile, output.toString());
}
return firstClassFileFrom(javaFile.getParentFile());
} finally {
fileManager.close();
}
}
private File firstClassFileFrom(File directory) {
return directory.listFiles(new FilenameFilter() {
#Override
public boolean accept(File dir, String name) {
return name.endsWith(".class");
}
})[0];
}
See https://github.com/jpalomaki/compiler for a runnable sample webapp.
i met the same question. The reason is not "-classpath" .
my code :
String classpath ="xx/WEB-INF/clases ";
List<String> options = classpath != null ? Arrays.asList("-d", classpath,"-cp",classpath) : null;
CompilationTask task = compiler.getTask(null, javaDinamicoManager, diagnostics,
options, null, Arrays.asList(sourceObj));
boolean result = task.call();
the “result” will return true .
You could follow the answer provided for the even more specific question of how to load dependencies of compiled code from within a web app running directly from an unexpanded WAR file (there are no JAR files to reference - only the container's class loder knows how to access the classes): https://stackoverflow.com/a/45038007/2546679

Fatal error : unable to launch target VM

I am new to the java and jdb ,trying to debug an example program :
Foo.java
class Foo {
public static void main(String[] args){
System.out.println("Chexking dalvik virtual machine on system");
}
}
compiled it with -g flag . javac -g Foo.java
compiled properly .
Tried to run program using command >java Foo
Got the output .
Then tried to run : jdb Foo
C:\Users\test\workspace\sampleJava>jdb Foo
Initializing jdb ...
> stop in Foo.main
Deferring breakpoint Foo.main.
It will be set after the class is loaded.
> run main
run main
java.io.IOException: Cannot run program "C:\Program": CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessBuilder.start(ProcessBuilder.java:470)
at java.lang.Runtime.exec(Runtime.java:593)
at java.lang.Runtime.exec(Runtime.java:466)
at com.sun.tools.jdi.AbstractLauncher$Helper.launchAndAccept(AbstractLauncher.java:162)
at com.sun.tools.jdi.AbstractLauncher.launch(AbstractLauncher.java:114)
at com.sun.tools.jdi.SunCommandLineLauncher.launch(SunCommandLineLauncher.java:217)
at com.sun.tools.example.debug.tty.VMConnection.launchTarget(VMConnection.java:334)
at com.sun.tools.example.debug.tty.VMConnection.open(VMConnection.java:166)
at com.sun.tools.example.debug.tty.Commands.commandRun(Commands.java:589)
at com.sun.tools.example.debug.tty.TTY.executeCommand(TTY.java:474)
at com.sun.tools.example.debug.tty.TTY.<init>(TTY.java:707)
at com.sun.tools.example.debug.tty.TTY.main(TTY.java:1011)
Caused by: java.io.IOException: CreateProcess error=2, The system cannot find the file specified
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.<init>(ProcessImpl.java:177)
at java.lang.ProcessImpl.start(ProcessImpl.java:28)
at java.lang.ProcessBuilder.start(ProcessBuilder.java:452)
... 11 more
Fatal error:
Unable to launch target VM.
To my knowledge : jdb is unable to load the class . Is there any path setting i need to set for jdb . (I was trying to follow this tutorial)
I think i am missing a very basic thing. Tried google but the same think but i couldnt resolve the problem .
My PATH=%SystemRoot%\system32;%SystemRoot%;%SystemRoot%\System32\Wbem;%SYSTEMROOT%\System32\WindowsPowerShell\v1.0\;C:\cygwin\;C:\Users\test\Downloads\adt-bundle-windows-x86-20130219\adt-bundle-windows-x86-20130219\sdk\platform-tools\;"C:\Program Files\Java\jre1.6.0_16\bin";"C:\Program Files\Java\jre6\bin";"C:\Program Files\Java\jdk1.6.0_45\bin";C:\Users\test\Downloads\adt-bundle-windows-x86-20130219\adt-bundle-windows-x86-20130219\sdk\tools;"C:\Program Files\Graphviz2.26.3\bin";"C:\Program Files\Graphviz2.26.3\bin"
C:\Users\test\workspace\sampleJava>java -version
java version "1.6.0_45"
Java(TM) SE Runtime Environment (build 1.6.0_45-b06)
Java HotSpot(TM) Client VM (build 20.45-b01, mixed mode, sharing)
C:\Users\test\workspace\sampleJava>javac -version
javac 1.6.0_45
OS: windows 7
Had the same problem - appears to be that this is caused by jdk being installed in a folder with a space in its path, i.e., "Program Files" - moved the jdk installation to c:\jdk and the problem went away.

ClassNotFoundException with PostgreSQL and JDBC

I am having some difficulty in making connectivity with Java and PostgreSQL Database.I have download the JDBC4 Postgresql Driver, Version 9.2-1002 driver and properly set the application ClassPath. My code is as under
import java.sql.*;
public class JavaPostGreSQLConnectivity
{
public static void main(String[] args)
{
DB db = new DB();
db.dbConnect("jdbc:postgresql://127.0.0.1:5432/TestDB", "postgres","pwd");
}
}
class DB
{
public DB() {}
public void dbConnect(String db_connect_string, String db_userid, String db_password)
{
try
{
Class.forName("org.postgresql.Driver");
Connection conn = DriverManager.getConnection(db_connect_string, db_userid, db_password);
System.out.println("connected");
}
catch (Exception e)
{
e.printStackTrace();
}
}
};
Upon running I am getting the below error
Is it complaining about
Class.forName("org.postgresql.Driver");
If so then what will be the driver name? However, I followed this for my learning purpose.
However, If I do
C:\Program Files (x86)\Java\jdk1.7.0\bin>java -cp C:\Users\pos
tgresql-9.2-1002.jdbc4.jar; JavaPostGreSQLConnectivity
connected
It works.Why I need to explicitly mention the driver again when I have already placed it in the classpath properly? Is there any alternative way (I just want to put the JAR file in Classpath and the program should read from there)?
Thanks in advance
The driver name is OK. It is the same as mentioned in the official docs of the driver. Therefore the driver is just not in the classpath.
You say:
I [...] properly set the application ClassPath
On the other hand you start the program by just calling:
java JavaPostGreSQLConnectivity
In that case no PG driver is on the classpath. You have to add it by hand using someting like
java -cp postgresql-jdbc4.jar JavaPostGreSQLConnectivity
EDIT The question has been changed while typing, hence the duplication.
You added the jar only in you IDE. This helps the IDE to compile your code. If you start the program using you IDE then the IDE will also set the classpath for you. But if you don't start via the IDE then nobody knows the correct classpath and it has to be set by hand.
Your options are:
start always via IDE
make some batch script which hides the setting of the classpath (common solution)
set the CLASSPATH environment variable (does not scale with other Java applications)
make an "Executable Jar" and set the classpath there. (Search this site using that term).
put the jar into a place where the JVM picks it up automatically (e.g. in the lib/ext directory of the JRE). But polluting the JRE/JDK libs is the worst option.
Note: This is all basic Java knowledge and has nothing to do with PostgreSQL.

Configure Java CV with eclipse juno

I am having a 64-bit windows 7 laptop.
I have opencv version 2.4.2. I have extracted it in the C:
I have eclipse juno classic on my laptop.
Jdk 7 64-bit version is installed and and path variable set so i can access javac from CMD.
I have javacv-0.2 downloaded from google projects.
for opencv i have added following path to the classpath variable.
C:\opencv\build\x64\vc10\bin;C:\opencv\build\common\tbb\intel64\vc10\
I have installed Microsoft Visual C++ 2010 Redistributable Package (x64)
I have inclused javacv.jar, javacpp.jar and javacv-windows-x86_64.jar in the ProjectBuildPath of eclipse.
Yet when i try to write following program function cvLoadImage(), cvSmooth(), cvSaveImage and cvReleaseImage() they are not identified and available to me.
import static com.googlecode.javacv.cpp.opencv_core.*;
import static com.googlecode.javacv.cpp.opencv_imgproc.*;
import static com.googlecode.javacv.cpp.opencv_highgui.*;
public class ssss {
public static void main(String filename) {
IplImage image = cvLoadImage(filename);
if (image != null) {
cvSmooth(image, image, CV_GAUSSIAN, 3);
cvSaveImage(filename, image);
cvReleaseImage(image);
}
}
}
Please guide me. If you need any other information regarding it do let know.
I followed the instruction available at this link to configure java-cv: http://ganeshtiwaridotcomdotnp.blogspot.in/2011/12/opencv-javacv-eclipse-project.html
Regards,
Priyank
You have mentioned that you are using 64bit system. But you have set path for 32bit binaries. correct path for 64 bit system should be
C:\opencv\build\x64\vc10\bin;C:\opencv\build\common\tbb\intel64\vc10\