0

I have been using Eclipse lately, where compiling and running the program is very simple. Not much needs to be done in setting the classpath. But apparently that is not the case when it comes to running them from commandLine. when I try compiling from terminal, I am having various errors. I am pasting an image of my package structure of the project cp125_soln. Now I want to compile Invoice.Java in the com.scg.domain package, I tried

javac src/main/java/com/scg/domain/Invoice.java 
src/main/java/com/scg/domain/Invoice.java:17: error: package com.scg.util does not exist
import com.scg.util.StateCode;
.......................//long error message

This means I do not have com.scg.util.* in my classpath. so I tried

javac -cp src/main/java/com/scg/util/*  src/main/java/com/scg/domain/Invoice.java 
src/main/java/com/scg/util/ListFactory.java:8: error: package org.slf4j does not exist
import org.slf4j.Logger;
                ^
src/main/java/com/scg/util/ListFactory.java:9: error: package org.slf4j does not exist
import org.slf4j.LoggerFactory;
                ^
src/main/java/com/scg/util/ListFactory.java:11: error: cannot find symbol
import com.scg.domain.ClientAccount;
                     ^
  symbol:   class ClientAccount
  location: package com.scg.domain
  ................... // long error message

I read different articles on how classpath works and how to provide it in command-line. but when it comes topackage level structures, I am not able to find a good tutorial on how to COMPILE and RUN packages. If a little help could be provided here on the propery way to compile and run these kind of packages, it will be very helpful.

enter image description here

2

1 Answer 1

1

javac src/main/java/com/scg/domain/Invoice.java

Try this:

cd src/main/java
javac com/scg/domain/Invoice.java
Sign up to request clarification or add additional context in comments.

5 Comments

without doing cd src/main/java, is it possible to make it work? I am just curious..Thanks
Yes, but you have to add the -sourcepath src/main/java option, and you're still in the wrong place to execute the program. Do it this way.
why do you say I am still in the wrong place to execute the program..?
Because src/main/java isn't implicitly on your CLASSPATH, but . is.
If you could spare a minute, kindly look at my package structure above. I have a class file in app package. I tried javac app/Assignment03.java when I am in src/main/Java, that did not compile, giving similar errors above, I also tried javac -cp /Users/sridhar/.m2/repository/org/slf4j/slf4j-log4j12/1.7.5/:com/scg/domain/:com‌​/scg/util/* app/Assignment03.java, that did not work either. please give suggestion

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.