• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Batch file for an eclipse project

 
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi guys, I built a project in eclipse, now I want to make a batch file that executes the app without eclipse. My main class is under a hierarchy like this,

classes\x\y\z\mainClass.class

If I cd to this dir and use java mainClass, it dosent work!

How to run the app?
 
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What exactly is your x/y/z. Is it a package or just a windows directory like classes.

Naseem
 
Ranch Hand
Posts: 961
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
> java -cp classes x.y.z.mainClass

If x/y/z is a package.

I have to add, also, that altough not critical, your class name "mainClass" violates the JavaBeans naming policy. It should be MainClass.
 
Edward Morris
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Oh dont worry, mainClass is what I gave out as a name on the forum. My main class is diff, but anyways, it didnt work. I get the same noclassdeffound error! and yes, its a package....
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You have to make sure that you set the classpath correctly.

Suppose your project is in C:\MyProject, and you have a directory C:\MyProject\classes\x\y\z with a file MainClass.java in there.

First you have to compile your source code from the directory C:\MyProject:

C:\> cd \MyProject
C:\MyProject> javac x\y\z\MainClass.java

The you run it from the directory C:\MyProject:

C:\MyProject> java -cp . x.y.z.MainClass

Note this: You use the -cp switch to specify the classpath. The dot "." indicates the current directory. So you include the current directory in the classpath.

Then you specify the fully qualified name of your class (the name of your class including the packages in front of it).

If your class needs other classes that are inside JAR files or in a directory somewhere else on your harddisk, you'll have to add those classes to the classpath as well. For example:

C:\MyProject> java -cp .;mylibrary.jar;C:\OtherProject\classes x.y.z.MainClass

More info: How Classes are Found
 
Edward Morris
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Ok I was able to compile but I am stll not able to run it.

here is exactly what my proj looks like, can anybody please help me with a good batch file?

MyProj
+--classes
|xxxxxxxx|
|xxxxxxxx+--x
|xxxxxxxxxxx|
|xxxxxxxxxxx+--y
|xxxxxxxxxxxxxx|
|xxxxxxxxxxxxxx+--z
|xxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxx+--a
|xxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxx+--MainClass.class
+--sources
|xxxxxxxx|
|xxxxxxxx+--x
|xxxxxxxxxxx|
|xxxxxxxxxxx+--y
|xxxxxxxxxxxxxx|
|xxxxxxxxxxxxxx+--z
|xxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxx+--a
|xxxxxxxxxxxxxxxxxxxx|
|xxxxxxxxxxxxxxxxxxxx+--MainClass.java
|
|
+--Resources (icons and stuff)

[ July 21, 2006: Message edited by: Edward Morris ]
[ July 21, 2006: Message edited by: Edward Morris ]
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Please copy and paste the exact error message from the command prompt and post it here.
 
Naseem Khan
Ranch Hand
Posts: 809
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If MyProject is in suppose c:\java_project directory

Here is your batch file......

---------------------------------------------------------

Set classpath=%classpath%;c:\java_project\MyProj\classes

java x.y.z.a.MainClass

---------------------------------------------------------

Does that help?


Naseem
 
Edward Morris
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This got it to run, but now the prob is when I compile, the classes are not going to the classes folder. They are ending up in the sources folder. I need a script to compile my proj just like eclipse does. Read from the sources folder and generate the classes in the classes folder for corresponding packages. And then a script to run it. That would solve my problem, can anyone help?
 
Jesper de Jong
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Edward, please read the documentation of javac. You need to use the "-d" switch to tell it that you want to have your class files in the classes directory.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic