• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

New to Java and trying to work with an existing app

 
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have been asked to modify a java application to send an email warning when certain events occur. I noticed the existing emailcommand class was sending to an internal smtp server, So I created a smtp ssl app that send via a gmail account and have that working. I am now trying to compile the existing application before I add my smtp ssl logic I got working. I think these a basic errors, but have not been able to resolve them. The following is the application I am compiling and the compiler errors. Thats in advance for any help or comments you can provide.





C:\fis>javac -classpath C:/fis/jre/lib/rt.jar;/fis/libmail/mail.jar;/fis/jre/lib
/jsse.jar;/fis/lib/xerces.jar;/fis/jre/lib/jce.jar;/fis/jre/lib/sunrsasign.jar;/
fis/lib/com.checksol.dex.gateway_v1r1m1f1.jar;/fis/lib/importscrubber.jar;/fis/l
ib/bcel.jar;/fis/lib/junit.jar;/fis/lib/DoxygenTask.jar;/fis/lib/jalopy-ant-bund
le-0.5.2.jar;/fis/lib/jdepend.jar;/fis/lib/xalan.jar;/fis/lib/jaxen-full.jar;/fi
s/lib/saxpath.jar;/fis/lib/Quick4rt.jar;/fis/lib/regexp.jar;/fis/lib/mail.jar;/f
is/lib/mailapi.jar;/fis/lib/activation.jar;/fis/lib/smtp.jar;/fis/lib/tools.jar;
/fis/build/classes/BytePumper.class src\EmailCommand.java
src\EmailCommand.java:5: '.' expected
import BytePumper;
^
src\EmailCommand.java:6: cannot resolve symbol
symbol : class Command
location: class EmailCommand
public class EmailCommand extends Command
^
src\EmailCommand.java:29: cannot resolve symbol
symbol : class CommandContext
location: class EmailCommand
public void execute(String[] tokens, CommandContext context) throws Mess
agingException, IOException
^
src\EmailCommand.java:40: cannot resolve symbol
symbol : variable BytePumper
location: class EmailCommand
BytePumper.pump(in, out);
^
4 errors

 
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Michael,

Welcome to the Ranch Seems that the rest of your custom classes has not been imported properly or else you are missing the Package declaration in the class you posted. Or the other classes present in the same package?

src\EmailCommand.java:6: cannot resolve symbol
symbol : class Command
location: class EmailCommand
public class EmailCommand extends Command


For sample, in the above error it says that Command class is not known to the current class

import BytePumper;


and for the above you have to specify the BytePumper class' package name before the class.

I think you are missing the package declaration in all your classes.
 
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
An import statment like this:

is not valid. You cannot import classes that are not in a package. (This used to be possible in old versions of Java, but this feature was removed).

Since your class EmailCommand is also not in a package, you can just remove the import statement. Make sure that class BytePumper is in the same directory as class EmailCommand.

It is recommended, however, to always put your classes in a package.
 
Michael Sasser
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You mention to remove the import statement for the other, but I do not have import statement for EmailCommand and CommandContent. Did you want me to remove the "extends Command"

Here is the structure I am using.

c:/fis/src
Contains .java files for EmailCommand, BytePumper, Command and CommandContext

c:/fis/build/classes contain the compiled classes


BytePumper contains this package statement


EmailCommand.Java has



Here are the latest errors.


I first compiled BytePumper. The class file was created in c/fis/src so I moved it to c:/fis/build/classes.

I then attempted to compile EmailCommand.



 
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

Michael Sasser wrote:You mention to remove the import statement for the other, but I do not have import statement for EmailCommand and CommandContent. Did you want me to remove the "extends Command"


Remove the line:

from the file EmailCommand.java.

You cannot (and you don't need to) import classes that are not in a package, such as the class BytePumper.

*edit* If BytePumper is in the package build.classes, then yes, you need to import build.classes.BytePumper. This is a really strange package name, though. It looks as if you added that package name there just because the file is in the directory build/classes.

Package names normally reflect the organizational structure of your program, and they often start with a kind of reversed URL. For example, if you work for Oracle, you would start your package with com.oracle.

See this tutorial to learn more about packages: Creating and Using Packages
 
Michael Sasser
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper thanks for your response and the the Tutorial. I have been reading quite a few things to try to understand all this.


I removed the statement remove


I still have three errors, any suggestions on these?

 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Michael - Try making a folder named com inside your src folder. Now copy all the java classes you have into the com folder. Add the package declaration as below in ALL of the java classes and try compiling again.

package com;

 
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
Java has to know where to look for each class that you are using in your code. The Java compiler and runtime environment use the classpath to know where to look for classes. The classpath is a set of directories and JAR files that Java will search for classes.

You need to add the directory that contains your class files to the classpath. If the classes are in a package, then your class files must be in a directory structure that matches the package structure, and the base directory of the package must be in the classpath.

For example, if you have a class in a package com.mycompany.xyz, then you must put that class in a directory such as C:\MyProject\classes\com\mycompany\xyz, and you must add C:\MyProject\classes (the base directory of the package) to the classpath.

You can add things to the classpath by using the -cp or -classpath option when compiling and running your code, for example:

javac -cp C:\MyProject\classes HelloWorld.java

or by setting the CLASSPATH environment variable (but I recommend using the command line options instead of this).
 
John Jai
Rancher
Posts: 1776
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper - nice explanation
 
Michael Sasser
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jesper and John,

Thanks for your explantions and help. I was able to compile the EmailCommand, the BytePumper and a few others.

The changes were
removal of the import of BytePumper in EmailCommand
moved the BytePumper.java to /fis/src - where all the other sources files are
Added a class statements for where all the class files are located (/fis/build/classes) as well as the -d option to designate where the class files should be written to.

Not on to the next step to change the EmailCommand from using TLS as that will not work to SSL with login authentication.

Thanks Again

Michael
 
Can you shoot lasers out of your eyes? Don't look at this tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic