I have a Java application which runs on an Apache Tomcat server. The Java application is a web service.
From within one of the Java classes I try to access a file, however the following section of code throws a FileNotFoundException.
DataModel dm = new FileDataModel(new File("data/WheelChairData.csv"));
However if I run this Java application without using the server, I don't get the error message which means that it's apache that's not be able to find it. So where can I store the file WheelChairData.csv so that the server can find it ? is it possible to store it within Apache Tomcat, if so can you please point me in the right direction
Thank you.
Use this line and see where the path is:
System.out.println(new File(".").getAbsoluteFile());
(or if you are using logger, put output into it)
Related
This question already has answers here:
What causes and what are the differences between NoClassDefFoundError and ClassNotFoundException?
(15 answers)
Closed 4 years ago.
so I'm trying to write a java web service via Eclipse to expose some SQL Server data in XML format
I've some how managed to write a script that returns the SQL Server query results I want
I've also some how managed to set up a basic java web service that exposes XML of some dummy data (stored as a ArrayList) through localhost
All the necessary jars have been added via configure build path
Both work fine separately. But when I remove the dummy data to try and use the data from the query, I keep getting java.lang.NoClassDefFoundError com/microsoft/sqlserver/jdbc/SQLServerDriver errors
My dummy data involves simply hardcoding string data into the ArrayList
I get also get the string values of my query resultset via something like
rs.getObject("FieldName").toString()
I know this works because I can see the data when I print to console.
So I simply replace the hardcoded strings with this but it keeps throwing error
Any advice?
I managed to resolve it. Mostly this stems from my lack of knowledge between maven and non maven projects.
As I somewhat understand, with a non maven project, you would need to add the SQL server jar to the web-inf/lib folder. Since you're deploying tomcat, and then running the application on it. The tomcat server picks up the jars from that folder
In a maven project, I don't have that folder. Instead, via eclipse, I went into the Servers tab, double clicked on my server, clicked on Open Launch Configuration, and this brings up a similar window to if I were just to add the jar via build path
So in here, I added my SQL server jar, then restarted the server and it worked!
I'm developing a custom application for IBM BPM that uses these libraries: Jace.jar, pe.jar, log4j.jar, stax-api.jar, xlxpScanner.jar and xlxpScannerUtils.jar that are used to call a web service.
When I create a java project and add those libraries, it works fine. It also works ok when I create a dynamic web project using tomcat 8 as server; but when using jboss I don't get the expected result when calling the web service. So, does anybody know how to disable the modules that use these libraries? Or where to find information about it?
I want my application to be server independent.
This is my code:
try {
VWSession vwSession = new VWSession("userName", "userPass", "connPt");
vwSession.isLoggedOn(); /* It's loaded with 'false' value in jboss.
In tomcat it's loaded with 'true' value */
} catch (Exception e) {
Logger.getLogger(getClass().getName()).log(Level.FATAL, "Details: ", e);
}
To create an application that is server agnostic, you need to strictly adhere to Java EE specification. Meaning, use only those jars that are bundled as part of the Java EE version you are using. Then too, there are certain deployment descriptors specific to a given application server that would need to be used in some cases. For example - jboss-deployment-structure.xml, ibm-application-bnd.xml, etc.
In your case, xlxpScanner.jar is not a part of the Java EE spec, so making the application server independent is not possible with the current settings. You could look for a replacement of the part of this jar you are using with something Java EE has. In short, get rid of this jar alongwith xlxpScannerUtils.jar.
Alternatively, if you want jboss to run the application properly, add all the jars in a module and give it to the EAR/WAR using jboss-deployment-structure.xml. Details can be found here.
I had deployed an application in the application server Apache
Tomcat. My GWT application needs to access files in folder "C:
\Storage". In development mode the application runs like a charm but
in an external web server (Apache Tomcat) it does not run, crashes
when it tries to copy files from "C:\Storage" to "\docs". I think this
might be because i'm trying to access files outside the webroot. How
can i solve this situation? Using apache commons libs to deal with
files? Could be permissions? I need some enlightment, some help will
be very apreciated.
Thanks in advance,
João Cavaleiro.
Another (wild) guess: if you deploy wars without unpacking as real files, getRealPath("/doc") will return null. (You have no files inside a war). So you have to configure Tomcat:
http://tomcat.apache.org/tomcat-5.5-doc/config/context.html
upackWAR = true
Thanks you all for the replies. I actually figured out what the problem was: Paths.
"\docs" is the folder located in the root of the app.
Unfortunately Apache didn't wrote any exception on catalina.out log (the code catch the exceptions ocurred).
Simply i didn't create a new File(pathname) with the absolute path of the destination location, i was using only the "docs/filename.txt" assuming that the File classe would recognize the full path, "knowing" the location in the filesystem of the app. I assume that this is a situation to keep in mind with sepecific application servers because with eclipse/Jetty it works but with Apache Tomcat don't (I am developing a GWT application).
But in the matteer of fact, the debbug was not easy, the debbug mode with external server didn't work in the server side in the peace of code where i it's needed to do this io operations strange), and the System.out.println that i managed to help me figure out the problem didn't show up in the catalina.stdout (strange to and yes, i have compiled and deployed it on the Apache Tomcat with that modifications twice).
Thanks to everyone.
I have a WSDL file from which I have created Server Side Code Skeleton. Now after modification of these skeleton Java classes I have deleted the WSDL file from the project folder. Now, I am trying to prepare a web service for these classes. I m using Axis engine and apache tomcat 5.5 for this which is embedded with the eclipse. But when I start this I m getting the following error.
IWAB0489E Error when deploying Web service to Axis runtime
axis-admin failed with {http://schemas.xmlsoap.org/soap/envelope/}Server.userException java.lang.reflect.InvocationTargetException
Can any one help. What is this error??
I had this problem before, the solution?, use JAX-WS instead Axis.
I think you are trying to call some method from the client skeleton which you've generated from the wsdl file. If you are calling any of the methods which are exposed, make sure that the parameters which you are sending are correct.
userExceptions mostly come with sending wrong params
From my experience:
Check this
invocationTargetException occurs when some of the dependency class might be missed in the cass path(build path) of the webservice project(i mean, the webservice might be used some external jars or external projects as a reference,if suppose those are not in the class path(build path), it shows invocationTargetException exception while building webservice).so make sure all the dependency classes/projects must be in the webservice project class path(build path).
I am working on single solr app. I downloded solr exampple code for net, which is working fine while running on jetty server.It is having data which are to be indexed in C:\apache-solr-1.4.0\example\exampledocs and the indexes are stored in C:\apache-solr-1.4.0\example\solr\data, using jetty server indexes are created using command java -jar post.jar *.xml. Now i want to know how can i achieve this using Tomcat. do i need to change the configuration to change the path for indexe storage and for xml files storage. how data will b indexed so that i would able to search it.
If I understand your question correctly, you'll want to use the -Durl flag when running post.jar, e.g.:
java -jar -Durl=http://localhost:8080/solr/update post.jar solr.xml monitor.xml
In solrconfig.xml you can mention the path that has to hold the index
<dataDir>${solr.data.dir:}</dataDir>
I think you just have to read more from SOLR documentation, and click through what you have in the package.
There is an tomcat deployment doc in solr wiki:
http://wiki.apache.org/solr/SolrTomcat
And the war file is in the dist folder you've downloaded.
How to search it? There is no simple answer. I suggest you read more on the solr wiki. Find out what is a handler, what is the difference between dismax handler and standard handler, how schema.xml defines the database.