1

i'm trying to export a Runnable Jar in order to run my project with .bat file, however when trying to export a Runnable jar it fails with massage:

"Jar creation failed. See details for additional information." < < Details : No resources selected. See details for additional information. Could not find main method from given launch configuration.

Using Windows Server 2012, newest eclipse, jdk and jre. cleaning didn't change anything, nor copying the project to a new one.

Downgrading to 1.8 didn't help as well, I looked at some suggestions for the last couple of hours, none helped.

Of-curse I have static void main(String[] args) in my Runner.java class, and if you click "Run" (with same Run Configuration) from Eclipse it works perfect.

Couldn't find a solution as of now.

6/12 - Update: Adding screenshots of the export process as howlger asked.

I've also tried new workspace according to Akshay Bahadur's suggestion, same result.

https://s3.amazonaws.com/stackover/Screenshot_141.png

https://s3.amazonaws.com/stackover/Screenshot_142.png

https://s3.amazonaws.com/stackover/Screenshot_143.png

6/12 - 2nd Update: Adding Run Configuration: https://s3.amazonaws.com/stackover/Screenshot_149.png

7/12 - 3nd Update: Adding About Eclipse:

Eclipse IDE for Java Developers Version: Oxygen.1a Release (4.7.1a) Build id: 20171005-1200 OS: Windows Server 2012 R2, v.6.3, x86_64 / win32

https://s3.amazonaws.com/stackover/Screenshot_155.png

and the main() function is plain Java - no Maven or Gradle:

public static void main(String[] args) {
    boolean errorNotHappened = true;
    boolean errorWithMailNotHappened = true;
    boolean performDownload = true;
    boolean performEmailSent = true;
    boolean performDataManipulation = true;

    System.out.println("***~~~*** Starting job. If you want more details - turn on debug mode");

    //Downloader d = new Downloader();
    printMsg("Date to use with files: "+getDateToUse());
    printMsg("Write mail for date: "+getYasterdayNiceDate());

    if (performDownload) 
    {
        Downloader d = new Downloader();
        d.connectAnd(); //connect to pair server
        errorNotHappened = d.downloadFiles();
        d.disconnectFromServer();
    }

    if (errorNotHappened && performDataManipulation) 
    {
        Manipulator m = new Manipulator();
        errorNotHappened = m.work();
        m.terminateManipulator();
    }


    if (performEmailSent) 
    {
        GoogleMailer gmail = new GoogleMailer();
        gmail.startMailingService();
        if (errorNotHappened)
            errorWithMailNotHappened = gmail.sendMailWithAttach();
        else
            gmail.sendFailedMail();
        if(!errorWithMailNotHappened)
        {
            gmail.sendFailedMail();
        }
    }
    System.out.println("***~~~*** Job ended.");

}
Tipxbomb
  • 81
  • 2
  • 9
  • What settings do you have in the Export JAR dialog? – howlger Dec 05 '17 at 12:30
  • I tried all three of them: 1.Extract required libraries into generated JAR. 2. Package required libraries into generated JAR. 3. Copy required libraries into a sub-folder next to the generated JAR. All options lead to the same Error. The Launch configuration is the same that I use to run from eclipse, I tried making a new project with a new run configuration, It didn't help. – Tipxbomb Dec 05 '17 at 12:35
  • If you used _File > Export: Java > JAR file_, add screenshots of at least the first and third dialog page to your question. Otherwise, tell how did you export the JAR? – howlger Dec 05 '17 at 12:44
  • I've added the screenshots, I Used Java > Runnable JAR file – Tipxbomb Dec 05 '17 at 23:34
  • Thx, I see. Is the type of the launch configuration `Runner - reportbb` _Java Application_? What does the classpath of the launch configuration look like? Is it a plain Java or Maven or Gradle or ... project? – howlger Dec 06 '17 at 07:03
  • It is Java Application, its plain Java - no Maven or Gradle, I've added screenshot of the launch config. – Tipxbomb Dec 06 '17 at 11:47
  • I tried to reproduce the problem with the Eclipse IDE for Java Developers, Version: Oxygen.1a Release (4.7.1a), but it worked as expected without any errors. Which Eclipse package and which version do you exactly use (see _Help > About Eclipse_)? – howlger Dec 06 '17 at 12:38
  • That's weird... I tried duplicating to server to another instance... it didn't help as well. Eclipse information: Eclipse IDE for Java Developers Version: Oxygen.1a Release (4.7.1a) Build id: 20171005-1200 OS: Windows Server 2012 R2, v.6.3, x86_64 / win32 I have also updated my main post with that information. – Tipxbomb Dec 07 '17 at 14:15

