Win a copy of Succeeding with AI this week in the Artificial Intelligence and Machine Learning forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
  • Junilu Lacar
Sheriffs:
  • Tim Cooke
  • Jeanne Boyarsky
  • Knute Snortum
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:
  • salvin francis
  • fred rosenberger
  • Frits Walraven

java command error

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have an application that is in a directory called processXXX. This folder has a build/processXXX directory which contains the classes for the application: the main class name is processXXX. It also has a lib where i have the necessary jar files to run an irreports from jasper. The source directory is in src/processXXX where the package name is processXXX. For the life of me i am not able to issue the java command properly and i am at a loss as to why.

I have tried java -cp build/processXXX processXXX which returns an error java.lang.NoClassDefFoundError: processXXX (wrong name: processXXX/processXXX) at.... or if i use java cp build/processXXX processXXX.processXXX then i get a different error: Could not find or load main class processXXX.processXXX. I issue the java command from the root directory processXXX.

By the way, if i use netbeans, everything runs fine. So the code actually works, but when i try it manually i just am not able to make it work. Any suggestions would be appreciated.
 
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, and welcome to JavaRanch.

I think you have too many things named processXXX, and it's confusing. Where exactly is your class file? If the class name and package name are both processXXX, then it should be in build/processXXX/processXXX.class. In that case, you'd run it with:

java -cp ./build processXXX.processXXX

The package name shouldn't be part of your classpath entry.

That should work assuming: you run it from the parent directory of build, you are running on a Linux/Un*x/Mac (on Windows change the / to \), and your class correctly defines a main method. You also need classpath entries for each jar you need to include, although you can use a wildcard in Java 6 and above.
 
joao coelho
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree with the processXXX naming, it was a residue from my work with jdev.
Here is the directory:processXXX
under it i have: build which has the class files,dist for jar files, and a src directory which has the source code: src/processXXX/java files. I also have a directory lib which has the jasper libraries i need.

I followed the instructions for java command and it worked. Now my problem is that it is crying about my libraries, the jar files in the lib directory: It bombs with NoClassDefFound: net/sf/jasperreports/engine/JRException. I need to try your suggestion for the library tommorrow as i am leaving work pretty soon.

Thank you very much for the suggestions. I had looked at the oracle site but the instructions were not clear to me.
 
joao coelho
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is a follow up.
In this application i am creating a jasper report. Under the project directory I have a build directory with my classes a lib directory which has all the jar files used for jasper.
I compile the application by giving it a classpath of "lib/j.jar;lib/a.jar;...", i give the sourcepath as src and it compiles without any errors.
But when i try to run java cp ./build package.mainclass i get an error with JRException.

I have been at this problem for several days and i am not able to make it work. If i use netbeans and give the same parameters for the libraries, i get no errors. I am at a loss.

Any help or suggestions are highly appreciated.
 
Greg Charles
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A JRException, huh. Well, the good news is it sounds like you're successfully entering your application and even successfully running some Jasper code. I mean, it wouldn't know how to throw a JRException if it weren't making it to that stage. If you'll post the error message, and maybe the stack trace, we might be able to diagnose it for you.
 
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You need to include your jasper jar files in the classpath when you run it as well as when you compile it.
 
