Eclipse Juno EE NoClassDefFoundError when using external Jar - apache

I added an external jar in my eclipse dynamic webproject via Folder -> properties -> build path -> Libraries -> add external jar.
The code is working fine on compile time.
package servlet;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.MultipartConfig;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tika.Tika;
#WebServlet(name="UploadServlet", urlPatterns={"/uploadFile"}) // specify urlPattern for servlet
#MultipartConfig //Specify that this servlet will receive a multipart data
public class UploadServlet extends HttpServlet {
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException{
Tika tika = new Tika();
res.setContentType("text/html");
PrintWriter writer = res.getWriter();
writer.write(mediaType);
}
}
I added Apache Tika but when I run my application. these exception occured.
root cause
java.lang.NoClassDefFoundError: org/apache/tika/Tika
servlet.UploadServlet.doPost(UploadServlet.java:19)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
root cause
java.lang.ClassNotFoundException: org.apache.tika.Tika
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1559)
servlet.UploadServlet.doPost(UploadServlet.java:19)
javax.servlet.http.HttpServlet.service(HttpServlet.java:641)
javax.servlet.http.HttpServlet.service(HttpServlet.java:722)
I am using Apache Tika to determine what file has been upload, I want to use it for validating if a file is an image, or audio file

You forgot to add that jar to the Deployment Assembly page. It's not deployed to the server when you run your application, hence the NoClassDefFoundErrors.

Related

karate.log file is not getting generated

I have placed the logback-test.xml in classpath
karate.log is not getting generated, I have seen there is a file called main.log that gets generated sometime
Here is the project structure
Here is the runner file
package com.org.KarateLearning;
import com.intuit.karate.KarateOptions;
import com.intuit.karate.Results;
import com.intuit.karate.Runner;
import com.intuit.karate.junit4.Karate;
import org.junit.Test;
import org.junit.runner.RunWith;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.Map;
import java.util.Properties;
import static org.junit.Assert.assertTrue;
public class ParallelTestRunner {
#Test
public void parallel() {
Results res = Runner.path("classpath:features").tags("~#ignore").parallel(5);
assertTrue(res.getErrorMessages(),res.getFailCount()==0);
}}
I have tried placing logback-test.xml in resources and com.org.KarateLearning but karate.log is not getting genearted
Deleted the existing file ( logback-test.xml ) and created a new one from below path under src/test/java
https://github.com/intuit/karate/blob/master/karate-demo/src/test/java/logback-test.xml
Now file is getting generated in target folder
In between it was getting generated outside of target folder. Now its getting generated at correct location inside target folder.
Also note even after deleting the logback-test.xml log was getting generated. (not sure about the reason for it)
Now all works well

lucene java11 WARNING?

