How to run Java project - java

A friend of mine once gave me a Java project on offline browser. It contains all class file as well as Java sources but I don't know how to run it or how can I check how it works . It doesn't contain any database or applet. please help

If you want to run a java .class file, open the terminal (if you are using Unix machine) or the command line (if you are using a Windows machine) and type java filename Note: filename does not include the .class extension, just use the name of the file and do not include the extension.
If you get an error this probably means you don't have java installed.

Import it into Eclipse or NetBeans and then click "run"...
That would be the simplest solution in my mind

Related

VS Code runs .java files without the producing .class files

I have some basic java knowledge and i decided to switch from Intellij to VS Code. I know how to compile and run a java file (which may use other imported .java files) from the terminal, but i want to run a java program using the run icon inside vs code.
I'm not a 100% sure, but i think that in order to run a java program inside vs code you need a extension. For this reason i downloaded the Java extension pack. Note that i already have installed the latest jdk on my computer.
After i installed the plugin, i could run the program using the "run without debugging"/clicking in the run icon. However, no .class files are produced. I control+h but there isnt any hidden folder that vs code may drop the .class files.
How does the program run in the first place?
How can i config vs code in order to compile the java files before running the one that has the main function?
Basically, when you run a java file normally, you compile it with javac and then run it with java (or something along those lines, there are many different variations of possible ways to do it). If you go ahead and try, it is possible to run java filename.java and skip the normal javac step. In the case of VSCode, it will differ based on what extensions you have, but some may run the code with a simple java filename.java and others may have different settings set. If you take a look at your extension preferences as well as your preferences for java by searching your settings, there may be an option, such as "Java Source Paths" enabled which changed where compiled files are saved by VSCode.
If your project is a folder containing Java source files. And no build tools(Maven/Gradle) are used.
If that is the case, you can trigger the command Java: Configure Classpath, then find the section output and then set a relative path to your workspace.
The output files are by default stored inside the workspace storage.
If after triggering the command, what you see is the native vs code setting page. Then try to search java.project.outputPath and then set a relative path to it.

Can't open a .jar file on my mac

I'm trying to download jsoup on my mac (Mountain Lion). I've downloaded the jsoup.jar file and installed the last java 7 from the site. But here is the problem, when I double click the .jar file it tells to me:
The Java JAR file “jsoup-1.7.2.jar” could not be launched. Check the
console.
I can't find even the console! Someone can help me? I read a lot of answers about this topic, but they all talk about Java 6 and it has different settings that can't find.
EDIT
i also tried from the terminal with this command:
java -jar /Users/Ben/Downloads/jsoup-1.7.2.jar
but it tells me:
Failed to load Main-Class manifest attribute from
/Users/Ben/Downloads/jsoup-1.7.2.jar
The JSoup JAR is not executable, so you are not going to be able to 'run' it in any of the ways you described. You are supposed to include it in your project classpath and use classes from it to do your parsing (after importing them of course).
You might want to refer to the JSoup Guide for examples on using the library.
I guess you are trying to run the jsoup library as a standalone application assuming it to be an executable jar. All indicates that the jar file you are using is NOT an executable jar hence it wont work.
jsoup.jar is supposed to be used as a java library and you will need to write java code to be able to use the HTML parsing capabilities.
If you are using an IDE like IntelliJ, you can open the module settings for a particular project and select Libraries. There'll be an option to add a particular external library from the Maven repository after which you can download the JAR and include it in your project's dependencies.

How to convert exe application to jar file?

I have exe file called Myapp.exe. Now I want to convert .exe to jar file. That jar file should also work in NON JAVA system. I don't have any idea to implement it. Can anyone please suggest me how to do it?
Direct conversion not available !!!
because they are in entirely different platforms.
Meeting your requirements is impossible for two reasons.
1) You cannot change an EXE to a JAR file.
2) You cannot run a JAR file on a system that doesn't have Java installed.
If you want to run something on a (Windows) system with no Java installation, it needs to be an EXE ... or something else that doesn't require Java.
(It might help if you explained why you think you need to do this. Perhaps there is an alternative set of requirements that are not impossible to meet.)
why i am doing all those stubs is for making my jar has to work in java not installed system.
It needs to be an EXE then!
I have an jar.It is working fine in java installed system.My task is to Bundle jre inside jar(Not along with jar(i.e we can put jre and jar in same folder to run a jar as given in following url mindfiresolutions.com/… ))Because i have to give jar file only to client,in such a way that they can use this Myapp.jar in non java system also.But,i don't know how to bundle jre inside jar.I Don't how to run jre inside jar?
Ermm ...
Is it possible?
No. You cannot embed a JRE inside a JAR file in any way that would allow it (the JAR file) to run your Java code without first installing Java. (And installing Java would defeat the purpose of embedding the JRE ... of course.)
But what you can do is create an EXE file which has a JRE and a JAR embedded in it. And there are tools for doing this. Here's the canonical Question on how to do it:
How can I convert my Java program to an .exe file?
I think you need to read the Oracle documentation on what a JAR file really is, and how Java programs are normally executed. That will help you understand what is feasible ... and what is nonsensical.