3 Answers3

0

I fixed the problem, I exported the project as an archive file. Then I opened up a new workspace and imported the the archived project. After that I tried to export the project as a runnable jar, after two tries the jar runs as is it should.

I still don't know what the exact cause was but I hope someone how has run into the same problem finds this helpful.

See

Eclipse cannot create runnable jar - No resources selected

Akshay Bahadur
  • 497
  • 4
  • 11
0

I managed to get the job working by exporting the project to regular Jar file (not Runnable as I originally tried) and activating from CMD with the following:

java -cp "C:\Users\Administrator\Desktop\runDebug\rundebug.jar";"C:\Users\Administrator\Desktop\runDebug\activation.jar";"C:\Users\Administrator\Desktop\runDebug\commons-net-3.1.jar";"C:\Users\Administrator\Desktop\runDebug\mail.jar" pairbb.Runner

I've wrote this command to a BAT file, and set this BAT file as a windows scheduled task. So right now I get what I need this way, I still however couldn't export it as a Runnable Jar.

Tipxbomb
  • 81
  • 2
  • 9
0

My case might not completely apply to yours, but considering that this question is the first one that popped up when I was still trying to fix my issue, I'll share my experience:

If you encountered a similar issue while coding with a Java 10 JDK, this might be of use.

I had a plain Java project I developed in Eclipse (Windows Version: Oxygen.3a Release (4.7.3a)) that didn't let me export it as a runnable JAR with the error message of 'No resource selected' for the run configuration (saying that there isn't a public static void main(String[] args) in the selected entrypoint). I had the latest JDK (Java 10) on my machine, but I was coding for Java 8 (as you can set the compatibility in Eclipse's settings).

As I had been seeing some issues relating to Java 9 while sifting through posts, I ultimately decided to actually download the 'older Java' version (aka. Java 8). So, what I did was:
1. Simply download the Java 8 JDK
2. Update my JAVA_HOME variable to point to the newly-installed version, rather than to Java 10
3. Remove Java 10 from Installed JREs & add Java 8 in its stead

Once I did these steps, I ran my code and then had some issues with regexes at runtime (I was using unbounded look-behinds which Java doesn't like, but which seem to be allowed as of Java 10, I assume), changed them to be bounded & ran it without issues.

Then the export finally worked again. Please note that the Java version (from the Java 10 JDK) was set in: Project > Properties > Java Build Path > Libraries (Tab) > JRE System Library (Entry)

For the Java Compiler, I had set the tickbox for 'Use compliance from execution environment' to Java 1.8 as well.

So I'm a bit confused on how compatibility mode didn't seem to work as an actual Java 8 version. Only explanation I can currently come up with is that either I forgot to switch the version in one more spot in the settings or that the export possibly relies on some plugin I possibly got during installation that isn't supported for Java 10 (Note: this is a 'fresh' installation of eclipse that I did about a month ago & I haven't installed any plugins additionally to what I might have selected during the initial installation). The last possibility does not explain why I was able to export another project (also Java 8) a few days prior though.

TL;DR Getting Java 8 JDK fixed it for me.

K__
  • 1
  • 1