Conditional java.lang.NoClassDefFoundError in Webstart application - java

We have a webstart swing application running on our multiple remote desktop servers for a lot of customers. Suddenly, on one of our servers the customers started getting a java.lang.NoClassDefFoundError. Not on startup, the applications starts up fine, but when doing specific tasks, eg sending a mail through our software, it popups up in the console like this:
java.lang.NoClassDefFoundError: pos/MailSenderInterface
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
......
Caused by: java.lang.ClassNotFoundException: pos.MailSenderInterface
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 56 more
The problem is, this only happens on ONE of our servers. On all the other servers the webstart application runs just fine! But on this single terminal server, I get the error, even though the java version is the same, and the link to the jnlp-file is the same.
I have of course tried deleting temporary internet files in the java control panel, to no avail.
I then started toying around a bit, and found out something very strange.
Our customers start the application from an icon pointing to a batch-file in c:\drift
This batchfile only contains the following:
#start javaws http://ourserver/ourapplication.jnlp
Typing the link outside the batch-file gives the same error. Then I typed cd .. so that my current path was c:\ instead of c:\drift and started javaws from there. And surprise, no errors! I then tried cd drift again and the error occured again. I have tried this many times now, with the same result. So somehow the path from WHERE I start javaws have something to say for if I get the NoClassDefFoundError or not. But neither c:\ or c:\drift contains any .jar-files (although subdirectories may). I am very perplexed by this. What on earth is wrong? Our java version is 1.7.0_67

Aha! The path c:\drift\ actually had a directory "pos" from a couple of years back, with an old version of MailSender.class but with no MailSenderInterface.class Deleting this directory solved the problem. :-)
(Remember that the error was about a missing pos/MailSenderInterface)
Apparently the newest javaws in java 1.7.0_67 tries to load classes from a subdirectory of the place where you started javaws if such a directory is found, instead of loading the files from the correctly downloaded jar-files.

Related

javamail class not found while trying to run on RHEL

I was asked to configure and use javamail on a RHEL 7 server.
I untar'ed a javamail directory they had here which contains the following files:
activation.jar
cacerts
config.properties
InstallCert.class
InstallCert$SavingTrustManager.class
mail.jar
SimpleSSLMail.class
Also, I have created a /etc/profile.d/java.sh where I have the following:
JAVA_HOME=/usr/java/jre1.6.0_45
export PATH=$JAVA_HOME/bin:/usr/bin:/bin:/usr/sbin:$PATH
export CLASSPATH=$CLASSPATH:/usr/share/javamail/activation.jar:/usr/share/mail.jar:.
cacerts is a keystore which holds gmail's cert to sendmail. When I try to send mail using the following:
java -Djavax.net.ssl.trustStore="cacerts" -Djavax.net.ssl.trustStorePassword="somepassword" SimpleSSLMail "SomeHeader" "Testing..." "some#mail.com"
It fails with message:
Exception in thread "main" java.lang.NoClassDefFoundError:
SimpleSSLMail Caused by: java.lang.ClassNotFoundException:
SimpleSSLMail
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source) Could not find the main class: SimpleSSLMail. Program will exit
I have reviewed many posts saying the problem is java not finding mail and activation jars, but I can't handle correctly the CLASSPATH to work with those files. I also tried using -cp flag like this: java -cp mail.jar -cp activation.jar -Djavax.net.ssl.trustStore="cacerts" .....
It was useless, I get the same error.
What am I missing or how do I get it to work?
I have java jre only; do I need to compile it using javac?
My goal is to make it work in order to create an alias where the user can type only sendmail "Message" "mail.com" or similar
UPDATE
I was having a typo in classpath where instead of using /usr/share/javamail/mail.jar I was using /usr/share/mail.jar.
Now, when creating the alias it works fine in javamail directory but if I try to run it outside the directoy, java complains that it doesn't find config.properties. I believe it is searching for it as ./config_properties.
I don't have the source code, so, is there a way to override the config.properties location with the command line?

Program compiles and runs in intellij but when i build a executable jar it wont work

So I'm making a program that connects to a server and downloads a number of images.
The program works as desired when I run it in intelli j, However when I create an executable jar file and click on the program it doesn't work, The program uses intellij's built in gui creator, Would this have anything to do with the problem?
I'm not even sure how I can find out if there are any error. I went into my java options and made the console visible but it never pops up.
Thanks in advance.
EDIT: What I mean by doesn't work is, When i run the program in intellij a gui pops up instantly. When i click on the jar nothing happens. It like is just an empty jar that does nothing.
EDIT 2: Arcy recommended running in cmd. Hadn't thought of that. This is the resulting error.
Exception in thread "main" java.lang.NoClassDefFoundError:
com/jgoodies/forms/la yout/FormLayout
at StartMenu.$$$setupUI$$$(StartMenu.java)
at StartMenu.(StartMenu.java:42)
at RetrieveImage.main(RetrieveImage.java:109) Caused by: java.lang.ClassNotFoundException: com.jgoodies.forms.layout.FormLayou
t
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
Seems like the jgoodies library isn't included in the jar.

