Create compile script for Java - java

I have downloaded an Eclipse project and I want to be able to have other people compile it without using Eclipse. It is a fairly large Java project that is still being worked on. How would I make a compile script that compiles like eclipse?

I highly recommend you look into Maven. Basically you'll define a Maven pom file in the root of your Eclipse project directory which will contain your dependencies (jars) as well as compile and assembly configuration. With this in place you can simply checkout a project and run a maven build command against the local directory you checked out to and an executable/deployable package will be created.

Related

Maven: How to compile only? Keep file structure intact

I have a regular java servlet web application with the following structure:
/project/
main_sources/
web/
(java source code files here)
pages/
(jsp files here)
WEB-INF/
web.xml
classes/
(this is where all the compiled java files from main_sources go)
css/
scripts/
This all compiles fine and runs in Tomcat.
I want to compile this project in maven (keep the file structure intact).
What do I put in the POM.xml to NOT produce a WAR/JAR file? I just want it to compile the java source code into the classes folder only.
(Basically, I want to deploy it to Azure App Service and have Maven as a build pipeline task to build the project...but currently it's produce a WAR file instead).
If you call mvn compile, Maven only executes the phases up to the compile phase, so the results will not be packaged.
As a side node: Think about refactoring your project into the standard Maven structure.
You might be doing clean and Build project..Build generates war file.
So ,you select only compile option in maven
To compile project from maven commandline, you can use mvn compile command

Using libraries in Eclipse without altering classpath

Edit:
How can I included packages in the .classpath that are downloaded at compile-time by gradlew and use them in Eclipse before compile-time such that my .classpath doesnt include local file paths from my personal computer?
I would like to use the org.apache.commons.cli package, but do so without altering the .classpath file. I'm using the gradlew to build my project, and in the build.gradle file is:
dependencies {
compile 'commons-cli:commons-cli:20040117.000000'
compile 'com.google.code.gson:gson:2.8.2'
testCompile "junit:junit:4.11"
}
So at compile-time, the necessary libraries are managed. However, without them added to Eclipse, using them seems to be impossible as they cannot be resolved.
Question:
If using build.gradle to manage project dependencies, is there a way to use them in Eclipse without going to the project's build path and adding external jar's? If not, what is the general practice for situations like this, where a library is needed to be use, but I dont want my local file path stored in the .classpath, where a user may not have the same jar in the same file path?
You should install and use Eclipse BuildShip to properly work with gradle projects.

multi project java build with gradle

I've decided to use gradle instead of ant in some of my applications.
the folder structure for my apps is:
<appname>
---java
------build.gradle
------settings.gradle
------sourcefolder1
------sourcefolder2
------sourcefolder3
---------------subsourcefolder1
---------------subsourcefolder2
I take the compilation files for every application and create a single jar that contains them all.
My issue is as follows:
There is no code to compile under the java folder, only under its subdirectories which are sub-projects in gradle. So, I apply the java plugin only for the sub-projects. In this case everything compiles fine but the final jar to contain everything doesn't get created. On the other hand, if I apply the java plugin to the rootProject it starts compiling the source folders although they have a uniqe project of their own.
I tried applying the java plugin to the root project and overriding compileJava task to do nothing - but it created an empty jar, probably this task also generates the products to jar.
Is there an elegant solution for this?
Thanks.

Compile NetBeans project from command line by using Ant

I have a NetBeans project I would like to compile from the command line. There are many other questions on StackOverflow about how to do so, but they explain how to compile the project using commands like javac src/*.java.
I haven't changed my NetBeans project's build settings. By default, how can I compile my project from the command line using Ant? Once I've built my project, where is the compiled file located, and what format is it in (i.e., .class files, one .jar file, etc.)?
(I understand that asking how to use Ant to compile my project in general is too broad of a question. That's why I'm specifically asking about how to compile using NetBean's default configuration for a project.)
I'm using NetBeans 8.0.2.
ant compile Compiles the project (.class files are placed in the build/classes folder)
ant jar Compiles the project (see above) and builds a JAR ( located in dist/ )
If that doesn't work for you, check ant's output for errors. (Is the JAVA_HOME Variable set properly?)
I'm totally agnostic IDE developer. After several frustrating years trying to emerge "netbeans ant config" to something usable from command line I became to create a wrapper for netbeans ant.
https://github.com/albfan/ant-netbeans
By now you can:
detect defined targets with standard
$ ant tabtab
Rely on project will honor JDK_HOME
and most important
Expect all ant target to complete smoothly, passing test and whatever stuff implied.

Adding plain Java project as a classpath to an eclipse plugin

I have a plain Java project (not a plugin project) which I want to add to a classpath of a eclipse plugin which I am developing. But in web projects I can add that project as a build path and it works fine. But I tried same thing in eclipse plugin, I am able to compile successfully, but at run time I am getting java.lang.ClassNotFoundException.
I know OSGi quite well and I know how to add OSGi into an classpath (using export-packages) but what I want is to add Standard, non-osgi project into an classpath, so that I wont' get runtime errors. Is there anyway I can achieve this?
I can export project as a jar file or make it as a plugin project and it would work fine. But that's not my option currently because, still that API is in pre-alpha stage, and there would be lot of changes going on. So I am trying to avoid pain of exporting it as jar file everytime. Is there any option for me other than this?
I have a similar situation: I want non-OSGi Maven dependencies integrated into the classpath of my plugin. I succeeded with a roundabout solution, which I think is the best I could get.
I have a build step outside of Eclipse where I copy the class files of the dependency into the plugin's lib folder. The lib folder is specified in MANIFEST.MF as an entry in Bundle-ClassPath and (here comes the hack) as a source folder in build.properties. That was the only way to make the plugin work both when launched from within Eclipse and when exported.

Categories

Resources