Can't figure out cause for NoClassDefFoundError: aspose/pdf/Paragraph - java

I can't get any pages of my webapp to load (locally on Tomcat 7.0.2.6), due to this NoClassDefFound error. I'm at my wits end trying to figure out what the cause is, here is what I know:
My coworker has this project successfully running locally (on Tomcat) and on our development server (WebLogic).
I have done a fresh pulldown from svn so my code is exactly the same as his. I've verified that I have a shared library reference to Aspose (and that the required .jars are in there), and that weblogic.xml has an entry for it.
We saw this same error when initially deploying on WebLogic because the Aspose library was named incorrectly, but it ran fine locally on his Tomcat server.
I've tried cleaning and rebuilding the project to no effect.
As best as I can figure, it has to be either a Tomcat issue, or maybe an Eclipse setting.
Has anyone encountered a similar situation? Any ideas on what to try to resolve this?

First thing you need to do is determine if you are colliding with another class with the same name and package. The easiest way to do this is with the cygwin/linux console, save this shell script to a file say, findjar
find "$1" -name "*.jar" -exec sh -c 'jar -tf {}|grep -H --label {} '$2'' \;
put it in your path and navigate to the root of the server instance and run the script like this
findjar . yourclass
Note the period, dont forget it. this will return if you have multiple classes with the same name in your project.
once your sure the project is clean and there is only one copy of the class, i would try actually adding your shared libraries folder to the websphere server instances JVM arguments. to do that:
Go into the admin, click on servers
Open server types, click on websphere application servers
You should see your server listed there, click on it
On the right hand side, you will see a section “server infrastructure” and below that is a subsection “Java and process Management”
Open that section and click on “Process Definition”
On the process definition screen is another right hand column. Click on “Java Virtual Machine”
Yes, finally we are on the correct screen, there is an end in sight here, I promise
On the virtual machine page, there is a large text field labeled “Classpath” What you need to do is enter the full path to the shared libraries folder
its odd and makes no sense to have to do it, but i have had to do that in the past to allow my code to see the properties files in a shared resource.

It is possible that your colleague has java librarys installed within his Tomcat instance itself.
Take a look in the Tomcat directory for some lib folders (I cant remember the exact location and I think it changes based on the version) but something like ${CATALINE_HOME}/common/lib
Verify that he doesnt have differen JAR files in his tomcat installation as yours.
From this question: Does Tomcat load the same library file into memory twice if they are in two web apps?
They are apparently stored here:
Tomcat 6 $CATALINA_HOME/lib
Tomcat 5 $CATALINA_HOME/common/lib

Related

Zookeeper cli not starting

