I want to encrypt a string, but the standard Java libraries are too complicated for me.
So I turned to Jasypt labriry. It's pretty simple to use and understan. However when I import the library to Eclipse 3.6 and when I try encrypt a string like "Hello" with the password "123", it always comes up with an error. I'm not sure what I'mm doing wrong but I think it also happens when I use other libraries in Eclipse.
Source:
import org.jasypt.util.text.BasicTextEncryptor;
public class Main {
static BasicTextEncryptor textEncryptor = new BasicTextEncryptor();
public static void main(String[] args) {
System.out.println("Hello World");
textEncryptor.setPassword("123");
System.out.println(textEncryptor.encrypt("Hello World"));
}
}
The error message:
java.lang.NoClassDefFoundError: org/apache/commons/lang/exception/NestableRuntimeException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(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)
at org.jasypt.util.text.BasicTextEncryptor.<init>(BasicTextEncryptor.java:67)
at eMain.<clinit>(eMain.java:4)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.lang.exception.NestableRuntimeException
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)
... 14 more
The library you imported depends on another library containing org/apache/commons/lang/exception/NestableRuntimeException. This is located in the Apache Commons Lang library.
In fact, if you downloaded JASYPT from http://sourceforge.net/projects/jasypt/files/ you'll get a zip file containing a lib-folder with these files:
commons-codec-1.1.jar
commons-lang-2.1.jar
jasypt-1.6.jar
You should include all of these in your project.
I tried it and your little sample program works fine (and prints the following)
Hello World
v09l9j/BIeSoMkQXc2CY0VIJLlLAQTYq
Related
I am very new to boilerpipe and I am trying out the following basic code:
package contentExtraction;
import java.net.URL;
import de.l3s.boilerpipe.extractors.ArticleExtractor;
public class ContentExtractor {
public static void main(String[] args) throws Exception {
final URL url = new URL(
// "http://www.l3s.de/web/page11g.do?sp=page11g&link=ln104g&stu1g.LanguageISOCtxParam=en"
"http://www.dn.se/nyheter/vetenskap/annu-godare-choklad-med-hjalp-av-dna-teknik"
);
System.out.println(ArticleExtractor.INSTANCE.getText(url));
}
}
But I am getting the following error when trying to run the above piece of code:
Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/xerces/parsers/AbstractSAXParser
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at de.l3s.boilerpipe.sax.BoilerpipeSAXInput.getTextDocument(BoilerpipeSAXInput.java:51)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:69)
at de.l3s.boilerpipe.extractors.ExtractorBase.getText(ExtractorBase.java:87)
at contentExtraction.ContentExtractor.main(ContentExtractor.java:16)
Caused by: java.lang.ClassNotFoundException: org.apache.xerces.parsers.AbstractSAXParser
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)
... 16 more
I googled the error and came across this link. I thought that I was missing xercesImpl.jar in my dependencies. I included the same, still my code is giving the same error. What is the issue?
I figured the solution myself. The boilerpipe jar has further dependencies. I converted my project to maven project, included the dependency:
<dependency>
<groupId>com.syncthemall</groupId>
<artifactId>boilerpipe</artifactId>
<version>1.2.1</version>
</dependency>
When I build the above project, I can see there are actually 4 jars that are imported in Maven Dependencies folder:
boilerpipe-1.2.1.jar
nekohtml-1.9.18.jar
xercesImpl-2.11.0.jar
xml-apis-1.4.01.jar
Here's my simple code:
import static com.jayway.restassured.RestAssured.get;
public class testget {
public static void main(String[] args) {
Response countryName = get("http://maps.googleapis.com/maps/api/geocode/json?latlng=45.2542285874,30.2564857&sensor=false");
System.out.println(countryName);
System.exit(0);
}
}
When running, I get the following error:
Exception in thread "main" java.lang.NoClassDefFoundError: com/jayway/restassured/mapper/factory/ObjectMapperFactory
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at com.jayway.restassured.config.RestAssuredConfig.<init>(RestAssuredConfig.java:41)
at com.jayway.restassured.RestAssured.<clinit>(RestAssured.java:423)
at testeget.main(testeget.java:6)
Caused by: java.lang.ClassNotFoundException: com.jayway.restassured.mapper.factory.ObjectMapperFactory
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)
... 15 more
But the Rest Assured lib is loaded, otherwise the get method wouldn't even be called... What could it be?
I'm using Rest Assured 2.8.
Update:
I'm using Eclipse to run it, and the classpath has, besides the default Java/Eclipse content, the path to the .jar file of Rest Assured and it's dependencies, as listed on their website.
Dependencies list on the bottom of the page (all added to the classpath).
http://mvnrepository.com/artifact/com.jayway.restassured/rest-assured/2.8.0
I have the project based on JavFX 2, it`s done and works perfect in Eclipse. Now i am trying to deploy it on computer(self-service,terminal,..). I have created jar file, but when i am trying to "java -jar myproject.jar" i take the following
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Caused by: java.lang.ClassNotFoundException: javafx.application.Application
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)
... 13 more
UDT:
I think there is some problem with jfxrt.jar where javafx.application.Application class stored, in eclipse i added this jar in build path manually..
In Java 7, JavaFX is included with the JDK download but is not on the classpath (JavaFX is not part of the core libraries in Java 7). Have a look at the tutorial on deployment, which shows mechanisms for deploying a jar file that will work.
(In Java 8, JavaFX becomes part of the core libraries and will be included on the classpath, so your regular jar file may well work. There are still some cool things you can do with the proper deployment process, though.)
I wonder why the Game.class wont start. Here's he problem I got:
java.lang.NoClassDefFoundError: Game (wrong name: game/Game)`
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$100(Unknown Source)
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)
at sun.launcher.LauncherHelper.checkAndLoadMain(Unknown Source)
Exception in thread "main"
You will get similar error if you do mething like this:
package game;
class Game
{
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}
without putting the compiled class file in a sub-folder called game and run it like java Game. So your Game class is in a package called game.
Please Check Your packaging structure and ensure that your class file is inside the package folder . Compile and Happy Execution ....
I'm trying to use the Lizzy library (http://lizzy.sourceforge.net/) to do some playlist manipulation. As a dependency, it requires that I have the Castor library (http://www.castor.org/) in my build path. So I went to the site, and downloaded Castor 1.3.1, then put the .jar into my build path.
However, when I try to run this line of code to convert a specific playlist file to a generic playlist object:
specificPlaylist = SpecificPlaylistFactory.getInstance().readFrom(playlistFile);
I end up getting a NoClassDefFoundError:
Exception in thread "AWT-EventQueue-0" java.lang.NoClassDefFoundError: org/exolab/castor/core/exceptions/CastorException
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(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)
at java.lang.ClassLoader.defineClass1(Native Method)
at java.lang.ClassLoader.defineClassCond(Unknown Source)
at java.lang.ClassLoader.defineClass(Unknown Source)
at java.security.SecureClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.defineClass(Unknown Source)
at java.net.URLClassLoader.access$000(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)
at org.exolab.castor.mapping.Mapping.<init>(Mapping.java:81)
at christophedelory.xml.XmlSerializer.getMapping(XmlSerializer.java:100)
at christophedelory.playlist.asx.AsxProvider.readFrom(AsxProvider.java:202)
at christophedelory.playlist.SpecificPlaylistFactory.readFrom(SpecificPlaylistFactory.java:132)
at christophedelory.playlist.SpecificPlaylistFactory.readFrom(SpecificPlaylistFactory.java:168)
...
Am I missing a .jar file? I managed to create an instance of a CastorException class (but it was in a different package than the one the exception is talking about). I thought that the basic Castor-1.3.1.jar file held all of the classes it needed.
Additional information: I'm trying to decode a .wpl playlist file, which should be supported by Lizzy. And my build path looks like this:
Thanks for any help.
You can easily look in the Castor jar to see what's there using a wide variety of tools - WinZip happens to be my tool of choice. You'll find that while there's a CastorException, it's in the wrong package.
Looking at the old downloads page under 1.3.1, I see a Castor-1.3.1-core.jar. Looking in it, I see CastorException in the right package. You may need other jars too - I'd consult the documentation, or continue by trial-and-error, or try to find a POM that will tell you.