I have this really simple java Lucene code that works in my friends PC but it makes a lot of errors for me ... we all use Lucene 5.3.1, I think that the problem is my jdk11
package project;
import java.io.IOException;
import java.nio.file.Path;
import java.nio.file.Paths;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.document.IntField;
import org.apache.lucene.document.TextField;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
public class Act1 {
public static void main(String[] args) throws
IOException {
Document doc = new Document();
Field titre = new TextField("Titre", "mon A staticestimation technique",Field.Store.YES);
Field ref = new IntField("Year", 2001,Field.Store.YES);
Field auteurs = new TextField("Auteurs","TaewhanKim, Ki-Seok Chung, C. L. Liu",Field.Store.YES);
doc.add(titre);
doc.add(ref);
doc.add(auteurs);
Path p = Paths.get("C:\\Users\\user\\Desktop\\abc");
Directory dir = FSDirectory.open(p);
StandardAnalyzer analyzer = new StandardAnalyzer();
IndexWriterConfig config = new IndexWriterConfig(analyzer);
IndexWriter index = new IndexWriter(dir, config);
index.addDocument(doc);
index.close();
}
}
but it make those errors
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by org.apache.lucene.store.MMapDirectory$1 (file:/C:/Users/user/Downloads/lucene-5.3.1/core/lucene-core-5.3.1.jar) to method java.nio.DirectByteBuffer.cleaner()
WARNING: Please consider reporting this to the maintainers of org.apache.lucene.store.MMapDirectory$1
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
Exception in thread "main" java.io.IOException: Unable to unmap the mapped buffer: MMapIndexInput(path="C:\Users\user\Desktop\abc\_1_Lucene50_0.doc")
at org.apache.lucene.store.MMapDirectory$2.freeBuffer(MMapDirectory.java:329)
at org.apache.lucene.store.ByteBufferIndexInput.freeBuffer(ByteBufferIndexInput.java:376)
at org.apache.lucene.store.ByteBufferIndexInput.close(ByteBufferIndexInput.java:355)
at org.apache.lucene.codecs.lucene50.Lucene50CompoundFormat.write(Lucene50CompoundFormat.java:92)
at org.apache.lucene.index.IndexWriter.createCompoundFile(IndexWriter.java:4680)
at org.apache.lucene.index.DocumentsWriterPerThread.sealFlushedSegment(DocumentsWriterPerThread.java:492)
at org.apache.lucene.index.DocumentsWriterPerThread.flush(DocumentsWriterPerThread.java:459)
at org.apache.lucene.index.DocumentsWriter.doFlush(DocumentsWriter.java:503)
at org.apache.lucene.index.DocumentsWriter.flushAllThreads(DocumentsWriter.java:615)
at org.apache.lucene.index.IndexWriter.doFlush(IndexWriter.java:3121)
at org.apache.lucene.index.IndexWriter.flush(IndexWriter.java:3096)
at org.apache.lucene.index.IndexWriter.shutdown(IndexWriter.java:1078)
at org.apache.lucene.index.IndexWriter.close(IndexWriter.java:1123)
at projet.Act1.main(Act1.java:31)
Caused by: java.lang.IllegalAccessException: class org.apache.lucene.store.MMapDirectory$2$1 cannot access class jdk.internal.ref.Cleaner (in module java.base) because module java.base does not export jdk.internal.ref to unnamed module #6e8dacdf
at java.base/jdk.internal.reflect.Reflection.newIllegalAccessException(Reflection.java:361)
at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:591)
at java.base/java.lang.reflect.Method.invoke(Method.java:558)
at org.apache.lucene.store.MMapDirectory$2$1.run(MMapDirectory.java:322)
at org.apache.lucene.store.MMapDirectory$2$1.run(MMapDirectory.java:314)
at java.base/java.security.AccessController.doPrivileged(Native Method)
at org.apache.lucene.store.MMapDirectory$2.freeBuffer(MMapDirectory.java:314)
... 13 more
please help me to fix this problem ...
and plz if there is anyone who is good in java and Lucene help I'm struggling I have a mini java/Lucene project and because of covid19 we didn't had any course... as you can see I can't even write a simple code

REST Annotated classes not part of org.superbiz package are not being deployed by TomEE Plume 7.0.4

On TomEE Plume 7.0.3/4 when I change my REST annotated classes package from org.superbiz then they are no more deployed when I deploy the war file.
Sample class is given below
package com.abc.rest.application;
import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Set;
#ApplicationPath("/rest-prefix")
public class ApplicationConfig extends Application {
public Set<Class<?>> getClasses() {
return new HashSet<Class<?>>(Arrays.asList(SimpleRESTPojo.class, SimpleRESTEJB.class));
}
}
Now ApplicationConfig class is never read by the TomEE Plume. What configuration I need to make so that TomEE recognize my rest application config class and other jax-rs, ejb and jpa annotated classes.
In system.properties set openejb.classloader.forced-load=com.abc
then only my application packages would be loaded. Tricky to understand.

cannot find symbol sshCloneUrl for cloning repository in bamboo-specs

