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?
Related
So I was following this tutorial:
https://spring.io/guides/gs/maven/
I cloned their repositories for the software for fear of mistyping something.
The code does not work when I compile Greeter.java using javac and then use java to run HelloWorld.java file It gives me the following error:
HelloWorld.java:5: error: cannot find symbol
Greeter greeter = new Greeter();
^
symbol: class Greeter
location: class HelloWorld
HelloWorld.java:5: error: cannot find symbol
Greeter greeter = new Greeter();
^
symbol: class Greeter
location: class HelloWorld
2 errors
I tried explicitly importing Greeter into HelloWorld using
ìmport hello.Greeter
The code works fine when I run it without the package hello;statements.
Any idea why I am getting this error??
So I followed through with the tutorial and using mvn package command and the jar file generated the project works.
So is this issue with trying to compile it with java command in the command line.
Adding directory structure of the project
pom.xml src target
./src:
main
./src/main:
java
./src/main/java:
hello
./src/main/java/hello:
Greeter.java HelloWorld.java
I assume you try to compile the sources while you're in the directory src/test/java/hello. That's the wrong directory, you have to do it from directory src/test/java and pass the directory (i.e. package) to the compiler, e.g.
javac hello/*.java
Another reason might be that you haven't compiled Greeter.java, so the compiler doesn't find the class-file while compiling Hello.java. Above command should solve that.
If you have a main method in hello run
java hello/name-of-file.java
to run your main method.
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
I'm new in Android SDK. I'm using Emacs as IDE (I know about Android Studio). I created a project and I compiled it from a script named gradlew (It was created automatically when the project was created). APK is created successfully. Now, I'm trying to implement (with FlyMake) syntax error checker. The command used to do this is the following:
javac "main.java"
where main.java is the main of the application (there is only one file).
Obviously, javac doesn't know where is the SDK (API level 20). So I tell it as follow:
javac -sourcepath "~/opt/android/sources/android-20" "main.java"
but it throws a lot of errors like "class not found". For example:
/home/carlos/opt/android/sources/android-20/android/app/Activity.java:29: error: cannot find symbol
import android.content.IIntentSender;
^
symbol: class IIntentSender
location: package android.content
When I see the content of android/content, there is not a .java named IIntentSender
So, what's happening? Thanks for reading and answering!
This question was answered by CommonsWare:
The last time I used javac by hand, I used -classpath, not -sourcepath. The appropriate JAR for -classpath would be ~/opt/android/platforms/android-20/android.jar, assuming that ~/opt/android/ is where your Android SDK is installed. IIntentSender is generated Java source code (from AIDL) and will not be in Java form in the SDK sources directory. So, if FlyMake requires -sourcepath, I expect that you're going to be in a world of hurt.
Thanks!
I downloaded/installed protocol buffers 3.1.0 and used protoc to compile a .proto file which generated a .java class for me.
With this change, everything works/compiles.
Then I replaced the avro jars with their latest versions and tried to compile my project again, but no luck, it's complaining this error:
# Compile: pregen/media.proto
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:828: error: cannot find symbol
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
^
symbol: class OneofDescriptor
location: class Descriptors
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:2669: error: cannot find symbol
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
^
symbol: class OneofDescriptor
location: class Descriptors
pregen/media.proto/serializers/protobuf/media/MediaContentHolder.java:4131: error: cannot find symbol
com.google.protobuf.Descriptors.OneofDescriptor oneof) {
^
symbol: class OneofDescriptor
location: class Descriptors
3 errors
I did a lot search/research and still no luck, also looked at this most relevant post: Problems using protobufs with java and scala
and then I compiled my generated .java file along with protobuf.3.1.0.jar into a new jar and placed it under my lib/, but the project still cannot compile.
Any help on how to resolve this issue please?
(I'm using an open-source project to benchmark Java serialzation performance, and I've posted a more detailed question/issue there as well.)
One of the authors of that open source projects helped me resolve the issue, copy the solution here as well:
"The problem was that avro-tools-1.8.1.jar bundles some of the Protobuf
class files (ugh). The bundled class files aren't compatible with the ones
our generated Protobuf code relies on.
We're pretty fast and loose with what's on the classpath; we just include
"lib/*.jar". It would be nice to be more precise with dependencies at some
point.
But as a quick fix, I put avro-tools-1.8.1.jar in "lib/extra/", so it won't
get picked up by default. The Makefile now specifically references that
JAR only when we need to run the Avro code generator."
Thanks.
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.