javac can't find classes in .jar even though they are present? - java

I'm including a rather large JAR file during compilation that I'm generating using Altova MapForce. The JAR file was around 65MB and compilation was working fine. I needed to add a bunch more mappings, so I did, regenerated my JAR, and tried building again. The JAR is now around 80MB.
Now I get all kinds of "cannot find symbol" error messages even though I've opened the JAR to verify that the symbols are there! Am I hitting some upper limit on JAR sizes? There are over 75,000 classes inside the JAR file.
What's weird is that Eclipse auto-completion works just fine with the new JAR; I only get these errors when building.
I'm using Ant if that makes any difference.
Thanks,
Brian
EDIT: Something else strange: I turned on the verbose output from javac. It seems that I start getting compile errors even before all of the classes are loaded:
[javac] [loading com\mycompany\myproject\*************************.class)]
[javac] [loading com\mycompany\myproject\*************************.class)]
[javac] [loading com\mycompany\myproject\*************************.class)]
[javac] [loading com\mycompany\myproject\*************************.class)]
[javac] [loading com\mycompany\myproject\*************************.class)]
[javac] C:\Users\*************************.java:38: cannot find symbol
[javac] symbol : class *************************
[javac] location: package com.mycompany.myproject.*************************
[javac] import com.mycompany.myproject.*************************;
[javac] ^
[javac] [loading com\altova\TraceProvider.class(com\altova:TraceProvider.class)]
[javac] [loading com\altova\io\StringInput.class(com\altova\io:StringInput.class)]
[javac] [loading com\altova\io\StringOutput.class(com\altova\io:StringOutput.class)]

It would be helpful to see the specific compiler errors you're getting, your classpath, etc. If it works from eclipse and not in ant, it's likely to be a classpath issue, i.e. your ant script is not setting the same classpath as your project settings in eclipse has.
I work on one project that has a jar file larger than 80MB no problem, and I don't think there's an upper limit on number of classes in a jar file or anything like that. the size of the jar and the number of classes it contains is unlikely to be your problem.
you can try writing a simple test main program that just imports the classes in question, and compile that with javac with only that jar on your classpath. if that test doesn't work, you know you've got a problem with the jar you're using. if it doesn't work, is has got to be either an ant issue or similar.
can you post your ant build target, and the verbose output of ant?

Well, I've solved the problem. All I did was regenerate my JAR (I didn't change anything!) and it worked. Seems like it was just a fluke.
Sorry to waste everyone's time!

I had exactly this problem, when building via Ant on Jenkins.
The class which is not found is shown loading after the error: "Cannot find symbol" shows up in the verbose output. Tried rebuilding numerous times, no joy.
Finally, I went to the class importing the class not found, and changed the order of imports so the problem class was nearer the top. This is a temporary fix, as soon as someone organizes the imports in Eclipse, they will be sorted in an order that Javac will fail to load. We may have to rename the class, so it sorts to the top of the imports.
After some more research, I found this is related to bug 7101822 in Java, where eager loading of the classes can result in "Cannot find symbol" error.
http://bugs.java.com/bugdatabase/view_bug.do?bug_id=7101822

Related

Vim Syntastic produces "package org.junit does not exist" error when saving java file