I've installed zookeeper v 3.4.9 on suse using the following package:
http://download.opensuse.org/repositories/home:/nicolasbock:/midokura/openSUSE_Leap_42.2/x86_64/zookeeper-3.4.9-1.1.x86_64.rpm
Starting the server works just fine an the various application that need to connect to it seem to be able to do so just fine, however I'm getting a strange error when I try to start the client:
zkCli.sh -server 127.0.0.1:2181
Error: Could not find or load main class org.apache.zookeeper.ZooKeeperMain
I've tried searching around the internet but the only answer I've come up with is setting the env variable $CLASSPATH. I tried looking what classpath is used internally by the serve starting script and set $CLASSPATH to that but with no results.
I'm running openjvm v 1.8.0_121
I encountered this problem today on Ubuntu 18.04. On zookeper official download page once one follows the given mirror link and chooses stable version, he can see 2 files available. In my case those were:
apache-zookeeper-3.5.5-bin.tar.gz
apache-zookeeper-3.5.5.tar.gz
I chose apache-zookeeper-3.5.5.tar.gz, observed the same problem. Tried to print CLASSPATH as #Jonathan suggested, it was printing different paths however, problem is that the archive file did not contain zookeper jars, probably it is expected that user packages to jar himself as I could find source code in that archive file.
Downloading larger apache-zookeeper-3.5.5-bin.tar.gz archive, extracting and running ./zkCli.sh went smooth as it had everything necessary, so whoever faces the same problem, try that and see if it does the trick for you.
Are you trying on Unix or Windows?
I dont think, you need "-server 127.0.0.1:2181"
Just run zkCli.sh or zkCli.cmd
That is a classpath problem. The zkCli.sh script is attempting to launch a java app where the main class is ZooKeeperMain. However, java cannot find the ZooKeeperMain class file because the classpath being passed to java does not contain a jar file that contains the ZooKeeperMain class.
Typically, the ZooKeeperMain.class file is contained in a jar file at something like $ZOOKEEPER_HOME/zookeeper-3.4.13.jar.
You might trying modifying the zkCli.sh script to print out the classpath just before the script attempts to launch ZooKeeperMain. The classpath should contain the jar that contains the ZooKeeperMain class.
On my Windows 10 machine, my classpath looks like this:
/c/Program Files (x86)/Zookeeper/bin/../build/classes:/c/Program Files (x86)/Zookeeper/bin/../lib/slf4j-log4j12-1.7.25.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/slf4j-api-1.7.25.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/netty-3.10.6.Final.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/log4j-1.2.17.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/jline-0.9.94.jar:/c/Program Files (x86)/Zookeeper/bin/../lib/audience-annotations-0.5.0.jar:/c/Program Files (x86)/Zookeeper/bin/../zookeeper-3.4.12.jar:/c/Program Files (x86)/Zookeeper/bin/../conf:
I encountered a similar errors as yours when launching zkCli.sh from Git Bash for Windows on my Windows 10 machine. My issue was because of the way Git Bash was handling wildcards in the classpath. I initially had some *.jar entries in my classpath that I removed to get zkCli.sh to launch.

ClassNotFoundException: BasicDataSourceFactory

I have a JAVA application that runs fine in my local Windows7 environment on Tomcat7. I am trying to put this into production in a Linux environment.
Everything is done and is working fine except when my application tries to access the DB. Operations where DB is not involved, it works fine.
The error I get is
java.lang.ClassNotFoundException: org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory
This class is part of tomcat-dbcp.jar. This is placed in my $CATALINA_HOME/lib folder. Why is this still not getting picked up? Please help!
UPDATE: I also opened up the .jar file and checked. The org.apache.tomcat.dbcp.dbcp.BasicDataSourceFactory.class file is present.
Was finally able to crack it. My mistake - I was relying only on echo $CATALINA_HOME to check its location. Turns out that this can be misleading.
It is better to use
ps aux | grep catalina
In the output that comes look for catalina.base and catalina.home. The path given in front of these variables is the path from where Tomcat libs are being fetched. I had done a default installation and found the libs under /usr/share/tomcat7. As it turns out, the default installation done using yum did not provide the tomcat-dbcp.jar file. Instead it provided the commons-dbcp.jar. Read about tomcat-dbcp vs commons-dbcp
Changing the lib files under the usr/share/tomcat7 folder required me to use sudo bash. Also you may notice that the lib folder under /usr/share/tomcat7 is a simlink. Just do ls /usr/share/tomcat7 -l to get the parent location. You will be able to make changes only in the parent location.
Similar things can be checked for server.xml which is also finally being picked from /usr/share/tomcat7 itself.
The best way to manage all these is to create your own simlinks so that you don't need to bother about going to various locations after the first time.
Thanks to everyone who tried to help.

How to run database program outside the Netbeans IDE?

