Program runs in eclipse, but not in .jar form - eclipse

I ran it in cmd and it said no main manifest attribute in, JGame2.jar
how do i show it where the main is?? it works fine in eclipse.

For
java -jar x.jar
to work, the jar file must contain a META-INF/MANIFEST.MF file, and this file must contain an entry for the main class. You can add a manifest in Eclipse. Note that any dependencies must also be accounted for, either by:
a class path in the manifest
-cp on the command line
use of some tool to combine to one jar
Eclipse is just an IDE, you might consider learning to use an actual build tool such as Maven or Gradle or Ant to allow you to repeatably build usable results.

Related

JavaScript Executor not working when running Executable JAR file

When I run the test case in Eclipse, everything works fine, but when I make executable .jar of it, it runs until the command
js.executeScript("arguments[0].scrollIntoView(true);", element);
It returns java.lang.NullPointerException at this line of code
If there is another way to scroll element into view?
When you run from Eclipse IDE, the Run Configuration automatically adds the library you depend on (defined in your Eclipse project if not using another dependency management technology) to the classpath. So in this case, it succeeds at instantiating properly the js variable.
When not in Eclipse IDE, you have to specify the classpath to the command line in order to include dependencies. Otherwise, the dependencies are missing and you don't get a good way to instantiate the js object.

Creat JAR from .jardesc in eclipse

I have a question with respect to compiling java codes and building a jar file on Eclipse platform. I would like to know if the Create JAR option on eclipse from a .jardesc file will still create a JAR file inspite of errors in the compiled Java codes? If yes, how can i enable this option in my Ant build xml?
If you edit your .jardesc in Eclipse (Open With – JAR Export Wizard), you can modify the behavior regarding errors/warnings on page two of the wizard:
.
This apparently toggles the attributes exportErrors and exportWarnings, respectively, at XPath /jardesc/options in the .jardesc file.
As far as the behavior of a corresponding Ant build file is concerned, you should probably take a look at the failonerror parameter of the Javac Task.

Call sbt externally

I am designing a tool, that takes an sbt project path as a parameter. I would like to be able to build that given project on the fly, and be able to get its classpath.
I previously designed my tool as a sbt plugin to achieve this but it is not flexible enough for my purpose: I don't want to have to parameter anything in the sbt config files of the project I am studying.
I would like to use sbt externally, construct a project (from a sbt directory path) and compile it externally in my scala code without invoking sbt in a console. This is a reproduction in code of what happens when "sbt" is typed in a given directory in the console. Is there a straightforward way to achieve this?
I think you need to look at SBT jar file and source code. Find the "Main" class and call it programmatically. The code is here: https://github.com/sbt/sbt. The main class is: xsbt.boot.Boot. I got it from sbt jar file by unzipping it and looking at META-INF/MANIFEST.MF. So you can see how SBT passes command line arguments to it and take it from there. Here is the Boot class just in case: https://github.com/sbt/sbt/blob/0.13/launch/src/main/scala/xsbt/boot/Boot.scala. Have fun! :)
p.s. in your code just call Boot.main(<your sbt commands>).
I have a vaguely similar requirement. I produce a command-line tool as one of the deliverables from my project. The script launches the Scala runtime itself and naturally needs the effective class-path for the project's dependencies. To get that in an external form, I use the SBT-Start-Script plug-in. While that plug-in does produce an actual launcher, I need to do more than it provides, so I just use it to externalize the project's (current) class-path, which I extract into a shell array initialization in a separate source file that may be source-ed by the main launcher script.

can I use the eclipse .classpath file to set classpaths and launch a jar from command line?

After doing some work on setting the eclipse build path, I would like to use what I did (which is in .classpath) to launch a version of my project, where I have only the jar and which has no dependencies compiled in, with the same classpath. Is this possible using the normal java command? Is it possible on the command line, at all? Do I need eclipse to use .classpath?
If you want to use the build path settings you made in eclipse, you should run your program from eclipse using the "Run As" command. However, this will not run the program from the jar, but from your compiled classes.
If you plan on running the jar file from a command line, you will need to set the classpath using the "-cp" option. I am not aware of any way to pass the eclipse .classpath file to the jvm.

how to exclude external jar while creating executable jar in eclipse or commandline?

I have written a program in Eclipse IDE which uses BouncyProvider class of BouncyCastle.jar. So to compile my class I added BouncyCastle.jar in my project classpath and it compiles perfectly.
Now I want to export my project as Runnable JAR so when I do that from Eclipse, it by default adds the classes of BouncyCastle.jar also in that runnable jar.
But I want to keep my application jar and BouncyCastle.jar different from each other.
How can I achieve this? Can anybody please help?
It sounds like you want to use the "Export JAR File" wizard instead of the "Export Runnable JAR File" wizard. When exporting a runnable jar file, Eclipse attempts to pack everything needed to run the application into a single archive. On the other hand, the "Export JAR File" wizard gives you more control over what is packaged in the archive. You can still create a runnable jar file, but you must make sure to include BouncyCastle.jar on the classpath when you execute the jar. Here are step-by-step instructions:
Click "File | Export". The Export
dialog pops up.
Expand the "Java" folder and select
"JAR file" (not "Runnable JAR
file"). Click Next. On the JAR file
specification page, choose the
classes you want included in the jar
file, and specify the name of the
JAR file to create. Click Next.
On the JAR Packaging Options page,
select options appropriate for you.
The defaults are probably fine.
Click Next.
On the JAR Manifest Specification,
make sure to select the "Main class" for your jar file. This is
the class that will be executed when
you execute the jar file. If you
leave this blank, the jar file will
not be runnable. Click Finish to
create the jar file.
You should be able to execute the jar file by executing "java -jar myjarfile.jar -classpath BouncyCastle.jar" from a command line.
Unfortunately, looks like you can't actually do that. A JAR can't use another JAR that's stored inside itself.
I'd say, unless you have a really strong reason why you can't unpack your BouncyCastle.jar
(like maybe licensing problems?)
just let it unpack (which you can do by adding BouncyCastle.jar as an external archive in Eclipse:)
Right-click on your project
Build Path...
Add External Archives...
Add your archive
Export as runnable JAR)
and watch your package names for conflicts.
Here's an open Java bug ID I found describing your situation
One-JAR may help - a open source solution to your situation
It looks like this has been added in Eclipse 3.5 Milestone 5. See the News for the latest build and bug 219530