I am working on writing Bamboo Specs for a build plan where i am trying to clone the repository from bitbucket. Here is my Spec code for Java
package tutorial;
import com.atlassian.bamboo.specs.api.BambooSpec;
import com.atlassian.bamboo.specs.api.builders.AtlassianModule;
import com.atlassian.bamboo.specs.api.builders.BambooKey;
import com.atlassian.bamboo.specs.api.builders.BambooOid;
import com.atlassian.bamboo.specs.api.builders.Variable;
import com.atlassian.bamboo.specs.api.builders.applink.ApplicationLink;
import com.atlassian.bamboo.specs.api.builders.permission.PermissionType;
import com.atlassian.bamboo.specs.api.builders.permission.Permissions;
import com.atlassian.bamboo.specs.api.builders.permission.PlanPermissions;
import com.atlassian.bamboo.specs.api.builders.plan.Job;
import com.atlassian.bamboo.specs.api.builders.plan.Plan;
import com.atlassian.bamboo.specs.api.builders.plan.PlanIdentifier;
import com.atlassian.bamboo.specs.api.builders.plan.Stage;
import com.atlassian.bamboo.specs.api.builders.plan.artifact.Artifact;
import com.atlassian.bamboo.specs.api.builders.plan.artifact.ArtifactSubscription;
import com.atlassian.bamboo.specs.api.builders.plan.branches.BranchCleanup;
import com.atlassian.bamboo.specs.api.builders.plan.branches.PlanBranchManagement;
import com.atlassian.bamboo.specs.api.builders.plan.configuration.AllOtherPluginsConfiguration;
import com.atlassian.bamboo.specs.api.builders.plan.configuration.ConcurrentBuilds;
import com.atlassian.bamboo.specs.api.builders.project.Project;
import com.atlassian.bamboo.specs.api.builders.repository.VcsChangeDetection;
import com.atlassian.bamboo.specs.api.builders.task.AnyTask;
import com.atlassian.bamboo.specs.builders.repository.bitbucket.server.BitbucketServerRepository;
import com.atlassian.bamboo.specs.builders.repository.viewer.BitbucketServerRepositoryViewer;
import com.atlassian.bamboo.specs.builders.task.CheckoutItem;
import com.atlassian.bamboo.specs.builders.task.CommandTask;
import com.atlassian.bamboo.specs.builders.task.MsBuildTask;
import com.atlassian.bamboo.specs.builders.task.ScriptTask;
import com.atlassian.bamboo.specs.builders.task.VcsCheckoutTask;
import com.atlassian.bamboo.specs.builders.trigger.BitbucketServerTrigger;
import com.atlassian.bamboo.specs.model.task.ScriptTaskProperties;
import com.atlassian.bamboo.specs.util.BambooServer;
import com.atlassian.bamboo.specs.util.MapBuilder;
import com.atlassian.bamboo.specs.api.builders.deployment.*;
/**
* Plan configuration for Bamboo.
* Learn more on: https://confluence.atlassian.com/display/BAMBOO/Bamboo+Specs
*/
#BambooSpec
public class PlanSpec {
/**
* Run main to publish plan on Bamboo
*/
public static void main(final String[] args) throws Exception {
//By default credentials are read from the '.credentials' file.
BambooServer bambooServer = new BambooServer("http://localhost:8085");
Plan plan = new PlanSpec().createPlan();
Deployment deploy = new PlanSpec().createDeployment();
bambooServer.publish(plan);
bambooServer.publish(deploy);
PlanPermissions planPermission = new PlanSpec().createPlanPermission(plan.getIdentifier());
bambooServer.publish(planPermission);
}
PlanPermissions createPlanPermission(PlanIdentifier planIdentifier) {
Permissions permission = new Permissions()
.groupPermissions("bamboo-admin", PermissionType.ADMIN)
.anonymousUserPermissionView();
return new PlanPermissions(planIdentifier.getProjectKey(), planIdentifier.getPlanKey()).permissions(permission);
}
Project project = new Project().name("Bamboo Specs").key("DRAGON");
Plan createPlan() {
return new Plan(
project,
"Java Specs Plan 2", "JSPTT2")
.description("Plan created from (enter repository url of your plan)")
.planRepositories(new BitbucketServerRepository()
.name("New Pattern Playbook")
.repositoryViewer(new BitbucketServerRepositoryViewer())
.server(new ApplicationLink()
.name("Bitbucket")
.id("bca01bef-a3d8-3da3-9187-91b73d0f1f77"))
.projectKey("ALM")
.repositorySlug("pattern.dotnet")
.sshPublicKey("ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQC2ETaXXCvEeZqcJWxybcMA91jiskcjrh5PB2UqLNenhiGRdh2kZBUgBMur/JsBYzFF2tNTlWdOXW1oRhSQ38PeUGXVRg3pMR5mxvOO/K/wO1DB6ZqjzRgwLFBJJMqCk58I213Y2pvd7Q9ot/xLludzh3rKmJFHwqOOBJYO/BLIqwL/hfM2Kvr4Op/284s5vBhJ+4l8sCrorSGsDE/r7mpAWjvrMGZGosLqgQtvrnzrL9XchxMT8UstzVeIAdHtWcwGOtv+1pjAqW6+035A/5W3tsWJ+EyBWFQ4rkZP/HFEdAAUgpM//oNVfB03+zZVn0BIKWX6evcwQPEjVzqn3+Ir http://bamboo-lab.cdk.com")
.sshPrivateKey("-----BEGIN RSA PRIVATE KEY-----\nMIIEowIBAAKCAQEAthE2l1wrxHmanCVscm3DAPdY4rJHI64eTwdlKizXp4YhkXYd\npGQVIATLq/ybAWMxRdrTU5VnTl1taEYUkN/D3lBl1UYN6TEeZsbzjvyv8DtQwema\no80YMCxQSSTKgpOfCNtd2Nqb3e0PaLf8S5bnc4d6ypi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b5XTusHJDZBmz407QKBgQCoCyHU4OeuPKYfJAbhWwKrO37isRmYTvtOz7vp\n/EIQ/JT+h+3KfBDqxGJSgrSSlUITEVQObc2Lotam066J//zRY10tO/0F8wBzOviK\nJOdKYUye/bW8bHdp1Ybrx67Jy+NO5tHlVPkzeKNNzBgsO1Tnz6h020H7rOBxhsMZ\nUJE9MQKBgDqRwfKmnBUcOElwvhQ1iH7aJL8zD5Ugbu0Xd72XUXcli1BcixvGdRyI\nWjnACbAVfPA/mcT8Ztto9uM/ZvH1rsAaqVnjKdxtlPYefuTff5QYUNWeR5C7FlJh\ntEJaTQdg/yXvnKpKCAtp+KJVfLyuRtuPwppR3yIGfpJNMYxUxHRb\n-----END RSA PRIVATE KEY-----\n")
.sshCloneUrl("ssh://git#stash-lab.cdk.com:7999/alm/pattern.dotnet.git")
.remoteAgentCacheEnabled(false)
.changeDetection(new VcsChangeDetection()))
.stages(new Stage("Stage 1")
.jobs(new Job("First Job","JOB1")
.tasks(new ScriptTask()
.inlineBody("echo Hello World")
)));
}
Deployment createDeployment() {
return new Deployment(new PlanIdentifier("DRAGON", "JSPTT"),
"Java Specs Plan Deployment")
.releaseNaming(new ReleaseNaming("release-1")
.autoIncrement(true))
.environments(new Environment("Java Specs environment")
.tasks(new ScriptTask().inlineBody("echo Hello world!")));
}
}
Error:
[ERROR] /Users/kamblea/Documents/REPOS/bamboo-spec/java/bamboospecjava/bamboo-specs/src/main/java/tutorial/PlanSpec.java:[90,25] cannot find symbol
[ERROR] symbol: method sshCloneUrl(java.lang.String)
[ERROR] location: class com.atlassian.bamboo.specs.builders.repository.bitbucket.server.BitbucketServerRepository
[ERROR]
[ERROR] -> [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] http://cwiki.apache.org/confluence/display/MAVEN/MojoFailureException
I resolved it on my own.
Solution: I am using Bamboo version 6.3.1 and trying to use Bamboo Specs 6.4 version which is only compatible with Bamboo 6.4 and higher version.
So, I refer the older API reference to solve this issue and it worked.

