• Post Reply Bookmark Topic Watch Topic
  • New Topic

normal java project in Servlet choose the wrong path ?

 
Mathias Krill
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Coderanch,

I have put normal a java project as a .jar (="Calculator_Project") into the WebContent/WEB-INF/lib folder.

This"Calculator_Project" need relative paths to folders:

/debug/indicatorscfg/output.indicatorcfg (it will write and later read here)
/temp/indicatorrunner (will write and read here)
/scripts (just read)
/models (just read)

The dynamic web project has a servlet named "runEval" where are the methodes of the .jar project (=Calculator_Project") are called.

Now the problem:
The methodes of the Calculator_project search for the folders (debug, temp scripts etc) in the directory: Calculator_Webservice/src
and not in the Calculator_Webservice/WEB-INF/ as i would expect it.

I could life with that i have to put these directory's into the /src directory. But that works only if the Calculator_Project" tries to read stuff, if it write stuff i get the error:
ERROR WorkflowEngine - java.io.FileNotFoundException: debug\indicatorscfg\output.indicatorcfg
org.eclipse.emf.mwe.core.ConfigurationException: java.io.FileNotFoundException: debug\indicatorscfg\output.indicatorcfg


I cannot change the way the "Calculator_Project" in the .jar need this relative folders. If i use the .jar in a normal java project and call the classes/methodes of the project with the needed folders (wich it grabs from the top domain of the programm) works fine.

Ideas how i can solve that problem wich i cant get rid of since weeks ?
Thanks in advanced.


(in the attached picture are the temp, scripts, models directories missing, they are located in the WEB-INF directory
myproject.png
[Thumbnail for myproject.png]
Structure
 
Stefan Evans
Bartender
Posts: 1822
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How are you running this program?
You say the Calculator program is storing things in relative directories. Relative to what?
The user.dir? (i.e. current working directory? ) Can you specify/change that in your startup?

Working with files under a deployed web application is not normally recommended.
The standard approach would be to specify/configure a directory where all file operations should go to.

 
Mathias Krill
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans wrote:How are you running this program?
You say the Calculator program is storing things in relative directories. Relative to what?
The user.dir? (i.e. current working directory? ) Can you specify/change that in your startup?

Working with files under a deployed web application is not normally recommended.
The standard approach would be to specify/configure a directory where all file operations should go to.



hi thank you for your quick response, sorry if my answer is not accurate, im still new to java.

Stefan Evans wrote:How are you running this program?
You say the Calculator program is storing things in relative directories. Relative to what?

Ill try to explain that with an example: in the origin (not jar'ed) Calculator_Project the methodes are in the class for exampe: /Calculator_Project/src/<packagename>/class
then the relative paths like the debug, scripts, temp directory are:

Calculator_Project/debug/indicatorscfg/output.indicatorcfg
Calculator_Project/temp/indicatorrunner
Calculator_Project/scripts
Calculator_Project/models

if i put that Calculator_Project in .jar and use the methodes in another normal java project for example "Second_Project" all works if the folders are under

Second_Project/debug/indicatorscfg/output.indicatorcfg
Second_Project/temp/indicatorrunner
Second_Project/scripts
Second_Project/models .

Stefan Evans wrote:
Can you specify/change that in your startup?


i already spent lots of days to put additional base-paths in the Calculator_Project , but there are lots of dependencies and mixed script languages in it wich i messed up - so i dont want change the way the Calculator_Project works (its not my project).

Stefan Evans wrote:
The standard approach would be to specify/configure a directory where all file operations should go to.


Can i do that in the dynamic web project?

I run a methode of the .jar Calculato_Project in the runEval Servlet, in the doGet Methode:

Calculatorslots [] calculatorslots = calculator_project.runIndicators(path, modelname); (path is the model-path, wich is found without a problem)
 
Stefan Evans
Bartender
Posts: 1822
10
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
From your reply, I presume you are running this from Eclipse IDE?

If you go into the run:configuration menu and look at the "arguments" tab, there is a property down the bottom for "Working Directory"
Possibly changing that from the default might help you out?

 
Mathias Krill
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Stefan Evans: From your reply, I presume you are running this from Eclipse IDE?

Yes

If you go into the run:configuration menu and look at the "arguments" tab, there is a property down the bottom for "Working Directory"
Possibly changing that from the default might help you out?


I tried the direct directory of the project , instead the default eclipse. Like before the
/debug/indicatorscfg/output.indicatorcfg was still not found :-(
 
Mathias Krill
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Okay i finaly solved the problem - i still dont know why this was the right thing:

I just created a new class "Calculator_Caller" put that in a package "Caller" and than the servlet "runEval" called this class in its doGet-methode. And thats it !

Bevor i did that -the runEval doGet-Methode did that on their own.

And your tipp mr. Stefan to change the running-directory was also a part of the answer.
 
Mathias Krill
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In Ecplise it now runs. If i export it to a war-file and deploy on tomcat i get a execption when calling the runEval servlet:

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!