I've imported all the necessary library files, and it works fine when I do a unit test using JUnit. But, when I run this code in the webapp, I get a ClassNotFoundException. I've commented out all the code that did not cause
the exception to occur. It seems the line "connection = new RConnection()"
is causing the problem.
I've also tried importing a different version of the Rserve library files, Rserve-0.6.5, with no success.
[update]
I've already added the Rserve and Rengine jars to the Build path for my project using Eclipses options.
Code:
import org.rosuda.REngine.REXP;
import org.rosuda.REngine.REXPMismatchException;
import org.rosuda.REngine.Rserve.RConnection;
import org.rosuda.REngine.Rserve.RserveException;
public class RServerAccessor implements ProductInfoDAO {
private RConnection connection;
public List<Product> getProducts(String path) {
List<Product> list = new ArrayList<Product>();
try {
connection = new RConnection();
//connection.eval("source('~/Desktop/Food/workspace/mcApp2/rScripts/ReceiptReader.R')");
//REXP raw = connection.eval("getProducts(\"" + path + "\")");
//String text = raw.asString();
//System.out.println(text);
// String[] items = text.split("\n");
// for(String item: items){
// list.add(new GroceryProduct(item));
// }
} catch (RserveException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
finally{
connection.close();
}
return list;
}
}
Exception:
Jan 02, 2017 9:27:09 PM org.apache.catalina.core.StandardWrapperValve invoke
SEVERE: Allocate exception for servlet Service
java.lang.ClassNotFoundException: org.rosuda.REngine.Rserve.RserveException
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1285)
at org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1119)
at ctrl.Service.init(Service.java:41)
Any help appreciated.
Okay I tried these things and got it working.
Tested in Junit -> Works
In the full webapp -> Doesn't work (ClassNotFound)
Seperated the RConnection into it's own pure Java program -> works but gives this warning:
"will not be exported or published, Runtime ClassNotfoundExceptions may result" Someone on StackOverflow solved a similar problem here Eclipse warning: XXXXXXXXXXX.jar will not be exported or published. Runtime ClassNotFoundExceptions may result by adding the lib files to the WEB-INF/lib of their project, however, this is not a web app so there is no such folder here. I tried this method in the actual web app with No success
I tried copying the RServe and REngine library jars files into the tomcat libs folder. e.g: /tomcat/lib/ and THIS WORKED.
Related
I downloaded and installed the free Spire.Doc.jar file to work with .docx files. When I run it within Netbeans the functionality works fine however when I attempt to build the program I am getting the following error:
warning: Supported source version 'RELEASE_6' from annotation processor 'org.eclipse.persistence.internal.jpa.modelgen.CanonicalModelProcessor' less than -source '1.8'
Note: Creating static metadata factory ...
error: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.spire.doc.packages.spryOb$1
not found
An annotation processor threw an uncaught exception.
Consult the following stack trace for details.
java.lang.RuntimeException: com.sun.tools.javac.code.Symbol$CompletionFailure: class file for com.spire.doc.packages.spryOb$1 not found
I have added the .jar file to my class path however there appears to be a class file missing from the com.spire.packages location.
Does anyone know if this is a Netbeans issue or does it look like there is an issue with the .jar file? I find it strange that it works when I run it within Netbeans but the above error occurs when I attempt to build the project.
I managed to get my application to build. What I had to do was remove the following code from my class and then it worked:
document.getMailMerge().MergeImageField = new MergeImageFieldEventHandler()
{
#Override
public void invoke(Object sender, MergeImageFieldEventArgs args)
{
mailMerge_MergeImageField(sender, args);
}
};
private static void mailMerge_MergeImageField(Object sender, MergeImageFieldEventArgs field)
{
String filePath = field.getImageFileName();
if (filePath != null && !"".equals(filePath))
{
try
{
field.setImage(filePath);
}
catch (Exception e)
{
e.printStackTrace();
}
}
}
I'm not sure why it didn't work with this included however I got this code from the following website:
https://www.c-sharpcorner.com/article/how-to-perform-mail-merge-in-word-document-in-java/
therefore I will inform them in case this happens to someone else in the future.
I'm maintaining a Java Swing application that requires a connection to an instance of Microsoft SQL Server. For various reasons, I opted to replace the native SQL Server driver being used with jTDS (the aforementioned Microsoft drivers were not working at the time and have apparently failed in the field as well). When I try to run the executable .jar outside of the IDE, I run into issues because I'm missing the appropriate ntlmauth.dll dependency.
Before proceeding, it's important to note that this application is being developed and used in an extremely restrictive (Windows-only) environment:
I cannot install any software that requires Windows UAC authentication
My users cannot install or run any software that requires UAC authentication
This currently means I cannot write files to System32 or JAVA_HOME, and cannot use any sort of ProcessBuilder tomfoolery to start another JVM with whatever command line arguments I need
I cannot use executable wrappers/installers that would only require the UAC permission for the first time installation/setup
The solution I'm trying is a combination of this one and this one to check it--essentially packaging the .dll inside of the .jar, then extracting it and loading it if necessary--as most of the other solutions I've found have been incompatible with the above restrictions; however, I'm running into an issue where even after the native library is ostensibly "loaded," I get an exception saying it isn't.
My pre-startup code:
private static final String LIB_BIN = "/lib-bin/";
private static final String JTDS_AUTH = "ntlmauth";
// load required JTDS binaries
static {
logger.info("Attempting to load library {}.dll", JTDS_AUTH);
try {
System.loadLibrary(JTDS_AUTH);
} catch (UnsatisfiedLinkError e) {
loadFromJar();
}
try {
// do some quick checks to make sure that went ok
NativeLibraries nl = new NativeLibraries();
logger.debug("Loaded libraries: {}", nl.getLoadedLibraries().toString());
} catch (NoSuchFieldException ex) {
logger.info("Native library checker load failed", ex);
}
}
/**
* When packaged into JAR extracts DLLs, places these into
*/
private static void loadFromJar() {
// we need to put DLL in temp dir
String path = ***;
loadLib(path, JTDS_AUTH);
}
/**
* Puts library to temp dir and loads to memory
*/
private static void loadLib(String path, String name) {
name = name + ".dll";
try {
// have to use a stream
InputStream in = net.sourceforge.jtds.jdbc.JtdsConnection.class.getResourceAsStream(LIB_BIN + name);
// always write to different location
File fileOut = new File(System.getProperty("java.io.tmpdir") + "/" + path + LIB_BIN + name);
logger.info("Writing dll to: " + fileOut.getAbsolutePath());
OutputStream out = FileUtils.openOutputStream(fileOut);
IOUtils.copy(in, out);
in.close();
out.close();
System.load(fileOut.toString());
} catch (Exception e) {
logger.error("Exception with native library loader", e);
JOptionPane.showMessageDialog(null, "Exception loading native libraries: " + e.getLocalizedMessage(), "Exception", JOptionPane.ERROR_MESSAGE);
}
}
As you can see, I basically copied the solution from the first link verbatim, with a few minor modifications just to try and get the application running. I also copied the class from the second link and named it NativeLibraries, the invocation of that method is fairly irrelevant but it shows up in the logs.
Anyway here are the relevant bits of the log output on starting up the application:
2015-07-20 12:32:33 INFO - Attempting to load library ntlmauth.dll
2015-07-20 12:32:33 INFO - Writing dll to: C:\Users\***\lib-bin\ntlmauth.dll
2015-07-20 12:32:33 DEBUG - Loaded libraries: [C:\Program Files\Java\jre1.8.0_45\bin\zip.dll, C:\Program Files\Java\jre1.8.0_45\bin\prism_d3d.dll, C:\Program Files\Java\jre1.8.0_45\bin\prism_sw.dll, C:\Program Files\Java\jre1.8.0_45\bin\msvcr100.dll, C:\Program Files\Java\jre1.8.0_45\bin\glass.dll, C:\Program Files\Java\jre1.8.0_45\bin\net.dll, C:\Users\***\lib-bin\ntlmauth.dll]
2015-07-20 12:32:33 INFO - Application startup
***
2015-07-20 12:32:36 ERROR - Database exception
java.sql.SQLException: I/O Error: SSO Failed: Native SSPI library not loaded. Check the java.library.path system property.
at net.sourceforge.jtds.jdbc.TdsCore.login(TdsCore.java:654) ~[jtds-1.3.1.jar:1.3.1]
at net.sourceforge.jtds.jdbc.JtdsConnection.<init>(JtdsConnection.java:371) ~[jtds-1.3.1.jar:1.3.1]
at net.sourceforge.jtds.jdbc.Driver.connect(Driver.java:184) ~[jtds-1.3.1.jar:1.3.1]
at java.sql.DriverManager.getConnection(Unknown Source) ~[na:1.8.0_45]
at java.sql.DriverManager.getConnection(Unknown Source) ~[na:1.8.0_45]
One can see that the library was, indeed, "loaded," from the third line in the log (it's the last entry, if you don't feel like scrolling). However, I simply used the class that I felt like was probably using the native libraries (I also tried the TdsCore class to no avail), as the example that showed how to do this was just using a random class from the package the library was needed in.
Is there something I'm missing here? I'm not very experienced with the JNI or the inner workings of ClassLoaders, so I might just be loading it wrong. Any advice or suggestions would be greatly appreciated!
Welp I figured out a workaround: I ended up using JarClassLoader. This basically entailed copying all my dependencies, both Java and native, into a "libraries" folder within my main .jar, and disabling .jar signing in the IDE. The application is then run by a new class that simply creates a new JarClassLoader object and running the "invokeMain" method--an example is on the website. The whole thing took about three minutes, after several days of banging my head against a wall.
Hope this helps someone someday!
I'm creating a small app to send messages to phone numbers using google voice. I made a simple test case that works in Eclipse and can send out messages as expected. However, when I try to run it on a terminal, I keep running into issues. Here is the main class I've written:
import java.io.IOException;
import com.techventus.server.voice.Voice;
public class main_WUB {
public static void main(String[] args) {
// TODO Auto-generated method stub
String username = "wake.up.bot.acc";
String password = "wakeupbotacc";
String originNumber = #;
String pavlePhone = #;
String wakeupMessage = "txt from main_WUB";
try {
Voice voice = new Voice(username, password);
voice.sendSMS(pavlePhone, wakeupMessage);
System.out.println("IT WORKED?");
//voice.call(originNumber, pavlePhone, "1");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
I've transferred the class into a remote server to test on a linux machine, however, these are the issues I've come up against. When I try to run the main class using
java main_WUB
it returns an exception, stating
Exception in thread "main" java.lang.NoClassDefFoundError: com/techventus/server/voice/Voice at main_WUB.main<main_WUB.java:18> ...
What confuses me is that I ran into this error beforehand in eclipse, and fixed it by importing the reference library in which com.techventus.server.voice.Voice is contained. Now I'm running into the same issue when trying to compile directly. Is there a way to fix this? What am I missing in my command? Any help would be appreciated.
create a jar file for your entire project in eclipse. Procedure for making jar file in eclipse -> right click on your project -> export -> java -> runnable jar file -> select main_WUB in launch configuration drop down list box -> select radio button "extract required libraries into generated jar" -> finish.
now open cmd promt -> goto the path where jar is there -> then give the command "java -jar main_WUB"
It should work.
You need build the JAR with all Libs (dependences) includes.
When you build your project in Eclipse, use the option 'Build with dependences'
I am trying to consume a web service from a Java client.
I generated the classes using wsimport:
wsimport -keep -verbose http://localhost:5382/Service1.svc?wsdl
Code looks something like:
private String CreateSalesforceIssue() {
IssueService service = new IssueService();
IIssueService binding = service.getBasicHttpBindingIIssueService();
String issueID = binding.createIssue(type, description, steps,
expected, workaround, storage,
docType, actions, tools, external,
repeatability, workaroundType, severity,
pmSeverity, products, extensions, versions,
os, status, project, resolution, fixversions);
return issueID;
}
When it hits this line:
IssueService service = new IssueService();
Stepping into the code far enough and it gets to javax.xml.ws.spi.Provider and fails there.
On
public static Provider provider() {
try {
Object provider =
FactoryFinder.find(JAXWSPROVIDER_PROPERTY,
DEFAULT_JAXWSPROVIDER);
if (!(provider instanceof Provider)) {
Class pClass = Provider.class;
String classnameAsResource = pClass.getName().replace('.', '/') + ".class";
ClassLoader loader = pClass.getClassLoader();
if(loader == null) {
loader = ClassLoader.getSystemClassLoader();
}
URL targetTypeURL = loader.getResource(classnameAsResource);
throw new LinkageError("ClassCastException: attempting to cast" +
provider.getClass().getClassLoader().getResource(classnameAsResource) +
"to" + targetTypeURL.toString() );
}
return (Provider) provider;
} catch (WebServiceException ex) {
throw ex;
} catch (Exception ex) {
throw new WebServiceException("Unable to createEndpointReference Provider", ex);
}
}
on this line:
if (!(provider instanceof Provider)) {
with a ClassNotFoundException: Provider com.sun.xml.ws.spi.ProviderImpl
I feel like I am missing something, unfortunately I am not sure what... Do I need to initialize the provider anywhere?
You should add Provider class into your classpath.
If you use IDE you can add the library easily by right click on library and choose "add Jar file" (or something like that!). But if you try to compile and run your application via terminal use the following commands:
javac -d [bin folder] -cp [jar files] [java source files]
java -classpath [jar files] [Main class]
you should split the jar files using : in Linux and MAC OS and ; in MS Windows. As you said this is a web service, I think you are using IDE and first solution may help you.
P.S. If you also added this jar file into class path and this exception occurs again, please add this jar file into your web server/container library directory. (for example lib folder in tomcat.
I am just trying to get some things to work so I can try some of google app engines java. However I seem to have a problem with something that I can't get a hold of.
The java code looks like this:
import java.net.URL;
import com.google.gdata.client.photos.*;
import com.google.gdata.data.photos.*;
public class TestPicasa {
public static void main(String[] args) {
try {
PicasawebService service = new PicasawebService("Picasa test");
service.setUserCredentials("username#gmail.com", "password");
URL feedURL = new URL("http://picasaweb.google.com/data/feed/api/user/username?kind=album");
UserFeed feed = service.getFeed(feedURL, UserFeed.class);
for (AlbumEntry entry : feed.getAlbumEntries()) {
System.out.println(entry.getTitle().getPlainText());
}
} catch (Exception e) {
e.printStackTrace();
}
}
}
I have referenced to mail.jar, activation.jar, servlet-api.jar, gdata-client, gdata-client-meta, gdata-core, gdata-media, gdata-photos-2.0.jar and gdata-photos-meta-2.0.jar according to instruction from google.
And I get this error to the console:
Exception in thread "main" java.lang.NoClassDefFoundError: com/google/common/collect/Maps
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:118)
at com.google.gdata.wireformats.AltRegistry.<init>(AltRegistry.java:100)
at com.google.gdata.client.Service.<clinit>(Service.java:532)
at TestPicasa.main(TestPicasa.java:10)
Any idea on what I have missed?
You also need Google Collections
Verify that you are not loading your google jars twice. Sometimes you would have 2 locations and the one that you are not thinking about would have a missing jar. Then your class file gets missing since the jar it's on is not under 1st classloader. This happens often on Tomcat when you have all your jars in the webapp's WEB-INF/lib but some of the jars in the Tomcat/lib. Alternatively, I only found missing class in google-collect.jar and I don''t think you are listing it