Eclipse - Compiling & executing program

In the past, I have used JCreator to develop my java applications. I wanted to try Eclipse and see its IDE.
On JCreator, I could just open a java file and run it in the command prompt. On Eclipse, I cannot find out how I can compile and run a java file written by someone else without first creating a project, creating a new java class and then copy and pasting the code from the file.
I cannot even figure out how to import a java file into the project.
So my questions:
1. How can I open, compile and run a java file without first creating a java project.
2. How can I import a java file into a project I already have.
3. How can I run the program in command prompt, instead of on the console that is in Eclipse, (update: to be more clear) directly from the Eclipse.
Thank you.
1/ Do not forget scrapbook page (also presented here)
In theory, you could copy a class in it, but since that class is actually encapsulated into a "main invisible" class, as an inner class, it would not support any static methods in it.
However, for a quick chunk of code, it does the trick just fine.
(from this Eclipse tutorial)
3/ Since you want it run directly from eclipse, use as indicated in this thread, an External tool
That External Tool would run C:\WINDOWS\system32\cmd.exe with working directory ${container_loc}
More details in this article "How do I open a Windows Command Prompt in my console ?".
(source: avajava.com)
That will give:
(source: avajava.com)
As far as I know, you can't
Right click project > Import
With respect to your platform, something roughly equivalent to: java <classname>. (Make sure java is in your path, otherwise use the absolute path to the it.)
A useful feature is available in Eclipse since version 3.4: you can paste the text of a Java class into a Java project (copy the content of the class, select the project or source folder, paste). This will create an appropriately named file, in the correct package. This is probably the easiest way to import a single class.
2) Use the "Import" command. Ensure the java file goes to the "src" directory.
3) One way is to export your classes to a JAR file and then run the JAR file at the command prompt (e.g. java -jar file.jar)

How can I extract java exe to jar

I have an exe that I know was written in java. I understand that java programs can be made into an exe and there are tools to convert jar files to exe but is it possible to convert back? AFAIK jar files can be run on any platform that can run java and I would like to use a windows compiled java program on mac without using any extra virtualisation (wine,vmware)
It depends how the exe has been built:
If it has simply wrapped, with a tool like JSmooth, the same tool can extract the jar
If it it has been compiled, with for instance gcj (as illustrated by this question),... I am not sure.
If it has been compiled by a static compiler (or AOT - Ahead-Of-Time -), I believe it is not possible to extract the orignial jars.
If your application was wrapped using JSmooth, you can look in your default temp directory (C:\Documents and Settings\Username\Local Settings\Temp) while the application is running.
Open a windows explorer window to the temp dir, then start up your application. You should see a jar file show up (Temp#.jar). Just make a copy of this and you should be on your way.
i suggest just rename your file extension from .exe to .jar and try to extract them.
to view the code use java Decompiler LIKE:
http://java-decompiler.github.io
It is possible to convert file.exe back to file.jar , To go with this reversing process to will require you to know how the file was beeen encrypted ,for example if is the first level encryption class name and files are not hidden , for the second level file classes are hidden , for the 3rd level file and classes are hidden . to get this well download jar to exe software and try how they convert jar to exe then you will be able to know the reverse. to know how you proceed with reversing the process there is a single blog which helped me and all tools you may use are listed there like : Resource Hacker
Winhex
Ollydbg 1.10+ MemoryDump 0.9 and Olly Advanced or StrongOD Plugin(for advanced ctrl+g).
DJ Java Decompiler
7-Zip or Winrar
The link:
https://reverseengineeringtips.blogspot.com/2014/12/unpacking-jar2exe-21-extracting-jar.html?showComment=1480364662658#c447064983483780468
thanks

Categories

Resources