RE: Working Directory

2002-04-03 Thread Chapman, Carl


 This code actually works for me. 

  getClass().getResourceAsStream(Configuration.xml);

  I did dump the Configuration.xml file into the same directory where this
code exists and jar'ed them all up.

com/blort/packagename/Configuration.class
com/blort/packagename/Configuration.xml

   You can start this simple and then get fancy.



 -Original Message-
 From: Sanjay Bahal [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, April 03, 2002 2:28 PM
 To: Tomcat Users List
 Subject: RE: Working Directory
 
 
 Carig,
 I tried this it does not work. I can't get the stream.
 I have a property file in the classes directory- where
 I all my classes are. My code is:
 MyClass thisInstance  = new MyClass();
 InputStream stream =
 thisInstance.getClass().getResourceAsStream(propFile);
 if ( stream != null) {
   props.load(stream);
   stream.close();
 }else System.out.println(The stream null);
 
 Thanks
 Sanjay
 
 
 --- Craig R. McClanahan [EMAIL PROTECTED] wrote:
  
  
  On Wed, 3 Apr 2002, Sanjay Bahal wrote:
  
   Date: Wed, 3 Apr 2002 12:00:17 -0800 (PST)
   From: Sanjay Bahal [EMAIL PROTECTED]
   Reply-To: Tomcat Users List
  [EMAIL PROTECTED]
   To: Tomcat Users List
  [EMAIL PROTECTED]
   Subject: RE: Working Directory
  
   Thanks Mark  Craig.
   My situation is slightly different. I am trying to
   read the property file from a Java class on the
   server(not the servlet). I would think there would
  be
   a way around to do this- else I can work around to
   pass a param to the helper class.
  
  Consider using
  getClass().getResourceAsStream(myprops.properties)
  for
  this kind of purpose.  This looks for
  myprops.properties on your class
  path, and loads it from wherever the classes
  themselves are found (either
  an unpacked directory or a JAR file).
  
   Thanks
   Sanjay
  
  Craig
  
  
   --- Craig R. McClanahan [EMAIL PROTECTED]
  wrote:
   
   
On Wed, 3 Apr 2002, Wagoner, Mark wrote:
   
 Date: Wed, 3 Apr 2002 11:38:31 -0500
 From: Wagoner, Mark
  [EMAIL PROTECTED]
 Reply-To: Tomcat Users List
[EMAIL PROTECTED]
 To: 'Tomcat Users List'
[EMAIL PROTECTED]
 Subject: RE: Working Directory

 I place my properties files in the WEB-INF
directory and do the following to
 find them -

 String webInfFolder =
getServletContext().getRealPath(/WEB-INF)

   
This only works if the app is run from an
  unpacked
directory, which is not
guaranteed to be portable (not every server
  supports
running this way).
The best way to read a properties file is to put
  it
in the WEB-INF
subdirectory and use something like:
   
  Properties props = new Properties();
  InputStream stream =
   
   
  
 
 getServletContext().getResourceAsStream(/WEB-INF/myprops.prop
 erties);
  props.load(stream);
  stream.close();
   
which is guaranteed to be portable to any
  server.
   
Craig
   
   
 -Original Message-
 From: Sanjay Bahal [mailto:[EMAIL PROTECTED]]
 Sent: Wednesday, April 03, 2002 11:34 AM
 To: tomcat
 Subject: Working Directory


 I am trying to read a properties file from my
servlet.
 It always comes back saying file not found. I
  have
 tried placing the file in
 classes/web-inf/context-path. Ideally I would
  like
to
 lace it in my classes directory- How do I
  achieve
it.
 Thanks
 Sanjay


  __
 Do You Yahoo!?
 Yahoo! Tax Center - online filing with
  TurboTax
 http://taxes.yahoo.com/

 --
 To unsubscribe:
   
  mailto:[EMAIL PROTECTED]
 For additional commands:
mailto:[EMAIL PROTECTED]
 Troubles with the list:
mailto:[EMAIL PROTECTED]

 --
 To unsubscribe:
   
  mailto:[EMAIL PROTECTED]
 For additional commands:
mailto:[EMAIL PROTECTED]
 Troubles with the list:
mailto:[EMAIL PROTECTED]


   
   
--
To unsubscribe:
   
  mailto:[EMAIL PROTECTED]
For additional commands:
mailto:[EMAIL PROTECTED]
Troubles with the list:
mailto:[EMAIL PROTECTED]
   
  
  
   __
   Do You Yahoo!?
   Yahoo! Tax Center - online filing with TurboTax
   http://taxes.yahoo.com/
  
   --
   To unsubscribe:  
  mailto:[EMAIL PROTECTED]
   For additional commands:
  mailto:[EMAIL PROTECTED]
   Troubles with the list:
  mailto:[EMAIL PROTECTED]
  
  
  
  
  --
  To unsubscribe:  
  mailto:[EMAIL PROTECTED]
  For additional commands:
  mailto:[EMAIL PROTECTED]
  Troubles with the list:
  mailto:[EMAIL PROTECTED]
  
 
 
 __
 Do You Yahoo!?
 Yahoo! Tax Center - online filing with TurboTax
 http://taxes.yahoo.com/
 
 --
 To unsubscribe:   mailto:[EMAIL PROTECTED]
 For additional commands: mailto:[EMAIL PROTECTED]
 Troubles with the list: mailto:[EMAIL PROTECTED]
 

--
To unsubscribe:   mailto:[EMAIL 

RE: Apache Tomcat/4.0.3 - HTTP Status 500 - Internal Server Error -HELP-ME-PLEASE

2002-03-28 Thread Chapman, Carl


  So it executed the Servlet Login2 as evidence in the stacktrace

 root cause

 java.lang.NoClassDefFoundError
 at Login2.doGet(Login2.java:51)
 at
 javax.servlet.http.HttpServlet.service(HttpServlet.java:740)


  ... and it got all the way to line 51. It looks like there are other
classes from this jar package that are being invoked. If they are being
invoked with no exception then the jar file is found. But the class at line
51 is not found. My line counting isn't working so you need to point to the
source code line 51. Also assuming your classes are like this:
com.sap.mw.jco.JCO.Repository and the jco.jar file is in your WEB-INF/lib
directory.


 -Original Message-
 From: Korakaki Stella [mailto:[EMAIL PROTECTED]]
 Sent: Thursday, March 28, 2002 4:39 AM
 To: Tomcat Users List
 Subject: Apache Tomcat/4.0.3 - HTTP Status 500 - Internal Server Error
 -HELP-ME-PLEASE



  When I'm trying to execute the following servlet from the
 web browser:
 -

 import com.sap.mw.jco.*;
 import java.io.*;
 import javax.servlet.*;
 import javax.servlet.http.*;

 public class Login2 extends HttpServlet
 {

JCO.Client mConnection;
JCO.Repository mRepository;

 public JCO.Function createFunction(String name) throws Exception {
 try {
   IFunctionTemplate ft =
 mRepository.getFunctionTemplate(name.toUpperCase());
   if (ft == null)
 return null;
   return ft.getFunction();
 }
 catch (Exception ex) {
   throw new Exception(Problem retrieving JCO.Function object.);
 }
   }

 public void doGet (HttpServletRequest req,
HttpServletResponse res)
 throws ServletException, IOException
 {

  res.setContentType(text/html);
  PrintWriter out = res.getWriter();
  String tmp;

 out.println(htmlbody);

 try {
   // Change the logon information to your own system/user
   mConnection =
 JCO.createClient(300, // SAP client
   username,   // userid
   ,   // password
EN, // language
   127.0.0.1, // application server host name
   00);// system number
   mConnection.connect();
   mRepository = new JCO.Repository(ARAsoft, mConnection);
 }
 catch (Exception ex) {
   ex.printStackTrace();
   System.exit(1);
 }

 JCO.Function function = null;
 JCO.Table codes = null;
 try {
   function = this.createFunction(ZRFC_CUSTOMERS);
   if (function == null) {
 System.out.println(ZRFC_CUSTOMERS +
 not found in SAP.);
 System.exit(1);
   }

   JCO.ParameterList input=function.getImportParameterList();
   input.setValue(0001,BUKRS);

   mConnection.execute(function);

   codes =
 function.getTableParameterList().getTable(CUSTOMER);
   for (int i = 0; i  codes.getNumRows(); i++) {
 codes.setRow(i);

 tmp=codes.getString(NAME1);
 if (tmp.length()  12 ) {
 out.println(li);out.println(tmp);}
 else {out.println(li);out.println(tmp.substring(0,12));}
   }
 }
 catch (Exception ex) {
   ex.printStackTrace();
   System.exit(1);
 }
 out.println(/body/html);

  mConnection.disconnect();

 }
 }
 --


 
 Stella Korakaki
 Koutoudis Consulting


 --
 To unsubscribe:   mailto:[EMAIL PROTECTED]
 For additional commands: mailto:[EMAIL PROTECTED]
 Troubles with the list: mailto:[EMAIL PROTECTED]


--
To unsubscribe:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]




RE: Properties files.

2002-03-26 Thread Chapman, Carl



Had a similar problem. This code seems to work in a servlet (more comment
after):

--
PrintWriter out = null;
ServletContext servletContext = getServletContext();

try
{
out = response.getWriter();
}
catch ( IOException ioe)
{
return;
}

InputStream inStream = servletContext.getResourceAsStream( /blotto
);
BufferedReader in
   = new BufferedReader(new InputStreamReader( inStream ) );

try
{
for(String line = ; (line = in.readLine()) != null; )
{
out.print(line);
out.flush();
}
}
catch ( IOException ioe ) {}
---

 The text file 'blotto' is in directory context. That is, the name of your
app, the directory below webapps but above WEB-INF.




 -Original Message-
 From: Xiao, Wei [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, March 26, 2002 12:55 PM
 To: Tomcat Users List
 Subject: RE: Properties files.


 I just removed / in front of the properties files. I even checked
 index$jsp.java file. But I am still getting the same exception.

 Wei

 -Original Message-
 From: David Burns [mailto:[EMAIL PROTECTED]]
 Sent: Tuesday, March 26, 2002 3:49 PM
 To: Tomcat Users List
 Subject: Re: Properties files.


 Are you sure you want the / in the name?

 On Tuesday 26 March 2002 03:43 pm, you wrote:
  I put abc.properties in .../WEB-INF/classes and have the
 following codes,
  it gave me NullPointerException.
 
  java.util.Properties props = new java.util.Properties();
  java.io.InputStream is =
  props.getClass().getResourceAsStream(/abc.properties);
  props.load(is);
 
  java.lang.NullPointerException
  at java.io.InputStreamReader.(InputStreamReader.java:85)
  at java.io.InputStreamReader.(InputStreamReader.java:74)
  at java.util.Properties.load(Properties.java:176)
  at org.apache.jsp.index$jsp._jspService(index$jsp.java:66)
 
  Thank you.
 
  Wei
 
  -Original Message-
  From: David Burns [mailto:[EMAIL PROTECTED]]
  Sent: Tuesday, March 26, 2002 3:06 PM
  To: Tomcat Users List
  Subject: Re: Properties files.
 
 
  I load application property files off the classpath and was
 able to load
  property files from mywebapp/WEB-INF/classes directory.
 Had a little
  trouble
  with the log4j.properties, had to place that file in
 common/classes (may
  have
  to do with where log4j.jar is located).
 
  Hope this helps.
 
  -- David.
 
  On Tuesday 26 March 2002 02:56 pm, you wrote:
   Hi all,
  
   I was trying to migrating an existing application to
 Tomcat 4.0. We used
   a lot of properties files and just specified the
 directory in classpath,
 
  then
 
   we can call
   load(/abc.properties). Where should I put properties files
 
  (*.properties)
 
   in tomcat? How should I call to load it?
  
   Thanks a lot.
  
   Wei

 --
 To unsubscribe:   mailto:[EMAIL PROTECTED]
 For additional commands: mailto:[EMAIL PROTECTED]
 Troubles with the list: mailto:[EMAIL PROTECTED]


--
To unsubscribe:   mailto:[EMAIL PROTECTED]
For additional commands: mailto:[EMAIL PROTECTED]
Troubles with the list: mailto:[EMAIL PROTECTED]