Applet Trouble : java.lang.NoClassDefFound - java

I'm having a bit of trouble with an applet using the SDK for the u.are.u 4500 biometric fingerprint reader.
When I test the applet locally using NetBeans, the applet works fine.
The problem is when I try to publish the applet.
I always get the "java.lang.NoClassDefFound".
I modified the java configuration so that the server config and my workstation config matches.
The SDK is installed in c:\java\jdk1.7.0_07
The JRE is installed in c:\java\jre7
The jar files for the biometric fingerprint reader are:
dpfpenrollment.jar
dpfpverification.jar
dpotapi.jar
dpotjni.jar
The CLASSPATH is:
C:\Java\jdk1.7.0_07\jre\lib\ext;
C:\Java\jdk1.7.0_07\jre\lib\ext\mysql-connector-java-5.1.22-bin.jar;
C:\Java\jdk1.7.0_07\jre\lib\ext\dpfpenrollment.jar;
C:\Java\jdk1.7.0_07\jre\lib\ext\dpfpverification.jar;
C:\Java\jdk1.7.0_07\jre\lib\ext\dpotapi.jar;
C:\Java\jdk1.7.0_07\jre\lib\ext\dpotjni.jar;
JAVA_HOME is:
c:\java\jre7
I have tried putting the jar files in the lib folder, put the result is the same.
I googled for this error, but nothing I find helps me solve this.
Any help is appreciated...
Thanks

The CLASSPATH is:
C:\Java\jdk1.7.0_07\jre\lib\ext;
C:\Java\jdk1.7.0_07\jre\lib\ext\mysql-connector-java-5.1.22-bin.jar;
C:\Java\jdk1.7.0_07\jre\lib\ext\dpfpenrollment.jar;
C:\Java\jdk1.7.0_07\jre\lib\ext\dpfpverification.jar;
C:\Java\jdk1.7.0_07\jre\lib\ext\dpotapi.jar;
C:\Java\jdk1.7.0_07\jre\lib\ext\dpotjni.jar;
No, no, no. As mentioned by EJP, that is not what the ext directory is for. Furthermore, the end users will not have those Jars in the ext directory, and even if they are, they will not be added to the run-time class-path of the applet.
If the applet requires those Jars, they need to be put in an accessible path on the server, while the codebase should point to that place and the archive attribute might be something like:
archive='mysql-connector-java-5.1.22-bin.jar,dpfpenrollment.jar,dpfpverification.jar,dpotapi.jar,dpotjni.jar'
The MySQL jar is a bit worrying as well. An applet should not have direct access to the DB, but that access should instead be mediated by server side functionality. If your applet can access the DB, a malevolent user can reverse engineer it and access the DB directly.

Related

user.dir is incorrect while using tomcat web app in eclipse

I have a configuration project that few projects are using it.
All of my project under the same workingspace.
workingspace/configuration
workingspace/webapp1
workingspace/mongoDB
workingspace/model
mongoDB and the model project are using the configuration jar project and able to read the xml files using relative path ../configuration/conf/....xml
when using the
System.out.println("Working Directory = " +
System.getProperty("user.dir"));
inside both of them, I'm getting the correct path (workspace)
while trying to do it from the web app servlet i'm getting the folder of eclipse.exe that causing some problems.
How can i fix the user.dir defalte path for the web app?
At runtime, e.g. when you're not running from inside eclipse, you probably want to work in a defined directory as well - I'd suggest to explicitly configure a specific directory. When you're running within an appserver, you might run as an unpriviledged user that doesn't have a home directory writeable at all (when the account is properly administered with minimal permissions). This differs from applications that are launched ad hoc. In fact, you probably can't assume that your application server runs as the same user as your standalone apps do.
Another alternative is to utilize the system's temp directory - if these are truly temporary files. This could be assumed writeable, or complaints if it isn't do make sense.

Access AWS credentials file in WAR

I am making a Java application that uses, Spring, Maven and the AWS-SDK-Java. In order to the AWS SDK to work I have to place the AWSCredentials.properties file inside the "MyProject/src/main/resources" folder.
So far so so good. Then I have to create a .war file. To do that I use mvn install command and voilá.
Now inside the .war created, the file I want to access is in the "/WEB-INF/classes/" folder and I need to read it.
How can I access this file inside the war so I can read its content? I have experimented with ServeltContext but so far nothing I try works!
It is generally not a good practice to keep credential in code package (war). Instead I would suggest you use IAM Roles.
This will make it easy for you to move your code from one AWS account to another (say dev environment to production). Since the code will be submitted to a version control system which will be accessed by many, it is also good from a security point of view to use IAM roles.
I found a way to do it. I can access the file by using:
InputStream inputStream =
getClass().getClassLoader().getResourceAsStream("/resources/email/file.txt");
As explained in this discusison:
Reading a text file in war archive