so I have a problem using vim with Syntastic for java. I spent hours looking for a solution but none of the dozens of questions seem to solve my problem.
I have some java files and a lib/ folder containing (among other files) a junit.jar file. I'm using ant to compile the java files and I'm using ant test for testing. Everything works.
But every time I save my test class file in vim, it gives me these errors in Location List (some kind of error list):
ClassTest|5 col 17 error| package org.junit does not exist
ClassTest |6 col 17 error| package org.junit does not exist
ClassTest |17 col 4 error| cannot find symbol (The #Test thing)
As I said, it's still working, the only problem is that vim/Syntastic can't find the junit.jar file, I guess. I just want these errors to go away :D
Any ideas?
Thanks

Project compiles with Ant. But if I open eclipse, the project no longer compiles

I'm on Windows.
I downloaded the source to a java project (Plovr) and I can build it with ant using cygwin.
But just opening it in Eclipse means it will never build again. If I open it in Eclipse and then close it again, it will no longer build. I also can't add files that were written in Eclipse.
Output:
javacc:
compile:
[javac] Compiling 7 source files to C:\Users\Bryana\plovr\pulled\plovr-master\build\classes
[javac] C:\Users\Bryana\plovr\pulled\plovr-master\closure\closure-stylesheets\build\genfiles\java\com\google\common\css\compiler\ast\GssParserCC.java:345: error: cannot access Type
[javac] public CssBooleanExpressionNode buildBoolExpressionNode(CssBooleanExpressionNode.Type type,
[javac] ^
[javac] bad class file: C:\Users\Bryana\plovr\pulled\plovr-master\build\classes\com\google\common\css\compiler\ast\CssBooleanExpressionNode$Type.class
[javac] bad signature: ▒3i
[javac] Please remove or make sure it appears in the correct subdirectory of the classpath.
BUILD FAILED
Using: jdk1.7.0_40 , Apache Ant(TM) version 1.9.2 , Eclipse Juno Service Release 2
Found this: http://suneelgv.wordpress.com/2011/02/17/java-lang-classformaterror-invalid-constant-pool-index-63-bad-class-file/ referring to that http://mail-archives.apache.org/mod_mbox/cayenne-user/200804.mbox/%3C0JZC008038T159#mail.uni-rostock.de%3E.
In your case the filterset or similar on-the-fly modification during copying - accidentally including class files - might not do any harm with Unix but convert line endings on Windows.

Java code not compiling with 'javac' but compiles in Eclipse

I have just written a Java multi-threaded program in Eclipse. It compiled fine and works like a charm.
However, as this is coursework we are required to ensure that it compiles in the command line using 'javac' otherwise we score ZERO!
So, some classes compile others don't. The error I'm getting is the following ( they are all similar just with different class names, this is one example)
GateRunnable.java:7: cannot find symbol
symbol : class Station
location: class package.name.here.GateRunnable
public GateRunnable(Station st) {
^
Is this a javac issue? Any help appreciated.
Your compile -classpath and/or -sourcepath is incomplete. The compiler doesn't know where to find class Station. Here is a related question that describes how to set the classpath to include all the classes you want.
To solve the problem I was having, it was simply necessary to compile all classes by using the following command:
javac *.java
which compiles all java files in the directory.
have you compiled every .java file in your folder/packages? if not, then do so. Eclipse usually does that for you, but within the terminal it's you taking the responsibility of compiling every part of the code.

Lucene: Cannot find symbol

I am using Lucene 3.4.0, hibernate (hibernate-all.jar), ANT and TestNG to run some test...
Most of all works right now, but since I have implemented my lucene part nothing seems to work when I use ant command... I'm kind of lost here.
Because everything works perfectly locally. I can run my test, compile, etc. As soons as, I try to build with ant, I get this error "cannot find symbol" for contructor StandartAnalyzer(version.), etc...
But like I said, everything works on eclipse... At first, I had an method not found error, but fixed it because hibernate is not compatible with the latest version of lucene. So I upgraded hibernate... but now, I get this.
Thank you. If you need more information plz ask.
$ ant explode
Buildfile: c:\DuplicateBugFinder\dbf\build.xml
init:
groovy.compile:
groovy.copy:
compile:
[javac] c:\DuplicateBugFinder\dbf\build.xml:156: warning: 'includeantruntime' was not set, defaulting to build.sysclasspath=l
st; set to false for repeatable builds
[javac] Compiling 27 source files to c:\DuplicateBugFinder\dbf\exploded-archives\dbf.ear\dbf_jar
[javac] c:\DuplicateBugFinder\dbf\src\hot\com\rim\sts\dbf\business\service\classification\LuceneClassificationAlgorithm.java:
6: cannot find symbol
[javac] symbol : constructor StandardAnalyzer(org.apache.lucene.util.Version)
[javac] location: class org.apache.lucene.analysis.standard.StandardAnalyzer
[javac] Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_34);
[javac] ^
[javac] c:\DuplicateBugFinder\dbf\src\hot\com\rim\sts\dbf\business\service\classification\LuceneClassificationAlgorithm.java:
2: cannot find symbol
[javac] symbol : constructor QueryParser(org.apache.lucene.util.Version,java.lang.String,org.apache.lucene.analysis.Analyzer
[javac] location: class org.apache.lucene.queryParser.QueryParser
[javac] new QueryParser(Version.LUCENE_34, "title", analyzer)
[javac] ^
[javac] c:\DuplicateBugFinder\dbf\src\hot\com\rim\sts\dbf\business\service\classification\LuceneClassificationAlgorithm.java:
9: cannot find symbol
[javac] symbol : constructor IndexSearcher(org.apache.lucene.store.Directory,boolean)
[javac] location: class org.apache.lucene.search.IndexSearcher
[javac] searcher = new IndexSearcher(index, true);
[javac] ^
[javac] c:\DuplicateBugFinder\dbf\src\hot\com\rim\sts\dbf\business\service\classification\LuceneClassificationAlgorithm.java:
00: cannot find symbol
[javac] symbol : method search(org.apache.lucene.search.Query,org.apache.lucene.search.TopScoreDocCollector)
[javac] location: class org.apache.lucene.search.IndexSearcher
[javac] searcher.search(q, collector);
[javac] ^
[javac] 4 errors
BUILD FAILED
c:\DuplicateBugFinder\dbf\build.xml:156: Compile failed; see the compiler error output for details.
It's probablly a difference in the classpathes used by Eclipse and by Ant respectively. Check what jars are you exactly using inside Eclipse (what libraries are added to the project) and then what jars you use in your declared Ant classpath when you build with that. Also check that you're using the same JDK in Eclipse and Ant. If either of the two differ, change Ant ones to be like Eclipse (since that's the environment that does work)
Check the ant classpath for multiple versions of Lucene library. Do ant -diagnostics to check the ant environment.
Ok fixed it. I needed to add the jar file in my lib/test (I'm using seam framework). In eclipse, everything was working because I was pointing to the jar in my run configurations for TestNG. When I was running the command "ant test" no jar was found...
So thanks to everyone.
Plus, for those of you who wants to make use of lucene and seam make sure too have no version incompatibilty. I had this problem for a long time. Finally, I found out that I had to use an older version of lucene (2.4.1) to work with seam 2.2. I didn't check yet for lucene 3.4 and seam 3...

Why javac task does not creates classes

I have an ant task that contains javac task inside. It reports about error in one of the classes, but the build doesn't fail, because it has failonerror="false". I suppose to see class files in the end of build, but I don't see it. Can anybody tell me why?
Properties used:
checkout.path=work/workingcopy
classpath.path=work/build/classes
log.file=work/log.txt
Ant code:
<record name="${log.file}" action="start"/>
<javac destdir="${classpath.path}" srcdir="${checkout.path}/src"
debug="true" failonerror="false">
<classpath>
<path refid="webinf.lib"/>
<path refid="tomcat.lib"/>
</classpath>
</javac>
<record name="${log.file}" action="stop"/>
Log file:
[javac] Compiling 169 source files to C:\work\build\classes
[javac] C:\work\workingcopy\src\com\mycompany\exception\handlerException\CustomExceptionHandler.java:25: cannot find symbol
[javac] symbol : class RequestContextImpl
[javac] location: package org.primefaces.context
[javac] import org.primefaces.context.RequestContextImpl;
[javac] ^
[javac] C:\work\workingcopy\src\com\mycompany\exception\handlerException\CustomExceptionHandler.java:103: cannot find symbol
[javac] symbol : class RequestContextImpl
[javac] location: class com.mycompany.exception.handlerException.CustomExceptionHandler
[javac] new RequestContextImpl(ec);
[javac] ^
[javac] Note: Some input files use or override a deprecated API.
[javac] Note: Recompile with -Xlint:deprecation for details.
[javac] Note: Some input files use unchecked or unsafe operations.
[javac] Note: Recompile with -Xlint:unchecked for details.
[javac] 2 errors
[javac] Compile failed; see the compiler error output for details.
The failonerror option is for Ant not for javac. So if failonerror=false then Ant will continue your task even javac returns an error.
From the docs:
failonerror Indicates whether compilation errors will fail the build; defaults to true.
The build is Ant's build process not javac's !
Use Eclipse Java Compiler (EJC) instead of standard Oracle javac. One of ECJ advantages over javac is that it is permissible of errors, it tries to compile as much as possible and keeps already generated class files. With javac it is everything or nothing.
EJC was developed for use in IDE, for highly interactive work where partial compilation is a must, but it can also be used as CLI or Maven plugin. Plexus guys provide EJC as a handy Maven dependency.
For example configuration of ECJ in Maven, a partial compilation, check my answer to this question:
Maven: partial compilation before code generation
I've had same problem. And that is soluion I've found on the Web
This depends on the compiler that you are actually using. If you're using
javac 1.3, this is what Sun does by design. (see
http://java.sun.com/j2se/1.3/docs/tooldocs/tools-changes.html for more
information, specifically the last paragraph of the first bullet.)
Try using an older compiler or using the jikes compiler from IBM. Both
javac 1.2.2 and jikes 1.13 will produce output for classes that do compile,
even if another file in the fileset doesn't.
Jay
Best regards,
Michael

Categories