Question

Package does not exist error even if the package is connect for the run time compilation. Here is the code.

JavaSourceCompiler javaSourceCompiler = new JavaSourceCompilerImpl();
                JavaSourceCompiler.CompilationUnit compilationUnit = javaSourceCompiler.createCompilationUnit();
                compilationUnit.addClassPathEntry("G:/project/eclispe/www.spade.com/src/com/ibm/database/DbConnection.java");
                compilationUnit.addJavaSource(myClass, sourcecode);
                compilationUnit.addClassPathEntry("/src/com/ibm/database/DbConnection.java");
                System.out.println(compilationUnit.getClassPathsEntries());
                ClassLoader classLoader = javaSourceCompiler.compile(compilationUnit);

                Class<?> FMClass = classLoader.loadClass(myClass);

                Object FMObj= FMClass.newInstance();

                Method forecast = FMClass.getMethod("Forecast",new Class[] {String.class,String.class,String.class,int[].class});
                System.out.println("Forecast method return type is:"+forecast.getReturnType());
                f=(Integer)forecast.invoke(FMObj, new Object[] {partcode,sercid,fm,a});

The code which is running at runtime need to import the package com.ibm.database . the error found is:

java.lang.IllegalStateException: string:///CumulativeBean.java:5: package com.ibm.database does not exist


import com.ibm.database.DbConnection;

publistring:///CumulativeBean.java:17: cannot find symbol
symbol  : variable DbConnection
location: class CumulativeBean
ction con=DbConnection.getMyConnstring:///CumulativeBean.java:26: cannot find symbol
symbol  : variable DbConnection
location: class CumulativeBean
tion con1=DbConnection.getMyConnstring:///CumulativeBean.java:35: cannot find symbol
symbol  : variable DbConnection
location: class CumulativeBean
tion con2=DbConnection.getMyConnstring:///CumulativeBean.java:44: cannot find symbol
symbol  : variable DbConnection
location: class CumulativeBean
tion con3=DbConnection.getMyConnstring:///CumulativeBean.java:55: cannot find symbol
symbol  : variable DbConnection
location: class CumulativeBean
tion con4=DbConnection.getMyConn
at     org.abstractmeta.toolbox.compilation.compiler.impl.JavaSourceCompilerImpl.compile(JavaSourceCompilerImpl.java:102)
at org.abstractmeta.toolbox.compilation.compiler.impl.JavaSourceCompilerImpl.compile(JavaSourceCompilerImpl.java:78)
at org.abstractmeta.toolbox.compilation.compiler.impl.JavaSourceCompilerImpl.compile(JavaSourceCompilerImpl.java:72)
at com.ibm.bean.ForecastingBean.Forecast(ForecastingBean.java:124)
at com.ibm.controller.ControllerServlet.doPost(ControllerServlet.java:73)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:710)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:230)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:175)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:128)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:104)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:261)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:844)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:581)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
at java.lang.Thread.run(Thread.java:619)

Thanks in advance

Was it helpful?

Solution

It seems problem with the way your are adding class path entries:

replace:

 compilationUnit.addClassPathEntry("G:/project/eclispe/www.spade.com/src/com/ibm/database/DbConnection.java");

with

compilationUnit.addClassPathEntry("G:/project/eclipse/www.spade.com/src/");

And remove the other entry as you are trying to add same class.Hope this helps.

OTHER TIPS

It pretty long shot but I see a probable typo in the compilationUnit.addClassPathEntry. You have there eclispe and it probably should be eclipse.

But as I said this is long shot, maybe there's another problem . But worth trying :)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top