Storing configuration file of an application in OS independent path

I am writing an application (basically eclipse plugin), so there are few combo-box, drop-downs etc, which I am getting values for them dynamically via XML file. My doubt is which is the best way to store these files in a particular directory so that it can be read in both Windows as well as Linux.
Initially I tried to create a config path under {eclipse.home.location} like:
String finalPath = System.getProperty("eclipse.home.location") +"/myAppConfig";
and store all of my plugin's configuration there (not only configuration but few helper jars which I programatically read in my plugin). But there is a probabilty that Eclipse installation maybe in shared location and user may not have write access to it.
I also tried to store it in a program files directory using:
System.getenv("ProgramFiles");
But this fails under non-windows environments. So my question is can anyone shed a light on this so that I can store in some common directory where it is valid for both windows and linux?
Kindly let me know if my wordings are confusing. Or is it possible to store my config files under plugins directory and get the path like this /plugins/myConfigDir ?
Try using the getStateLocation() method in Plugin.
That will give you an IPath that points to a user specific workspace location.

Java: Where to write config without requiring administrative rights

I actually can't believe I'm saying this but since porting my programs to OSX and getting used to permissions, I've realized that what I planned to do on Windows will not work how I want it to. Currently, on windows, my program stores it's setting's in the registry (HKLM) and some user editable resources in a folder next to the program file. For various reasons, I have now decided that the configuration/settings will be stored in a file and the user will be able to in which folder the other resources are kept.
So the question I have now is where to store the configuration file. Obviously it will be updated, but I don't want to program to have to require administrator permissions to run. I would like to offer an option so that all users can use the program (like most programs do), which will of course require Admin, so this leads be onto the second query: where should I store the configuration file (and the folder in which other resources are kept) and how can I detect whether the program has been installed for all users or just one!
Thanks in advance
PS If you didn't guess, the program is written in Java so I would like to know how to programatically get the location you suggest as well please.
Its normal practice in *nix compatible programs to store information in folders starting with name . in the home directory of the users like,
.bash_history
.bashrc
You could use the same on OSX in my opinion and create a directory say,
.myapp
You can store any number of files with any format under that directory.
To get the location of the folder, you can do
String homeDir = System.getProperty("user.home");
File myAppDir = new File(homeDir, ".myapp");
That is roughly the code that can get you your custom config directory for your app.
Please not that dot files / folders are somewhat similar to hidden folders in windows. Your File Manager will not generally show these files / folders by default.
To identify if the program is installed for all the users or not, you could create the configuration at some administrator (root) controlled location like /etc (not sure about Mac) The user configuration can always override the default config. There could be a better way to handle this though.
On both windows and unix, User(usually) has a (home)folder to which it has full permissions. You may create a directory in the home folder and have your user configuration files reside there.

Where will WebLogic look for files by default?

I have a web application deployed in WebLogic. In one of my java file, I tried to read PleaseNote.txt as following:
File file = new File("PleaseNote.txt");
Now WebLogic is taking PleaseNote.txt from its domain directory.My question is:
Why it is domain directory? Why not the directory where my java file which has the above line of code is in?
Is there any configuration which I am not aware of , but did unknowingly, for WebLogic to look in its domain directory?
What are the implications / side effects of using above line of code in production?
Any WeLogic experts, please respond.
Thank you
Regards
Chaitanya
Reading a file using that way makes your application less portable and not very robust: if you deploy your application on another application server, you'll have to find out where to put that PleaseNote.txt file again or the code will break.
This breaks the WORA (Write Once, Run Anywhere) principle and I'd consider this as a bad
practice.
So, I'd rather put this file in the classpath and use ClassLoader#getResourceAsStream(String name) to read it.
It is domain directory because it's corresponds to value of user.dir system variable, the place where java reads/writes files if path not explicitly set.
Why domain directory corresponds to user.dir ? Because you start Weblogic server here.
Regards
Alexander Rozhkov
when using new File(..) java looks for the file in the directory from where java.exe is started. In case of an weblogic domain, this is ofcourse the domain directory. This is default java behaviour.
When you want to load a file that is in de same directory as the class-file you are loading from, use ClassLoad.getResourcesAsStream(). If you want to load a resource from the classpath use the same method, but prefix your file with "/".

Categories