facebook

ClassNotFoundException / junit test

  1. MyEclipse IDE
  2.  > 
  3. Maven for MyEclipse (Maven4MyEclipse)
Viewing 8 posts - 1 through 8 (of 8 total)
  • Author
    Posts
  • #293842 Reply

    Will Glass-Husain
    Participant

    Hi,

    I’m getting ClassNotFoundExceptions when I run my Junit test from the IDE. I’ve read the sticky issue on this, it recommends to check the output directory is in the standard target location.

    However, this is a Web project, and the output directory is webapps/WEB-INF/classes. Any advice on resolving this problem? I’m guessing the junit test from within the IDE is not finding this location.

    One idea I had is to remove the Maven capability from this project– how can I do this?

    #293849 Reply

    cherngje
    Member

    It’s sad to say that MyEclipse’s maven feature and web project doesn’t play nice with each other (due to how MyEclipse and maven each use different ways to package and deploy). In our environment, we just use maven to do package and deploy (instead of using MyEclipse’s deploy feature). By doing this, we can modify the output folders of source folders to target/classes instead of WEB-INF/classes. That way, you can do anything you want with your web project under the IDE beside using MyEclipse to deploy.

    #294006 Reply

    allenparslow
    Member

    Which version of MyEclipse are you running and is your test class in src/test/java?

    #294468 Reply

    lynchdp
    Member

    @cherngje wrote:

    It’s sad to say that MyEclipse’s maven feature and web project doesn’t play nice with each other (due to how MyEclipse and maven each use different ways to package and deploy). In our environment, we just use maven to do package and deploy (instead of using MyEclipse’s deploy feature). By doing this, we can modify the output folders of source folders to target/classes instead of WEB-INF/classes. That way, you can do anything you want with your web project under the IDE beside using MyEclipse to deploy.

    Why is this still a problem in a GA release?

    If the Maven2 integration with MyEclipse cannot handle something so basic as the ability to run Unit Tests, it is certainly not production ready and should only be available as a beta or trial product.

    I’ve been fighting this problem for two days now and have basically reached the end of my patience.

    Where can I modify the configuration of my workspace so that I can prevent Maven and MyEclipse from stepping on each other when resolving something so simple as the CLASSPATH?

    If the answer is “nowhere” I’m ready to recommend to my team (and every other Java developer I know) that we abandon this product (so called) completely.

    #294478 Reply

    allenparslow
    Member

    Is it possible for anyone to post a pom.xml or steps to reproduce this problem? I only observed this problem in the milestone releases of MyEclipse 7 (but not the GA).

    Also note when applying the sticky’s workaround for MyEclipse 7M2, it is implied that you have a src/test/java folder and you are only redirecting that folder to target/test-classes (and leaving src/main/java pointed to src/main/webapp/WEB-INF/classes). On a side note there is a second reason why maven encourages the src/test/java folder: it is not packaged into a war when executing the mvn install command, which keeps your production artifacts free of testing clutter.

    #294490 Reply

    lynchdp
    Member

    This happened after specifying the output folder for my test source tree as “target/test-classes” and doing the same for my test resources tree.

    There seems to be a problem with the Maven JDK setting. Even though I have specified a JDK external to MyEclipse, I see the following in the MyEclipse maven console when I select, “Project->Clean…”

    2/6/09 7:38:16 AM MST: [ERROR] COMPILATION ERROR :
    2/6/09 7:38:16 AM MST: [INFO] ————————————————————-
    2/6/09 7:38:16 AM MST: [ERROR] Unable to locate the Javac Compiler in:
    C:\Program Files\Genuitec\Common\binary\com.sun.java.jre.win32.x86_1.5.0.011\..\lib\tools.jar
    Please ensure you are using JDK 1.4 or above and
    not a JRE (the com.sun.tools.javac.Main class is required).
    In most cases you can change the location of your Java
    installation by setting the JAVA_HOME environment variable.

    Yet, the test classes are still being compiled to the target/test-classes folder.

    And I am able to run the Unit Test.

    #294542 Reply

    allenparslow
    Member

    Oh, that is not a ClassNotFoundException.

    You need to change a value in the myeclipse.ini file (MyEclilpse 7.0GA):

    -vm
    <<location of a java 1.5 jdk>>

    note the -vm line needs to be on a separate line from the jdk path.

    #294543 Reply

    lynchdp
    Member

    Oh, that is not a ClassNotFoundException.

    Clearly understood — although MyEclipse should honor the preferences setting for the Maven JDK. I shouldn’t have to change the JVM for all of MyEclipse.

    This error gets in the way of completing any exercise which attempts to remedy the original problem: ClassNotFoundException .

    After many trials (and many errors) I seem to have reached a workable solution, although I am thoroughly dissaponted with the poorly envisioned, weakly implemented Maven/MyEclipse integration.

    As long as a person is very careful to configure the IDE source and output folders exactly the same as the corresponding Maven configuration, it seems to work. At least until you run a Maven Clean on the POM, which should probably trigger a Project Build in the IDE but apparently doesn’t.

    I don’t understand why the source and output folders for the IDE can’t be determined from the POM file, similar to the way the IDE interprets the maven dependencies and sets up the project classpath appropriately. Changing one should update the other (IMHO).

Viewing 8 posts - 1 through 8 (of 8 total)
Reply To: ClassNotFoundException / junit test

You must be logged in to post in the forum log in