NoClassDefFoundError executing jar using jaxrpc

I have developed a Webservice client application using jaxrpc. Within eclipse the application runs fine, however after I have exported the jar file, I get the following runtime error
D:\>java -jar Myclient2.jar
Exception in thread "main" java.lang.NoClassDefFoundError: javax/xml/rpc/Service
Exception
at Mynet.MyScheduler.<init>(MyScheduler.java:47)
at Mynet.MyScheduler.<init>(MyScheduler.java:36)
at Mynet.MyNetMain.main(MyNetMain.java:11)
Caused by: java.lang.ClassNotFoundException: javax.xml.rpc.ServiceException
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 3 more
I have tried to set the CLASSPATH variable but no changes.
set CLASSPATH=%CLASSPATH%;D:\eclipse\plugins\javax.xml.rpc_1.1.0.v201209140446\lib\jaxrpc.jar
set CLASSPATH=%CLASSPATH%;D:\eclipse\plugins\org.apache.axis_1.4.0.v201005080400\lib\axis.jar
echo %CLASSPATH%
java -jar Myclient2.jar
I am rather new to java so definitely a newbie question
KR
You should consider migrating your web service to JAX-WS. JAX-RPC is an older java web service technology that is unlikely to be maintained much moving forward.
But the single biggest benefit you will experience is that all of the JAX-WS runtime and tooling has been part of the Java JDK since Java 6. This means that you can build web services with no runtime library dependencies.
Anytime that you get "java.lang.NoClassDefFoundError"; it is very probable that you are missing a jar file.
you should search for the jar file containing "javax/xml/rpc" and then add it to your classpath or as a dependency to your maven project.
Here you should find them:
http://search.maven.org/
http://mvnrepository.com/

Having trouble running code in Eclipse using JOGL

I'm trying to run an application in eclipse which is setup as MVC app and it is the solution code posted by our professor for a homework. After I copy and pasted all of the classes and tried to run it, I got the following error:
JOGL> Hello JOAL Exception in thread "main" java.lang.NoClassDefFoundError: com/jogamp/openal/JoalVersion at jogamp.opengl.openal.av.ALDummyUsage.main(ALDummyUsage.java:14) Caused by: java.lang.ClassNotFoundException: com.jogamp.openal.JoalVersion at java.net.URLClassLoader$1.run(Unknown Source) at java.net.URLClassLoader$1.run(Unknown Source) at java.security.AccessController.doPrivileged(Native Method) at java.net.URLClassLoader.findClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source) at java.lang.ClassLoader.loadClass(Unknown Source) ... 1 more
I'm not entirely sure what the issue is and apparently no one else has been having the same issue.
My buildpath has a library I titled "JOGL" and I added the external jars gluegen-rt.jar and jogl-all.jar as was instructed by the professor.
Thanks for the help!
Actually, your code uses JOAL too, you need to put joal.jar into your classpath (Build path in Eclipse) and you need to put the JAR(s) containing its native libraries into the same directory as you did for JOGL and GlueGen. I assume you followed these instructions:
http://jogamp.org/wiki/index.php/Setting_up_a_JogAmp_project_in_your_favorite_IDE#Eclipse_IDE_project
Edit.: You don't run your own program for your homework, you try to run ALDummyUsage which is in JOGL itself. If you want to run your own program with your own main class, rather right-click on it and choose "Run As" -> "Java application" in Eclipse.

Webstart and JavaCompiler API restrictions

I have an application that has only signed jars, all by the same certificate, mine. I wan't to run the application with Webstart. The application runs a compiler, and the compiled code runs LWJGL. However when I run the application, it returns errors by the compiled code that it literally cant find the LWJGL(-library) packages (the original application can see it fine). When I compile the application as a Trusted-Library, it errors out as well:
Exception in thread "CompilerThread" java.lang.NoClassDefFoundError: com/sun/tools/javac/api/JavacTool
at customcompile.CustomCompile$2.run(CustomCompile.java:82)
at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.ClassNotFoundException: com.sun.tools.javac.api.JavacTool
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at com.sun.jnlp.JNLPClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 2 more
http://download.oracle.com/javase/6/docs/technotes/guides/jweb/mixed_code.html
I found this site, but it doesn't get me much wiser on the particular subject, since it is clearly related to the compiled code being handled differently than the other code.
Can anyone help me out with this? Or clear it up?
Edit: I have concluded the compiled code is treated as unsigned.
Getting the libraries to be recognized, requires them being added in the classpath.
I think redirecting System.getProperty calls and the like, to the signed classes, will solve any problems in the unsigned code, giving it indirectly more rights.

Categories