I have developed an Matlab code for stegnography which requires some preprocessing to be done by a Java file.
The java file aes1.java contains the function encrypt(String s) which needs to be called by matlab code:
javaaddpath('C:\Users\Aneesh\Desktop\BE_Project');
disp(char(javaMethod('hash', 'aes1', userText)));
I am getting the following error:
Error using javaMethod
No class aes1 can be located on the Java class path
Error in project_mod (line 11)
disp(char(javaMethod('hash','aes1',userText)));"
Versions I'm using:
Matlab 2013a
Java 1.6
Any help would be greatly appreciated!
Update:
I have a .jar file which contains all the classes i need. I've imported it and tried using it but I'm still getting the same error!
Please take a look at the documentation. javaaddpath adds one or more folders of java Archive (jar) files.
You need to compile your java file to a class-file and add it using javaclasspath
Related
I have developed a linux shared library to communicate with pos terminals. The library has been developed using C language, and the routines are imported in to a java program using JNI interface. I have tested the library with the simple Java class it works perfectly.how ever when I try to develop a front end java application using netbeans it pops up Unsatisfied link error . so i recompiled the library with the package name embedded in ever function call with in the shared library and the issue was resolved. I found the package name causes the specific error. Is there a way to come out from this problem. because I cant ask the client to keep the package name static. it should be able to change as they need. I tried several compiler and linker directive but failed ..The current working library has been compiled using the following command
gcc -shared -o libecr.so -fpic ecr.c -lusb-1.0
This compiles with no errors in Fedora 14.
libecr.so is my shared library
ecr.c is the source code file
lusb is the libusb which is referenced by ecr code
I'm having trouble compiling my Matlab code in java (with the matlab compiler tool) because I use VLfeat inside my code. This is the error it generates:
Error using loadlibrary (line 447)
There was an error loading the library "vlfeat\toolbox\vl_setup"
Undefined function or variable 'vl_setup_proto'.
Error in sift_uniform_grid (line 7)
Error in sift_bag_of_words (line 25)
Do you have any ideas of how to fix this?
It might not be properly set up and Matlab does not include vlfeat in the created jar, or cant see it. Try to add vlfeat directory to shared resources and helper files or check vlfeat path.
I have a Java class that i would like to import into my Jython script. Unfortunately, eclipse won't let me create a Java class inside my Jython project.In the window, where you create and name your Java class, I get a message at the top (alongside a red cross) saying, "Source folder is not a Java project" when I type the name of the would be class. How do I rectify this? I need the Java Class to call C code using the JNI (declaring the native method,loading and then calling it). Thank You !!!!!!!
What you can do is to create second module which would be java project. Anyhow, logically it should be that way. Please check out other similar question - PyDev: Jython modules & Java classes in the same project.
Other links that might help - http://pydev.org/manual_101_project_conf2.html
So what nefo_x suggested is correct. You need to create a new Java project that will contain your Java class. Then import the Java package as you would a python module. But there are a few things to watch out for in eclipse to make it work. I list the whole process below:
Your Java class (or classes) should not be in the default package. You need to create a new package and make/put your java class files there.
Export the package as a jar file to some place on your computer.
Add the jar file (located at some place on your computer) to your python path.
Import the package by writing "import PackageName".
The problem for me was that I had my java class in the default package. That does not work due to some naming issues. Anyhow, hope that this helps.
I am trying to use Java protobuf stubs inside Matlab. I generated the Java stub and corresponding jar file in Eclipse. I then take the jar file and add it to the Matlab path. In Matlab I do the following:
import raven.aos.*;
import raven.aos.Messages.*;
image = Image.newBuilder();
At this point I get an error message that says:
??? Undefined variable "Image" or class "Image.newBuilder".
Error in ==> pub>pub.pub at 16
image = Image.newBuilder();
I have successfully been able to use the Java jar in a Java project using the exact same syntax. So this validates that my stub is correct. I have also successfully imported and used a different Java library, zmq.jar, in my Matlab project, so to a certain extent this verifies that I know how to import jar files properly into Matlab.
I've refrained from attaching the generated Java stub file since it is very long. I hope that someone can point out what I'm doing wrong with just the code that I've provided. If required, I will add the stub source.
Thanks in advance!
Because generated protocol buffer message classes are inner classes, you need to use Matlab's javaMethod command to get to the static methods. Import statement will not work. Using your example:
image = javaMethod('newBuilder','raven.aos.Messages$Image');
http://www.mathworks.com/help/techdoc/ref/javamethod.html
I am using the code from Rome's tutorials page http://wiki.java.net/twiki/bin/view/Javawsxml/Rome05TutorialFeedReader . Also trying this one: http://wiki.java.net/twiki/bin/view/Javawsxml/Rome05TutorialFeedReader
Compiling works, but I'm not sure how to run these examples. Why I just type java FeedReader or java FeedAggregator into the command line, I get the error:
C:\projects\freshmeat\src>java FeedAggregator http://freecode.com/?format=atom
Exception in thread "main" java.lang.NoClassDefFoundError: com/sun/syndication/f
eed/synd/SyndFeed
plus the large block that follows this error
Why is this happening, how do I fix it and try these things out? How do I get something to work with Rome!?
You need to include rome in the runtime classpath (in addition to the compile-time classpath)
java -classpath lib/rome.jar FeedAggregator ...
The samples you are trying to run are in the package com.sun.syndication.samples. You say you are a complete beginner, so, to make things simpler, I would recommend that you remove the line beginning with package in each of FeedReader.java and FeedAggregator.java. Recompile the classes after removing their package directives.
Then, to run these classes, make sure you're in the same directory as the class files FeedReader.class and FeedAggregator.class that javac created. Then, try running:
java -cp c:\projects\freshmeat\libs\rome-1.0.jar;c:\projects\freshmeat\libs\jdom-1.0.jar;. FeedReader
(and similarly for FeedAggregator.)
Note also that I've added the current directory, ., to the -cp attribute. Without this, the Java virtual machine won't know that it has to look in the current directory to find your FeedReader and FeedAggregator classes.
If you were to reinstate the package directives, you'd find the class files FeedReader.class and FeedAggregator.class would be created inside a directory com\sun\syndication\samples when you compile their sources. To run the class files from this location, you'd use a command line such as
java -cp c:\projects\freshmeat\libs\rome-1.0.jar;c:\projects\freshmeat\libs\jdom-1.0.jar;. com.sun.syndication.samples.FeedReader
and you'd run this from the directory containing the com subdirectory, not the directory that contains the class files.
More information on packages in Java can be found here.