0

I'm trying to start java class from commad line (Java 7.0, Windows XP). Class is packaged to jar and deployed to execution environment with other jars needed for execution. Not to be verbouse (and not to hardcode list of jars that could be chaged rarely) I'm trying to user wildcard. Next code is not working for me

java -cp ../classes/* some.package.Main

it says "Could not find or load main class" from very first jar of that directory. Java doesn't look for my class in other jars.
It should according to Understanding the class path and package names, isn't it?

All works fine if I set jar file explicitly

java -cp ../classes/playground.jar some.package.Main

But this doesn't fit for me because in other jars I also have main classes and I would like to have only one start script with configured classpath and environment variables etc. and only put class name as an argument to start.

What is wrong with first command line?

Resolved: escape wildcard processing in java classpath

Thanks.

Community
  • 1
  • 1
Mike
  • 20,010
  • 25
  • 97
  • 140

2 Answers2

0

You need to create a manifest and define which class is the main class. Here is a reference.

Nitin Chhajer
  • 2,299
  • 1
  • 24
  • 35
  • What if my jar contains "usefull command line tools" for my project that could be started as separated jobs/tasks, executed by admins? Main class in manifest force me to have only one main class in a jar. – Mike Jul 21 '12 at 13:38
  • @MykhayloAdamovych In that case you can create a single jar and pass command line arguments which can be used to control the path of your program flow. You don't need to create or execute multiple jars – Nitin Chhajer Jul 21 '12 at 13:42
  • Current project last almost 10 years and have huge amount of dependent jars, huge amount of scripts and kilometers of ant build scripts. I need to write one more simple flexible script to start class I need, not to create script for each job/task. – Mike Jul 21 '12 at 13:48
0

to run jar having main class just do :

java -jar ../classes/playground.jar 

it will .. try

Harmeet Singh
  • 2,555
  • 18
  • 21
  • I dont want to start jar having main class. I want to start exact class from classpath. – Mike Jul 21 '12 at 13:39