Arun Bv
Arun Bv

Reputation: 11

deploy java app on Heroku launch.main error

I want to deploy a java appa on HEROKU. I am new to maven. I made all set up as per in the deploy a sample app to heroku (java+maven+ tomcat7)documentation. and i made a bulid,It was successfull. But as soon i typed sh /target/bin/weapps i am getting the following error. Can anybody help me to sort out this issue.

Exception in thread "main" java.lang.NoClassDefFoundError: launch/Main  
Caused by: java.lang.ClassNotFoundException: launch.Main</br>
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:306)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:301)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:247)
 Could not find the main class: launch.Main.  Program will exit.

regards, arunbv

Upvotes: 1

Views: 2208

Answers (4)

mjw
mjw

Reputation: 914

This is probably dead, but in case it helps people of the future.

I was getting up and running with a java app on Heroku, using an Ubuntu machine for development - and got this same Exception in thread "main" java.lang.NoClassDefFoundError.

Double check that you're using the same java compiler version as your java sdk version.

type java -version & javac -version. Make sure they are the same version.

If not, you can fix this by reconfiguring your environment to use the same for both. Assuming you have downloaded and installed the java version you want to use, type :

`sudo update-alternatives --config java`

You'll get a nice menu with options

  Selection    Path                                            Priority   Status
------------------------------------------------------------
* 0            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      auto mode
  1            /usr/lib/jvm/java-6-openjdk-amd64/jre/bin/java   1061      manual mode
  2            /usr/lib/jvm/jdk1.7.0/bin/java                   1   

Select the version you wish to use. Done. Now try to build.

Upvotes: 0

taotao
taotao

Reputation: 186

Since you said you are new to maven, I think the reason of this error is that you simply put your *.java code under the root folder of the project, while you are rather expected to put it under ./src/main/java/

This should work for you. I experienced the same problem and figured this out.

Upvotes: 0

Dimitri De Franciscis
Dimitri De Franciscis

Reputation: 1032

I had a similar problem, I (well, almost) solved it this way, just remove:

<packaging>war</packaging>

from pom.xml. I know this is not an ideal solution, but somehow the embedded tomcat plugin doesn't work with war packaging!

Upvotes: 8

Naaman Newbold
Naaman Newbold

Reputation: 3334

I don't have enough points to comment, but what article are you following? Can you link it?

Based on the error, I suspect your Main.java is not in src/main/java/launch. If you follow these instructions, I think you should be able to clear up the error:
http://devcenter.heroku.com/articles/create-a-java-web-application-using-embedded-tomcat

If that's the article you're following and you're still having trouble, it may ease the problems you're having if you simply clone the sample repo:

git clone git://github.com/heroku/devcenter-embedded-tomcat.git

Upvotes: 1

Related Questions