spring: package does not exist - java

I am a beginner of Java and Spring framework. I've test a simple controller which use spring annotation.
I am doing this using notepad and I have already set jar files to classpath ( jar files: http://i.stack.imgur.com/oFjSW.jpg )
But when i tried to compile the programs i have get the error ( detail: http://i.stack.imgur.com/PFvxG.jpg ) like
error: package org.springframework.stereotype does not exist
error: package org.springframework.ui does not exist
error: package org.springframework.web.bind.annotation does not
exist
How can i fix this problem?
Thanks~

Try to compile likes this,
javac -cp .;your_library_path/spring-aop-4.0.jar;your_library_path/spring-aspects-4.0.jar controller.java
You need to declare all of your external libraries separate with ;but personally I recommend you should try to use some java IDEs likes eclipse, netbeans,etc.

Related

Javac complains that can not see jre library classes during compilation

I am trying to compile java classes using javac. The project uses ByteInputStream class that is located in java_version/jre/lib/rt.jar file(in package com.sun.xml.internal.messaging.saaj.util). javac compilter complains that can't find that class. I tried to include all library classes on during compilation(lib1:lib2:lib3:etc) but still no result.
Here is error message:
package com.sun.xml.internal.messaging.saaj.util does not exist
cannot find symbol : class ByteInputStream
Any ideas?

Compilation with javac fails, with eclipse-compiler it works

I'm trying to write a simple ant build to compile a project.
The project is in eclipse and there it compiles successfully (with the eclipse-compiler).
But with ant (using javac) it appears an error and i don't know how to resolve it.
Structure of the used jar:
com
xxx
a <= package
b
a.class
Codeblock of my class:
Object o = com.xxx.a.b.method();
^
The exception of ant is:
error: cannot find symbol
symbol: variable b
location: class a
I think eclipse uses the package first to try to compile the code. javac seems to think that a is the class.
Is there a way to resolve the problem without changing the jar?
It looks like either package name is different or you have multiple class files of the same name. I would suggest checking the import statements and adding the specific jar file to classpath while compiling using javac or ant command.
To find the exact jar file, use ctrl+T then paste your class name in the box and it will tell you the jar file. Add that jar file to your ant classpath and build.
I didn't find anything in the Java Language Specification that this is an error, so it might be a javac bug.
Since it is a javac vs. Eclipse compiler thing, try one of the following:
Use the Eclipse compiler in the Ant script
If it is a javac bug, the bug may be fixed in a newer (update) JDK version
If your code does not directly reference class com.xxx.a, compile the code with the JAR in which the class com.xxx.a was removed

Unable to run hadoop aplication due to NoClassDefFoundError

I am new in Hadoop and I have been following some tutorials like this. I have found a nice set of mapreduce examples in here. I was able to run wordcount example but I am not able to run the EnhancedTopN example. It gives me the error: Exception in thread "main" java.lang.NoClassDefFoundError: EnhancedTopN (wrong name: samples/topn_enhanced/EnhancedTopN). I have correctly compiled the java file, although it gives me a note saying "Note: EnhancedTopN.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.". What could be wrong?
Thanks
NoClassDefFoundError with the message "wrong name" means that the package structure of your class is wrong, or that you are running it the wrong way. This has nothing to do with Hadoop, just with the way packages work in Java.
Is your class EnhancedTopN in a package named samples.topn_enhanced; do you have the following package statement at the top of the source file?
package samples.topn_enhanced;
public class EnhancedTopN {
// ...
}
The directory structure of your project must match the package structure, so the source file EnhancedTopN.java should be in a directory samples\topn_enhanced, and you must compile and run it from the base directory of the package structure:
C:\Project> javac samples\topn_enhanced\EnhancedTopN.java
C:\Project> java samples.topn_enhanced.EnhancedTopN
Going into the directory and using java EnhancedTopN will not work and will give you the error that you are asking about:
C:\Project\samples\topn_enhanced> java EnhancedTopN -- error!
See: Lesson: Packages in Oracle's Java Tutorials.

Java Package Compiling Issue

OK, like many of the package compiling issues out there I have not found one like this out of the 12 hours I've spent searching..
Basically I have the normal setup :
My Directories are as follows: JavaCSVReader/FRC_API
My Source files are setup as this:
JavaCSVReader/CSVFile.java
JavaCSVReader/FRC_API/RobotConfig.java
(that is CSVFile.java is located in JavaCSVReader and same for RobotConfig.java)
CSVFile.java contains the lines:
package JavaCSVReader;
import JavaCSVReader.FRC_API.*;
...
RobotConfig.java contains the lines:
package JavaCSVReader.FRC_API;
import JavaCSVReader.CSVFile;
...
Both files compile fine without the lines above.
The error is thus: I receive
"cannot find symbol... class: CSVFile location: JavaCSVReader"
when I try to compile the RobotConfig.java.
I also receive the
"package does not exist: JavaCSVReader.FRC_API" error when compiling CSVSFile.java
my
CLASSPATH=/home/src/JavaCSVReader/:.:..
(I am using linux)
Your classpath setting is wrong. You should set it to
/home/src/
The compiler will take classpath as the "base" directory in order to find packages defined in the source.
it's a classpath issue.
How do you configure java environment variables?
You'd better check on it.
is your package JavaCSVReader.FRC_API; or JavaCSVReader ?

error package org.python.util does not exist, compilation with ant

I am trying to call a python method in java, similar functionality as Unresolved import org.python / working with jython and java?
However, I am using ant to compile and run my files. using import org.python.util will give me this error
package org.python.util does not exist
I can see that python.org.util exists in jython-2.5.0.jar.
So, here is the class path I have in my build.xml ant file:
classpath="${java.class.path}:./jgrapht/lib/jgrapht-jdk1.5.jar:\
./jgrapht/lib/jgraph.jar:./jgraphx/lib/jgraphx.jar:\
./jython/lib/jython-2.5.0.jar:./colt/lib/colt.jar:."
and I also I added the path to jython jar files to my class path. i.e. looks like echo $path gives me all the required paths. Is there anything missing here that I am not aware of?
Try this to make all classes in the package available:
import org.python.util.*;
Or this to include a particular class:
import org.python.util.TemplateAntTask;
EDIT: Also, looks like there is an extra slash after jython-2.5.0.jar in your classpath.

Categories

Resources