joao coelho
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all for the help.
So, i have a src directory sucha src/packageName/*.java.
I also have a build directory with the same structure but there i keep the class files.
I also have a lib folder with all the jar files for the jasper reports and an oracle driver.
I also have a dist folder for the distribution.jar file with a lib subfolder which contains the jar files from the lib folder above.

My javac is as follows, roughly since i am not yet at work: javac -classpath .;"lib/file1.jar;lib/file2.jar;....." -sourcepath src src/packageName/*.java -d build.
No errors and it compiles fine and places the class files in the build directory.

When i tried to create a jar file i would do the following: jar cvfm dist/distribution.jar manifest.txt -C build . , everthing seems to work except when i try to rung java -jar distribution.jar i get the same error i get when i try to run the java class from the java command. So, i am not sure if the way i am compiling the classes is incorrect or what.

I will post my error message when i get back to work in a couple of hours as i need to do some errand first.

again, thank you all.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you have a Main-Class and a Class-Path setting in your manifest file ?
 
joao coelho
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes i do.
The path of the application is as follows: C:\DAT\process_emp634_V_1.
underneath i have the manifest file: which contains the following:
Manifest-Version: 1.0
Main-Class: process634.process_emp634
Class-Path: lib/commons-beanutils-1.8.0.jar
lib/commons-digester-1.7.jar
lib/commons-collections-3.2.1.jar
lib/commons-logging-1.1.jar
lib/groovy-all-1.5.5.jar
lib/iText-2.1.0.jar
lib/jasperreports-3.6.1.jar
lib/log4j-1.2.15.jar
lib/ojdbc14.jar
 
joao coelho
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the javac compile command, here is what i do:
C:\DAT\PROCES~2>javac -classpath .;"lib/commons-beanutils-1.8.0.jar;lib/commons-digester-1.7.jar;lib/commons-collections-3.2.1.jar;lib/commons-lo
gging-1.1.jar;lib/ojdbc14.jar;lib/groovy-all-1.5.5.jar;lib/jasperreports-3.6.1.jar;/lib/iText-2.1.0.jar;lib/log4j-1.2.15.jar" -sourcepath src/pro
cess634 src/process634/*.java -d build

process634 is the package name.

When i then run the java command:
C:\DAT\process_emp634_V_1>java -cp .;"lib/commons-beanutils-1.8.0.jar;lib/commons-digester-1.7.jar;lib/commons-collections-3.2.1.jar;lib/commons-
logging-1..1.jar;lib/ojdbc14.jar;lib/groovy-all-1.5.5.jar;lib/jasperreports-3.6.1.jar;lib/iText-2.1.0.jar;lib/log4j-1.2.15.jar;build" process634.process_emp634

I get the following error:

Exception in thread "main" java.lang.NoClassDefFoundError: org/apache/commons/logging/LogFactory
at net.sf.jasperreports.engine.xml.JRXmlDigesterFactory.<clinit>(JRXmlDigesterFactory.java:178)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:199)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:164)
at net.sf.jasperreports.engine.xml.JRXmlLoader.load(JRXmlLoader.java:148)
at process634.process_emp634.main(process_emp634.java:66)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.logging.LogFactory
at java.net.URLClassLoader$1.run(Unknown Source)
at java.net.URLClassLoader$1.run(Unknown Source)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
at sun.misc.Launcher$AppClassLoader.loadClass(Unknown Source)
at java.lang.ClassLoader.loadClass(Unknown Source)
... 5 more

It feels like somehow it gets confused as to where the libraries are. But i think it is me who is confused.



 
Greg Charles
Sheriff
Posts: 3036
12
Mac IntelliJ IDE Python VI Editor Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is saying it can't find a class in Commons Logging. In your classpath, I see:

lib/commons-logging-1..1.jar

It looks like there might be an extra dot in there.
 
joao coelho
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Greg,
I thought you might be on to something but i checked this morning and there are no extra dots. In the lib folder the name is commons-logging-1.1.jar. I am not sure what's going on. I have the same application in netbeans and it works fine there. I can run the jar file from anywhere as long as i have the lib subdirectory under the location where the jar file is located.

I am at a loss. I will keep plugging along and if i do find a solution i will post it in the event anyone else runs into this difficulty.
 
joao coelho
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
here is the solution: as soon as i posted my reply to Greg, i realized he was talking about my java command. For, as soon as i removed the extra period in lib/commons-logging-1..1.jar, the whole thing came together, the application runs fine. What a fool. Thank you all for the time spent trying to help out. Unfortunately, i did not have another pair of eyes to check my spelling and the mistake probably just kept on repeating. Thanks again.
 
Popeye has his spinach. I have this tiny ad:
Try Free Java/.NET Libraries for Word Excel PowerPoint and PDF
htttp://www.e-iceblue.com/free-apis.html
    Bookmark Topic Watch Topic
  • New Topic