first of all sorry for my bad english. I have a question and I cant find an answer anywhere.
My Programm exports some loose *.java files withouth any entrypoint. The written API allows an CMD to be executed. Problem is, the CMD Order to start eclipse with parameters. My questions is is it possible to start eclipse 3.3-3.6 with a command line parameter to create a project. Creating a Workspace through -data c:\xxxx\myworkspace is no problem but since eclipse sees no files outside a project, i need to make one so i can put my java files into it and startup an remote debug after it. The Plan is to startup an external export java file, which starts eclipse with the defined workspace and a fresh project (with the exported java files) for usage.
Using Maven it's possible to create an Eclipse project and all kinds of useful stuff, http://maven.apache.org/guides/mini/guide-ide-eclipse.html gives at least a starting point
There are some tools like Maven or Ant plugins that create Eclipse projects from some structural information (e.g. the Maven plugin reads the pom.xml).
If your code is unstructured it might be hard to create a fully functional Eclipse project. You might be able to create a Java project and define its source path (in fact it's a simple XML file called .project - you could easily write one yourself) but any other information like additional dependencies etc. would have to be added manually.
Besides that, creating a simple project from existing sources isn't that hard in Eclipse. Why don't you just do it manually?
Related
Is there any way I can create Java projects using a simple text editor? Not an IDE like eclipse?
I want to be able to create .jar files without the assistance of an IDE, I have all the JDK commands installed already on my computer (such as javac)
I'd like to know what file structure I need, how I need to arrange my class files, what compilation steps I need to go through etc. to be able to create jar files.
Yes, completely doable (just not much fun once the project gets bigger).
I suggest if it's not a throwaway project, use a build tool like Maven or Gradle to manage your build process, so that you don't need to assemble classpaths and resources yourself, but still retain full control of the build and test lifecycle, without IDEs. This comes at a complexity cost, of course, but once it's set up life becomes easier.
See also How can I create an executable JAR with dependencies using Maven? or the Gradle docs about creating JARs
I'd highly recommend the standard Maven source directory layout too (src/main, src/test etc) as it's both commonplace and makes for easy integration with the above tools.
Follow the below steps to create a jar file
Compile the java source using javac
Create a manifest file (if main exists) to identify main class
Use the below command to create a jar file
jar -cvfm *.class
Yeah. You can create your project structure without an IDE. But it's time consuming and you have to do everything.
To talk about creating JAR, you don't want any extra software. You can use jar utility, which comes with JDK.
Here are steps to create jar:
Compile classes which you want to in jar
Create manifest file (.mf). It's needed if you want to make jar as executable. If you want to bundle classes only together, then no need. (eg. Dependency jar)
Go to command prompt and execute following command "jar cvf MyJarName.jar *.class". Make sure java is set in environment path and you're inside the directory of classes.
cvf means "create a jar; show verbose output; specify the output jar file name.
That's all. If you want to include any folders inside jar then you can use folder name in above command after classes and it must be separated by space.
Example: jar cvf TicTacToe.jar TicTacToe.class audio images
I have this, perhaps, easy problem, but I don't know how to handle this.
I have my Java program and it works pretty well when I call it via terminal (Java command).
The program uses 4 text files from the hard disk which can't be added as resources to the project.
How to do this right so I could build jar file only with main class and files from hard disk (first one is a config file and it has paths to other files so the program knows where they are)?
I'm using IntelliJ IDEA 14.1.4 on Arch Linux.
I did it based on this blog, but it's not working without txt files in src folder.
Also "jar cvf" command builds jar file, but it's not working outside my computer (for example on windows or OSX).
Can anyone help me?
I prefer step by step instruction so I would understand what is going on in here.
I recommend to build your application with Maven and create a Maven Assembly which contains your JAR file as well as the config.txt file.
I'm working on a groovy project that runs as java application in Eclipse.
Normally there are normal class files under the groovy files, but when I make a clean install of the project with maven, it deletes those java classes, so i can't run it in eclipse anymore.
Why is that so? I have another project that has the same structure without this problem.
Greetings
edit:
I made a screenshot to clear what I mean.
The PDFConverter is how I want/know it the other is what I get and can't run in Eclipse anymore
I would look at your_project/target/classes/ directory, that's where Maven puts .class files.
Although it's not entirely clear what are you asking about.
I'm developing a quite big software for Android in Java (using Eclipse and ADT).
To support my development, I made an own command-line tool that does the following:
Loads and processes certain Java files (from the project of my developed software)
Outputs new Java files to a certain folder (so the input files are retained too) into my project
What the command-line tool does isn't relevant, its output is merely standard Java code (i.e. it's a code generator).
I would like that this command-line tool is automatically called during the build process. In other words, I want that when I'm finished with the manual coding and start the build process (e.g. by clicking "Run..."), the following happens:
The command-line tool is run
The files generated by the command-line tool are included in the build too (i.e. they are compiled exactly as if they were added and coded manually in the Eclipse project).
I'm pretty sure I have to add this program as a "Program" via to the Builder list of the project (see the attached screenshot). My questions:
What position to put it? Should it be the first?
What else do I need to do in order to meet the above requirements? I'm afraid that if the command line tool just writes the .java files to a folder, Eclipse will not see the newly generated files (as they are not added to its project file).
You are on the right track, and it will work fine given these conditions:
Your builder must be at the top, so it can modify the source files before the Java builder is running.
Your Java files must be generated into one of the existing "src" pathes of the project. Java files are not registered in the project, so if you put someting into a source folder of the project, it will be compiled. Eclipse tools like xtext and xtend work the same way.
The refresh option of your builder must be activated. Otherwise the workspace would not know that you created files (as your program works with java.io.File operations, thereby bypassing the workspace API for resources).
I am new to Java (and Eclipse) but I have used .NET (and Visual Studio) a fair amount. I also know about compiling C/C++ code and things like that. I know that at the end I get either an EXE or a nice binary file that can be run from the command line.
I have been making a Java utility that uses some external libraries. I need to compile this into an executable that I can run from the command line on a unix machine, but I cannot find any way to do this.
I can build and run/debug in Eclipse, but that is no use to me as this code will be run on a webserver. I just need all the dependancies compiled in to one file but after hours of searching on Google, the best thing I could find was the Fat-JAR plugin for Eclipse and after using that I just get the following error when I try to run the file:
Exception in thread "main" java.lang.NoClassDefFoundError: Network/jar
This is really confusing me and as it is such an essential thing to be able to do I am sure I must be missing something blindingly obvious, but as I said, after hours of searching I have gotten nowhere.
I really appreciate any help you can give me. Thanks.
If you build your java app using Maven (which can be done with every major IDE), then you can use the maven Shade Plugin to build a shaded jar file; this is a jar file with all of its dependencies included.
A shaded jar can be run from the command line like this:
java -jar myjar.jar command line options
You're doing something standard and you're using eclipse. This means, in your case, Maven is your friend. Download and install the M2Eclipse plug-in. Maven is best at managing dependencies. So, creating a jar with dependencies included will be very, very straight forward. There are thousands of examples on the web and in StackOverflow. If you have problems setting it up, comment on this and I can point you in the right direction.
Sounds like your class path on the server needs to be modified to pick up the jar file containing the Network class. How are you executing your program? What path(s) are you putting in the -cp option?
If you are not sure how to find out the contents inside a jar file, run jar tf , this will list the packaged classes. Validate that one of the jars in your CLASSPATH has that class it says missing.
Give us more details and we can help solve it.
I think I should first explain some basics. A Java class can be run as an application if it has a public static void main(String[] args) method. If it has this method, you can run it from command line as:
java my.package.MyClass <attributes>
Before launching your app, you need to make sure that all required .jar files (and the root of your own class folders, if you did not make a jar from your classes) are in the CLASSPATH environment variable.
These are the absolute basics. When you are building a more complex app, or an app for distribution, you'll probably use maven or ant or some other tool that makes your life easier.