• Post Reply Bookmark Topic Watch Topic
  • New Topic

Trouble starting the application outside Eclipse  RSS feed

 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I'm trying to run my application outside Eclipse, but it doesn't work:



In Eclipse everything works perfectly, but now I need to make it work without the IDE. I'm using Maven for building. Why the /config/log4j.xml file is not found? I already checked, the file is inside the JAR file. This is the .bat file I start:



Any tip?

Thanks
[ August 19, 2005: Message edited by: Tiago Fernandez ]
 
Marilyn de Queiroz
Sheriff
Posts: 9082
12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Looks like a classpath issue. You need more than just a '.' in your classpath. You need to include each jar file you're using and the path to the log4j.xml file. I'm sure you did this at some point when you were setting up your project in Eclipse, but the command line can't read the Eclipse settings.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following looks like the path to a file in a jar file. You won't be able to use this in a FileInputStream() constructor.
Notice the ! It follows the path to the jar file that holds the log4j.xml file.
java.io.FileNotFoundException: file:\K:\billy\setup\lib\tlf-base-1.0.jar!\config
\log4j.xml (The filename, directory name, or volume label syntax is incorrect)

To read files from a jar you need to use the JarFile or ZipFile and associated JarEntry or ZipEntry classes. Or you could use the Class.getResourceAsStream() method.
 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Marilyn and Norm,

Thanks for replying. Looks like I was having a problem with Log4J, not with the startup bat file. So, I was using the DOMConfigurator tool for retrieving the log4j.xml file, and it works fine at Eclipse because there I read straight from the source folder. I couldn't use Class.getResourceAsStream() because the DOMConfigurator needs the full path of log4j.xml, not the InputStream of it. So, I solved this getting rid of DOMConfigurator and copying the log4j.xml file outside the JAR file.

Let me ask you now: how can I get rid of the startup bat file? I mean, there I set few parameters needed to run the application, but I don't like the idea that if the user closes the window then the program exits. It would be fine if at least I could hide this window. Is it possible?

Thanks a lot again.
 
Norm Radder
Rancher
Posts: 2240
28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Since your program requires several parameters on the commandline, you need a place to put them when you start your program. The batch file builds the commandline and then executes it.
This is a Windows OS question: How to start a program with a commandline.
A batch file is one way.

If your program didn't require the parameters, you could put it in a jar file and use the generic command: javaw.exe -jar YourJar.jar to start it.
That commandline is set in the registry when the java jre is installed.

Another possibility is to create your own Windows extension, say jarX and place your own commandline in the registry with the parameters you need:
javaw.exe -cp . -D... -D... -jar %1 where %1 is replaced by the OS with the filename of your jar file: YourJar.jarX
More complicated but it does remove the possibility of the user closing the DOS window associated with batch files.
 
Tiago Fernandez
Ranch Hand
Posts: 167
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Interesting... or I could use Quick Batch File Compiler 2.0.7.1 for creating an EXE file, but it would only work for Window$
[ August 20, 2005: Message edited by: Tiago Fernandez ]
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!