PDF reader not working

import java.io.BufferedWriter;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.FileWriter;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import java.nio.file.Files;
import com.itextpdf.text.pdf.PdfReader;
import com.itextpdf.text.pdf.parser.PdfReaderContentParser;
import com.itextpdf.text.pdf.parser.SimpleTextExtractionStrategy;
import com.itextpdf.text.pdf.parser.TextExtractionStrategy;
`
public class Test{
public static void main(String []args) throws IOException
{
String pdf= "c:\\sample.pdf";
PdfReader reader = new PdfReader(pdf);
}
}
it not working
like it should i am running windows
need help please help i tried a lot of things but still getting the same message
here is the error message
this is the output i get when i tried ur code
File Exists: true
Exception in thread "main" java.lang.NoClassDefFoundError:
org/bouncycastle/asn1/ASN1Encodable
at com.itextpdf.text.pdf.PdfEncryption.<init>(PdfEncryption.java:148)
at com.itextpdf.text.pdf.PdfReader.readDecryptedDocObj(PdfReader.java:1024)
at com.itextpdf.text.pdf.PdfReader.readDocObj(PdfReader.java:1430)
at com.itextpdf.text.pdf.PdfReader.readPdf(PdfReader.java:732)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:181)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:219)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:207)
at com.itextpdf.text.pdf.PdfReader.<init>(PdfReader.java:197)
at pdfconverter.Test.main(Test.java:37)
Caused by: java.lang.ClassNotFoundException:
org.bouncycastle.asn1.ASN1Encodable
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)
... 9 more
The code looks good to me. Perhaps more information on the error you are having? For instance, it could be a classpath error - something like the itextpdf classes not being located...
In case it helps as a baseline - the following code works for me. I removed the extraneous includes, though they won't hurt to leave them in.
import java.io.File;
import com.itextpdf.text.pdf.PdfReader;
public class Test {
public static void main(String[] args) {
String pdf= "C:\\Java-Design-Patterns.pdf";
try {
System.out.println("File Exists: "+new File(pdf).exists());
PdfReader reader = new PdfReader(pdf);
int count = reader.getNumberOfPages();
System.out.println("PDF has "+count+" pages.");
} catch (Exception e) {
System.out.println("Failed to open PDF ["+pdf+"]: "+e);
e.printStackTrace();
}
}
}
The output is:
File Exists: true
PDF has 183 pages.
The itext jar I used is: itextpdf-5.5.12.jar (included via maven).
The pdf I used (courtesy of google: java design patterns pdf) is here: http://enos.itcollege.ee/~jpoial/java/naited/Java-Design-Patterns.pdf
I haven't read it yet, but the first page looks good ;)
That said, itextpdf is quite awesome.
java.lang.NoClassDefFoundError: org/bouncycastle/asn1/ASN1Encodable
clearly indicates the issue: Bouncy Castle is missing! (Or at least the required version is missing.)
Bouncy Castle is a library used by iText for encryption, decryption, signing, and signature verification, here their web representation.
Thus, add the Bouncy Castle libraries to your class path. Please be aware, though, that the BC version required depends on the iText version in question. The maven link you provided for your itext7 version indicates that BC 1.49 is required.