I am really new to database and this is my first program in database using java Netbeans 7.1 --- It is summer on our country now and I am a student with the course I.T. Our next subject on programming is about database and since there's no class I spend my time learning database for preparation for the next school semester and I refer to this site as my guide for the first database program I currently making now.
http://www.homeandlearn.co.uk/java/databases_and_java_forms.html
I did everything in the tutorial and I actually done doing the program.
The final thing I did is I clean and build the program since I want the program to run with out opening the netbeans again I downloaded the JRE and make my database_form.jar as a jar executable. "database_form" the name of my Netbeans Project. I do that by making javaw in JRE.7 as my dafault when opening any jar files.
Anyway, this is how i run the program.
Running Program in Netbeans IDE
Using Netbeans, before my program works I first need to "Start Server" on JavaDB. because if I didn't do that an Exception occurred "Err. connecting to server localhost 1527 and so on"
Running Program using jar executable alone.
The Problem is there's an Exception and Err in connecting still occurred.
What I want to achieve?
I want the program to run without opening the Netbeans IDE and going to Java DB to click the "Start Server", I dont want to do that anymore. Or my second option is to start the server using command prompt so that I just have to make a bat file so that whenever I open my program database_form.jar I just place the bat file on my desktop and run it.
Second Problem!
Actually, I already try my second option by using command prompt to start the server but I forgot how I did it, I just found it on some website the only thing I remember is the Exception says "Failed to lunch the server because the database Employees is missing. Employees is the name of my created database.
The O.S. I am using is Windows 7.
Thank you for all the reply and sorry for the long text I just want to be specific, :D
Right, from your description there seems to be a couple of things you are confusing.
First, databases are typically run as servers with multiple clients connecting to them thus allowing they contain to be shared. When you start Java DB you are starting the Java DB database server.
That said, lightweight databases, such as Java DB can be run in an embedded mode as explained here. Remember that the directory you point to with the derby.system.home property will need to contain the database files, if not you'll need to create that programatically too.
Second, there's various ways to run a Java application outside of an IDE, but jars themselves are not executable in the same way an exe file is in Windows.
The simplest way is to call the java executable passing the necessary classpath and the name of the class containing the main method. For example if I had a class called com.example.Application that had been compiled to a directory C:\dev\example\classes the following command line would run the application:
java -cp C:\dev\example\classes com.example.Application
If there were dependencies on external libraries, as there will be in your case on the Derby JDBC driver, then those would also need including in the classpath resulting in something like:
java -cp C:\dev\example\classes;C:\dev\lib\derby.jar com.example.Application
There's a full set of document on the Java launcher here.
Now, back to the jar. Like I said, jars are not executable but there is something that's know as an 'executable jar'. This is the same as any jar except there are some special additions to the manifest to specify the application entry point or main-class and the class-path as described here.
Once the main-class and class-path are specified in the jar's manifest, the following command line would run the application:
java -jar C:\dev\example.jar
You can even associate the jar extension with the java exe and double clicking the jar will cause the application to launch (though on a dev machine it's probably more useful that the jar extension be associated with WinZip or simlar in order to open that jar).
The default database in Netbeans is Derby/JavaDB. So you need to:
add the jar of javadb/derby in our classpath (it maybe already present, as it is bundled with java when you install it in Ubuntu)
setup a path with the jdbc URI to save the database data
I personally recommend the usage of hsqldb or H2 for this: they support in-memory database, very useful for stand alone project with no persistence data or for tests.
If you use window, add ODBC Data Sources from Administrative Tools to your Java Derby driver and run jar.

Specifying the location of Java communication libraries

Is there a workaround or a solution to having to place the javax.comm.properties file and the win32com.dll file in their respective folders?
My program works fine when I have the files stored as below:
%JAVA_HOME%/jre/lib/ext/comm.jar
%JAVA_HOME%/bin/win32com.dll
%JAVA_HOME%/lib/javax.comm.properties
This worked well until IT changed the permissions on our computers so that we can no longer write to these folders. I'd like to be able to install the Java program I wrote that uses the serial port once without needing to re-install it every time IT decides to update our JVMs. Does anyone know of a way to do this?
It's always a good practice to decouple the execution of your application from the configuration of the machine it is running on. In your case the first task will be identifying where you want to store the extra libraries and configuration files that are needed (its probably best to bundle them with your application). Once that is done, then you can configure your application to find them at launch:
Assuming the following directory tree:
myapp
|
--lib (archives and shared libraries stored here)
|
--resources (configuration files go here)
You could do:
java -Xbootclasspath/a:myapp/lib/comm.jar -cp "myapp/lib/*:myapp/resources" -Djava.library.path="myapp/lib"
Your JAR and DLL files would go into the lib sub-folder, and the property file would go into the resources subfolder.

Latest changes are not reflected in servlet (tomcat)

I am working on my project of quiet sometime now I am using tomcat and eclipse both working correctly till now..
I deployed the war on 22-1-2012 ( with some print messages) it was working correctly then next day I made some changes removed some messages and redeployed the file...In my webapps folder it is showing the latest time for 'last modified' of my war file.. what wrong i am doing tell me..
P.S any changes to JSP pages of same project are reflected but servlet class is unchanged
This is what log file shows
_SEVERE: A web application appears to have started a TimerThread named [MySQL Statement Cancellation Timer] via the java.util.Timer API but has failed to stop it. To prevent a memory leak, the timer (and hence the associated thread) has been forcibly cancelled. _
Well this is the summary of my problem i hope i can explain you now the problem
i again performed the following steps
Deleted my webapp directory from webapps
Tried to access servlet (it shows 'Resource not available')
Make some changes in print statement to debug
Redeployed WAR from eclipse
Again when access that servlet it is not the latest version it is showing same old messages.
Now tell me if there is solution....
Thanks in advance
After trying so many thing i just observed when i deploy the WAR file non-JSP servlet class files were not included in WAR when I manually add these class files in WAR all the changes are updated.. So now can u tell me how to auto deploy these in WAR..whats the problem?
The JSP files are not updating because they were precompiled, and even though they may pull information from files that have changed, each JSP file that may be affected needs to have a minor change made to it, like add a space and then remove a space, and then save it.
Then build your WAR, and then the updates should show. I went through this same problem tonight and none of the other answers helped. The key is, to check the file dates in the Tomcat directory of where you deployed the WAR. I noticed that even though I was deploying an entirely new cleaned WAR, and deleting all folders, there were still older cached files in there, probably because Eclipse keeps them to save compile time, thinking they don't have any changes.
Hope this helps
Go to Servers View in Eclipse:
Double click on your server. In my case, it’s Tomcat.
A Tomcat Web Module should pop up. Click on Modules tab at the very bottom (see Pic1)
Select your project. Click “Remove” button.
Pic 1:
Now you should see a star next to the Tomcat Tab. That means you need to save your changes. So do a Control+S.
Pic 2:
Right-click on your project in Project Explorer. Go to Maven -> Update Project…
Pic 3:
Now this is the important part, make sure you have “Force Update of Snapshots/Releases” checked. Having that part checked is critical. Then click Ok.
Pic 4:
Now look at your Server View. It should look like this, with a “Restart” warning telling you that it’s out of sync.
Pic 5:
Right-click on it and choose Restart
Pic 6:
Let the server restart. Now if you go back to the Server View, you should see that it’s synchronized. That’s what you want. Like this:
Pic 7:
Now you should be able to right-click on your project and choose “Run As” -> Run on Server and you should see your changes.
Pic 8:
If things still didn’t update, go back and look at your Server View and make sure it doesn’t say the restart thing like in Pic 5 above. If it does, please restart your server again like in Pic 6. Then click refresh on the browser.
Go to browser settings and clear the cache.
Check the log files for Tomcat, I bet there is a startup problem with your web app and it's not getting deployed.
The reality is that Tomcat cannot be running code it doesn't have a copy of. Especially if you have restarted it. It sounds like there is a separate "copy" of your web app that is actually in use. Either made inadvertently by you (hey lets face it, we've all done this) OR made by Tomcat in a location you weren't aware of.
Pick a unique file that exists within your web app. Maybe an icon name, or a configuration file name. Search the entire hard drive for it to locate exploded copies of the WAR file. This will help find it in a temp directory or working folder. Make sure to clean those up.
Also, make sure you are running the Tomcat that you think you are. Most developers with multiple Tomcat installations has also made the mistake of deploying to a different location. Look at the process list to see the arguments given to the JVM at launch time. Be sure to also check environment variable for things like CATALINA_HOME.
EDIT: Your update that JSP pages change, but classes do not make me think you have multiple JAR files on the class path that have the same file in it (one older version loaded first) OR you have changed a class name in the code base, but not updated references to it.
any changes to JSP pages of same project are reflected but servlet class is unchanged
It is not clear what you are saying.
If you are saying that the updated JSPs are in the expanded webapp directory, but the generated / compiled JSP classes have not changed (in the work directory), then try deleting the classes from the work directory. You may need to restart the web container too.
If you are saying that the non-JSP servlet classes have been updated (in the webapp) but you are not running them, then try restarting the web container.
If you are saying that the non-JSP servlet classes have not been updated in the webapp directory, then something went wrong in the webapp deployment. Shutdown the web container, delete the webapp directory (and the compiled JSPs for good measure) and restart the webapp.
After trying so many thing i just observed when i deploy the WAR file non-JSP servlet class files were not included in WAR when I manually add these class files in WAR all the changes are updated.. So now can u tell me how to auto deploy these in WAR..whats the problem?
So the problem is nothing to do with deployment. The problem is that you are not building the WAR file correctly in the first place.
I can't help with this because I don't use Eclipse to build my WAR files. (I use Maven so that the build process is scripted and reproducible ... and doesn't depend on me clicking the right buttons in the right order every time.)
is your tomcat server.xml pointing to the right Workspace?
to make sure, you go to tomcat installed directory -- find server.xml in the confi folder
for every war file, tomcat creates a similar named folder. Delete the folder, try to redeploy war again, hope it will reflect.
In web.xml file add one letter at the end and delete it and then by pressing enter save the file. After that run the program and it works with updated data.
go to catalina home\conf\context.xml
change <Context> to <Context reloadable="true">
Make sure you restart tomcat.
Boom.
You might have to still press F5 or Ctrl+F5 two or three times though.
TL;DR: Make sure your eclipse project is set to build automatically: Project > Build Automatically
I apologize for answering without having complete knowledge of what the WAR files are, but I assume the WAR files are the compiled .class files in the "build" folder.
I noticed that when I saved my Servlet "HelloWorld.java" in my case, that the compiled "HelloWorld.class" did not update at all. I could force the project to build by right clicking the java project and selecting "Build Project". After Building the project, the "HelloWorld.class" file was successfully updated, but the updated code still did not show on the server.
To get the results to show on the server, I had to click on my server (mine was called "Tomcat v9.0 Server at localhost [Started, Synchronized]") and then I clicked "Publish to Server". If you do not see your Servers, do: Window > Show View > Servers
I didn't even have to restart the server, after a few seconds (and refreshing google chrome), the website updated itself!
Of course manually building and publishing (and possibly restarting) the server is kind of too much for my lazy fingers, so I found how to fix it. You can just go to Project > Build Automatically. and then the website will update anytime you save a modified java file.
This solution worked for me because I was only missing the automatic building. but you could also have a problem where the server doesn't automatically publish.
I personally didn't have this problem so I'm just speculating, but there are some settings for publishing. In your "Servers" view, double click on your server name (in my case, double click on "Tomcat v9.0 Server at localhost [Started, Synchronized]"). A tab should open up showing your server settings. Expand the section titled "Publishing", and set your publishing settings as you desire. Right now mine is set to "Automatically publish when resources change".
Unfortunately I have no clue how to make the server automatically restart upon the saving of a modified .java file.

Categories